From b5af9500b987c1360aca92eb70d35c60753024cb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dominik=20Franti=C5=A1ek=20Bu=C4=8D=C3=ADk?= <bucik@ics.muni.cz> Date: Tue, 13 Dec 2022 14:09:03 +0100 Subject: [PATCH] =?UTF-8?q?fix:=20=F0=9F=90=9B=20Reworked=20how=20Jurisdic?= =?UTF-8?q?tion=20is=20read?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/ConsentHelper.php | 78 +++++++++++++++++++++++-------------------- 1 file changed, 42 insertions(+), 36 deletions(-) diff --git a/lib/ConsentHelper.php b/lib/ConsentHelper.php index 546d272..5e7164c 100644 --- a/lib/ConsentHelper.php +++ b/lib/ConsentHelper.php @@ -5,54 +5,60 @@ namespace SimpleSAML\Module\elixir; class ConsentHelper { private const EU_EAA = [ - 'AT' => 'Austria', - 'BE' => 'Belgium', - 'BG' => 'Bulgaria', - 'HR' => 'Croatia', - 'CY' => 'Cyprus', - 'CZ' => 'Czech Republic', - 'DK' => 'Denmark', - 'EE' => 'Estonia', - 'FI' => 'Finland', - 'FR' => 'France', - 'DE' => 'Germany', - 'EL' => 'Greece', - 'HU' => 'Hungary', - 'IE' => 'Ireland', - 'IT' => 'Italy', - 'LV' => 'Latvia', - 'LT' => 'Lithuania', - 'LU' => 'Luxembourg', - 'MT' => 'Malta', - 'NL' => 'Netherlands', - 'PT' => 'Portugal', - 'RO' => 'Romania', - 'SK' => 'Slovakia', - 'SI' => 'Slovenia', - 'ES' => 'Spain', - 'SE' => 'Sweden', - 'NO' => 'Norway', - 'IS' => 'Iceland', - 'LI' => 'Liechtenstein', - 'GB' => 'United Kingdom', + 'AUT' => 'Austria', + 'BEL' => 'Belgium', + 'BGR' => 'Bulgaria', + 'HRV' => 'Croatia', + 'CYP' => 'Cyprus', + 'CZE' => 'Czech Republic', + 'DNK' => 'Denmark', + 'EST' => 'Estonia', + 'FIN' => 'Finland', + 'FRA' => 'France', + 'DEU' => 'Germany', + 'GRC' => 'Greece', + 'HUN' => 'Hungary', + 'IRL' => 'Ireland', + 'ITA' => 'Italy', + 'LVA' => 'Latvia', + 'LTU' => 'Lithuania', + 'LUX' => 'Luxembourg', + 'MLT' => 'Malta', + 'NLD' => 'Netherlands', + 'PRT' => 'Portugal', + 'ROU' => 'Romania', + 'SVK' => 'Slovakia', + 'SVN' => 'Slovenia', + 'ESP' => 'Spain', + 'SWE' => 'Sweden', + 'NOR' => 'Norway', + 'ISL' => 'Iceland', + 'LIE' => 'Liechtenstein', + 'GBR' => 'United Kingdom', ]; + private const JURISDICTION_INTERNATIONAL_ORG = 'International organisation'; + private const JURISDICTION_EMBL = 'EMBL intergovernmental organisation'; + public function __construct() { } public static function getJurisdiction($dstMetadata): string { - $countryCodes = json_decode(file_get_contents('http://country.io/names.json'), true); $jurisdiction = empty($dstMetadata['jurisdiction']) ? '' : $dstMetadata['jurisdiction']; - if (empty($jurisdiction) || array_key_exists($jurisdiction, self::EU_EAA)) { - return ''; - } - if ('INT' === $jurisdiction || 'EMBL' === $jurisdiction) { + $pattern = "/\(\K[A-Z]{3}/"; + $jurisdictionCode = preg_match($pattern, $jurisdiction, $out) ? $out[0] : $jurisdiction; + if ( + self::JURISDICTION_INTERNATIONAL_ORG === $jurisdictionCode + || self::JURISDICTION_EMBL === $jurisdictionCode + ) { return $jurisdiction; + } elseif (empty($jurisdictionCode) || array_key_exists($jurisdictionCode, self::EU_EAA)) { + return ''; } - return 'in ' . $countryCodes[$jurisdiction]; + return 'in ' . $jurisdiction; } public static function printUserAttributes(array $attributes, $translator) -- GitLab