Skip to content

Commit

Permalink
Codestyle and fixes after code review
Browse files Browse the repository at this point in the history
  • Loading branch information
gvollbach committed Oct 23, 2024
1 parent d087d4c commit af1419a
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -507,30 +529,21 @@ public function getCustomDiscoveryUrl(): ?string
{
return $this->custom_discovery_url;
}

/**
* @return array<string, string>
*/
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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -593,6 +593,13 @@ protected function saveScopes(): void
$this->ctrl->redirect($this, 'scopes');
}

/**
* @param int $type
* @param string|null $url
* @param array<string, string> $scopes
* @return bool
* @throws JsonException
*/
protected function validateDiscoveryUrl(int $type, ?string $url, array $scopes) : bool {
try {
switch ($type) {
Expand All @@ -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]) {
Expand All @@ -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');

Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -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']);
Expand All @@ -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);
Expand All @@ -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();
}
}
Expand All @@ -955,7 +952,7 @@ private function initUserDefinedFields(): void
*/
public function userMapping($form = null): void
{
if($form === null) {
if ($form === null) {
$form = $this->initUserMappingForm();
}

Expand All @@ -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);
Expand Down

0 comments on commit af1419a

Please sign in to comment.