From af1419ade2f9168235499dd99508c9116de6d00f Mon Sep 17 00:00:00 2001 From: Guido Vollbach Date: Wed, 23 Oct 2024 12:13:35 +0200 Subject: [PATCH] Codestyle and fixes after code review --- .../classes/class.ilOpenIdConnectSettings.php | 53 ++++++++++++------- .../class.ilOpenIdConnectSettingsGUI.php | 37 ++++++------- 2 files changed, 50 insertions(+), 40 deletions(-) diff --git a/components/ILIAS/OpenIdConnect/classes/class.ilOpenIdConnectSettings.php b/components/ILIAS/OpenIdConnect/classes/class.ilOpenIdConnectSettings.php index 3ec0f332ca70..bb4626c80a19 100755 --- a/components/ILIAS/OpenIdConnect/classes/class.ilOpenIdConnectSettings.php +++ b/components/ILIAS/OpenIdConnect/classes/class.ilOpenIdConnectSettings.php @@ -40,6 +40,28 @@ class ilOpenIdConnectSettings public const VALIDATION_ISSUE_INVALID_SCOPE = 0; public const VALIDATION_ISSUE_DISCOVERY_ERROR = 1; + /** + * @var string[] + */ + private const IGNORED_USER_FIELDS = [ + 'mail_incoming_mail', + 'preferences', + 'hide_own_online_status', + 'show_users_online', + 'roles', + 'upload', + 'password', + 'username', + 'language', + 'skin_style', + 'interests_general', + 'interests_help_offered', + 'interests_help_looking', + 'bs_allow_to_contact_me', + 'chat_osc_accept_msg', + 'chat_broadcast_typing', + ]; + private static ?self $instance = null; private readonly ilSetting $storage; @@ -507,30 +529,21 @@ public function getCustomDiscoveryUrl(): ?string { return $this->custom_discovery_url; } + /** * @return array */ public function getProfileMappingFields(): array { - return [ - 'gender' => $this->lng->txt('gender'), - 'firstname' => $this->lng->txt('firstname'), - 'lastname' => $this->lng->txt('lastname'), - 'title' => $this->lng->txt('person_title'), - 'institution' => $this->lng->txt('institution'), - 'department' => $this->lng->txt('department'), - 'street' => $this->lng->txt('street'), - 'city' => $this->lng->txt('city'), - 'zipcode' => $this->lng->txt('zipcode'), - 'country' => $this->lng->txt('country'), - 'phone_office' => $this->lng->txt('phone_office'), - 'phone_home' => $this->lng->txt('phone_home'), - 'phone_mobile' => $this->lng->txt('phone_mobile'), - 'fax' => $this->lng->txt('fax'), - 'email' => $this->lng->txt('email'), - 'second_email' => $this->lng->txt('second_email'), - 'hobby' => $this->lng->txt('hobby'), - 'matriculation' => $this->lng->txt('matriculation') - ]; + $mapping_fields = []; + $usr_profile = new ilUserProfile(); + + foreach ($usr_profile->getStandardFields() as $id => $definition) { + if (in_array($id, self::IGNORED_USER_FIELDS, true)) { + continue; + } + $mapping_fields[$id] = $this->lng->txt($id); + } + return $mapping_fields; } } diff --git a/components/ILIAS/OpenIdConnect/classes/class.ilOpenIdConnectSettingsGUI.php b/components/ILIAS/OpenIdConnect/classes/class.ilOpenIdConnectSettingsGUI.php index 1fe3a86b95d8..27368e34c60a 100755 --- a/components/ILIAS/OpenIdConnect/classes/class.ilOpenIdConnectSettingsGUI.php +++ b/components/ILIAS/OpenIdConnect/classes/class.ilOpenIdConnectSettingsGUI.php @@ -593,6 +593,13 @@ protected function saveScopes(): void $this->ctrl->redirect($this, 'scopes'); } + /** + * @param int $type + * @param string|null $url + * @param array $scopes + * @return bool + * @throws JsonException + */ protected function validateDiscoveryUrl(int $type, ?string $url, array $scopes) : bool { try { switch ($type) { @@ -606,6 +613,7 @@ protected function validateDiscoveryUrl(int $type, ?string $url, array $scopes) $discoveryURL = null; break; } + $validation_result = !is_null($discoveryURL) ? $this->settings->validateScopes($discoveryURL, (array) $scopes) : []; if (!empty($validation_result)) { if (ilOpenIdConnectSettings::VALIDATION_ISSUE_INVALID_SCOPE === $validation_result[0]) { @@ -632,13 +640,14 @@ protected function validateDiscoveryUrl(int $type, ?string $url, array $scopes) $this->scopes(); return false; } + return true; } /** * @throws ilCtrlException */ - protected function saveProfile(): void + private function saveProfile(): void { $this->checkAccessBool('write'); @@ -848,9 +857,6 @@ private function showInfoMessage() $this->mainTemplate->setOnScreenMessage('info', $message); } - /** - * @throws ilCtrlException - */ private function initAttributeMapping() : void { $mapping = $this->attribute_mapping_template->getMappingRulesByAdditionalScopes($this->settings->getAdditionalScopes()); @@ -894,12 +900,7 @@ private function initUserMappingForm() : Standard ); } - /** - * @param mixed $definition - * @param array $ui_container - * @return array - */ - protected function buildUserMappingInputFormUDF(mixed $definition, array $ui_container) : array + protected function buildUserMappingInputFormUDF($definition, array $ui_container) : array { $value = $this->settings->getProfileMappingFieldValue(self::UDF_STRING . $definition['field_id']); $update = $this->settings->getProfileMappingFieldUpdate(self::UDF_STRING . $definition['field_id']); @@ -915,16 +916,11 @@ protected function buildUserMappingInputFormUDF(mixed $definition, array $ui_con [$text_input, $checkbox_input] ); $ui_container[] = $group; + return $ui_container; } - /** - * @param string $lang - * @param int|string $mapping - * @param array $ui_container - * @return array - */ - protected function buildUserMappingInputForUserData(string $lang, int|string $mapping, array $ui_container) : array + protected function buildUserMappingInputForUserData(string $lang, string $mapping, array $ui_container) : array { $value = $this->settings->getProfileMappingFieldValue($mapping); $update = $this->settings->getProfileMappingFieldUpdate($mapping); @@ -940,12 +936,13 @@ protected function buildUserMappingInputForUserData(string $lang, int|string $ma [$text_input, $checkbox_input] ); $ui_container[] = $group; + return $ui_container; } private function initUserDefinedFields(): void { - if($this->udf === null) { + if ($this->udf === null) { $this->udf = ilUserDefinedFields::_getInstance(); } } @@ -955,7 +952,7 @@ private function initUserDefinedFields(): void */ public function userMapping($form = null): void { - if($form === null) { + if ($form === null) { $form = $this->initUserMappingForm(); } @@ -974,7 +971,7 @@ public function userMapping($form = null): void $aria_label = "change_the_currently_displayed_mode"; $active_label = $this->lng->txt("auth_oidc_saved_values"); - if($active !== 2) { + if ($active !== 2) { $active_label = $this->lng->txt(ilOpenIdAttributeMappingTemplate::OPEN_ID_CONFIGURED_SCOPES); } $view_control = $this->factory->viewControl()->mode($actions, $aria_label)->withActive($active_label);