Skip to content

Commit 994244b

Browse files
committed
Plugin: Azure: Add option to set the verification order por existing user - refs BT#21930
1 parent c492a14 commit 994244b

File tree

6 files changed

+74
-36
lines changed

6 files changed

+74
-36
lines changed

plugin/azure_active_directory/lang/dutch.php

+4
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@
2222
.'U zult moeten kopiëren de <code>/plugin/azure_active_directory/layout/login_form.tpl</code> bestand in het <code>/main/template/overrides/layout/</code> dossier.';
2323
$strings['management_login_name'] = 'Naam voor de beheeraanmelding';
2424
$strings['management_login_name_help'] = 'De standaardinstelling is "Beheer login".';
25+
$strings['existing_user_verification_order'] = 'Existing user verification order';
26+
$strings['existing_user_verification_order_help'] = 'This value indicates the order in which the user will be searched in Chamilo to verify its existence. '
27+
.'By default is <code>1, 2, 3</code>.'
28+
.'<ol><li>EXTRA_FIELD_ORGANISATION_EMAIL (<code>mail</code>)</li><li>EXTRA_FIELD_AZURE_ID (<code>mailNickname</code>)</li><li>EXTRA_FIELD_AZURE_UID (<code>id</code> of <code>objectId</code>)</li></ol>';
2529
$strings['OrganisationEmail'] = 'Organisatie e-mail';
2630
$strings['AzureId'] = 'Azure ID (mailNickname)';
2731
$strings['AzureUid'] = 'Azure UID (internal ID)';

plugin/azure_active_directory/lang/english.php

+4
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@
2222
.'You will need to copy the <code>/plugin/azure_active_directory/layout/login_form.tpl</code> file to <code>/main/template/overrides/layout/</code> directory.';
2323
$strings['management_login_name'] = 'Name for the management login';
2424
$strings['management_login_name_help'] = 'The default is "Management Login".';
25+
$strings['existing_user_verification_order'] = 'Existing user verification order';
26+
$strings['existing_user_verification_order_help'] = 'This value indicates the order in which the user will be searched in Chamilo to verify its existence. '
27+
.'By default is <code>1, 2, 3</code>.'
28+
.'<ol><li>EXTRA_FIELD_ORGANISATION_EMAIL (<code>mail</code>)</li><li>EXTRA_FIELD_AZURE_ID (<code>mailNickname</code>)</li><li>EXTRA_FIELD_AZURE_UID (<code>id</code> or <code>objectId</code>)</li></ol>';
2529
$strings['OrganisationEmail'] = 'Organisation e-mail';
2630
$strings['AzureId'] = 'Azure ID (mailNickname)';
2731
$strings['AzureUid'] = 'Azure UID (internal ID)';

plugin/azure_active_directory/lang/french.php

+4
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@
2222
.'Vous devez, pour cela, copier le fichier <code>/plugin/azure_active_directory/layout/login_form.tpl</code> dans le répertoire <code>/main/template/overrides/layout/</code>.';
2323
$strings['management_login_name'] = 'Nom du login de gestion';
2424
$strings['management_login_name_help'] = 'Le nom par défaut est "Login de gestion".';
25+
$strings['existing_user_verification_order'] = 'Existing user verification order';
26+
$strings['existing_user_verification_order_help'] = 'This value indicates the order in which the user will be searched in Chamilo to verify its existence. '
27+
.'By default is <code>1, 2, 3</code>.'
28+
.'<ol><li>EXTRA_FIELD_ORGANISATION_EMAIL (<code>mail</code>)</li><li>EXTRA_FIELD_AZURE_ID (<code>mailNickname</code>)</li><li>EXTRA_FIELD_AZURE_UID (<code>id</code> ou <code>objectId</code>)</li></ol>';
2529
$strings['OrganisationEmail'] = 'E-mail professionnel';
2630
$strings['AzureId'] = 'ID Azure (mailNickname)';
2731
$strings['AzureUid'] = 'Azure UID (internal ID)';

plugin/azure_active_directory/lang/spanish.php

+4
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@
2222
.'Para ello, tendrá que copiar el archivo <code>/plugin/azure_active_directory/layout/login_form.tpl</code> en la carpeta <code>/main/template/overrides/layout/</code>.';
2323
$strings['management_login_name'] = 'Nombre del bloque de login de gestión';
2424
$strings['management_login_name_help'] = 'El nombre por defecto es "Login de gestión".';
25+
$strings['existing_user_verification_order'] = 'Orden de verificación de usuario existente';
26+
$strings['existing_user_verification_order_help'] = 'Este valor indica el orden en que el usuario serña buscado en Chamilo para verificar su existencia. '
27+
.'Por defecto es <code>1, 2, 3</code>.'
28+
.'<ol><li>EXTRA_FIELD_ORGANISATION_EMAIL (<code>mail</code>)</li><li>EXTRA_FIELD_AZURE_ID (<code>mailNickname</code>)</li><li>EXTRA_FIELD_AZURE_UID (<code>id</code> o <code>objectId</code>)</li></ol>';
2529
$strings['OrganisationEmail'] = 'E-mail profesional';
2630
$strings['AzureId'] = 'ID Azure (mailNickname)';
2731
$strings['AzureUid'] = 'UID Azure (ID interno)';

plugin/azure_active_directory/src/AzureActiveDirectory.php

+57
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ class AzureActiveDirectory extends Plugin
2323
public const SETTING_GROUP_ID_ADMIN = 'group_id_admin';
2424
public const SETTING_GROUP_ID_SESSION_ADMIN = 'group_id_session_admin';
2525
public const SETTING_GROUP_ID_TEACHER = 'group_id_teacher';
26+
public const SETTING_EXISTING_USER_VERIFICATION_ORDER = 'existing_user_verification_order';
2627

2728
public const URL_TYPE_AUTHORIZE = 'login';
2829
public const URL_TYPE_LOGOUT = 'logout';
@@ -48,6 +49,7 @@ protected function __construct()
4849
self::SETTING_GROUP_ID_ADMIN => 'text',
4950
self::SETTING_GROUP_ID_SESSION_ADMIN => 'text',
5051
self::SETTING_GROUP_ID_TEACHER => 'text',
52+
self::SETTING_EXISTING_USER_VERIFICATION_ORDER => 'text',
5153
];
5254

5355
parent::__construct('2.3', 'Angel Fernando Quiroz Campos, Yannick Warnier', $settings);
@@ -131,4 +133,59 @@ public function install()
131133
''
132134
);
133135
}
136+
137+
public function getExistingUserVerificationOrder(): array
138+
{
139+
$defaultOrder = [1, 2, 3];
140+
141+
$settingValue = $this->get(self::SETTING_EXISTING_USER_VERIFICATION_ORDER);
142+
$selectedOrder = array_filter(
143+
array_map(
144+
'trim',
145+
explode(',', $settingValue)
146+
)
147+
);
148+
$selectedOrder = array_map('intval', $selectedOrder);
149+
$selectedOrder = array_filter(
150+
$selectedOrder,
151+
function ($position) use ($defaultOrder): bool {
152+
return in_array($position, $defaultOrder);
153+
}
154+
);
155+
156+
if ($selectedOrder) {
157+
return $selectedOrder;
158+
}
159+
160+
return $defaultOrder;
161+
}
162+
163+
public function getUserIdByVerificationOrder(array $azureUserData): ?int
164+
{
165+
$selectedOrder = $this->getExistingUserVerificationOrder();
166+
167+
$extraFieldValue = new ExtraFieldValue('user');
168+
$positionsAndFields = [
169+
1 => $extraFieldValue->get_item_id_from_field_variable_and_field_value(
170+
AzureActiveDirectory::EXTRA_FIELD_ORGANISATION_EMAIL,
171+
$azureUserData['mail']
172+
),
173+
2 => $extraFieldValue->get_item_id_from_field_variable_and_field_value(
174+
AzureActiveDirectory::EXTRA_FIELD_AZURE_ID,
175+
$azureUserData['mailNickname']
176+
),
177+
3 => $extraFieldValue->get_item_id_from_field_variable_and_field_value(
178+
AzureActiveDirectory::EXTRA_FIELD_AZURE_UID,
179+
$azureUserData['objectId']
180+
),
181+
];
182+
183+
foreach ($selectedOrder as $position) {
184+
if (!empty($positionsAndFields[$position]) && isset($positionsAndFields[$position]['item_id'])) {
185+
return (int) $positionsAndFields[$position]['item_id'];
186+
}
187+
}
188+
189+
return null;
190+
}
134191
}

plugin/azure_active_directory/src/callback.php

+1-36
Original file line numberDiff line numberDiff line change
@@ -85,42 +85,7 @@
8585
throw new Exception('The id field is empty in Azure AD and is needed to set the unique Azure ID for this user.');
8686
}
8787

88-
$extraFieldValue = new ExtraFieldValue('user');
89-
$organisationValue = $extraFieldValue->get_item_id_from_field_variable_and_field_value(
90-
AzureActiveDirectory::EXTRA_FIELD_ORGANISATION_EMAIL,
91-
$me['mail']
92-
);
93-
$azureValue = $extraFieldValue->get_item_id_from_field_variable_and_field_value(
94-
AzureActiveDirectory::EXTRA_FIELD_AZURE_ID,
95-
$me['mailNickname']
96-
);
97-
$uidValue = $extraFieldValue->get_item_id_from_field_variable_and_field_value(
98-
AzureActiveDirectory::EXTRA_FIELD_AZURE_UID,
99-
$me['objectId']
100-
);
101-
102-
$userId = null;
103-
// Get the user ID (if any) from the EXTRA_FIELD_ORGANISATION_EMAIL extra
104-
// field
105-
if (!empty($organisationValue) && isset($organisationValue['item_id'])) {
106-
$userId = $organisationValue['item_id'];
107-
}
108-
109-
if (empty($userId)) {
110-
// If the previous step didn't work, get the user ID from
111-
// EXTRA_FIELD_AZURE_ID
112-
if (!empty($azureValue) && isset($azureValue['item_id'])) {
113-
$userId = $azureValue['item_id'];
114-
}
115-
}
116-
117-
if (empty($userId)) {
118-
// If the previous step didn't work, get the user ID from
119-
// EXTRA_FIELD_AZURE_UID
120-
if (!empty($uidValue) && isset($uidValue['item_id'])) {
121-
$userId = $uidValue['item_id'];
122-
}
123-
}
88+
$userId = $plugin->getUserIdByVerificationOrder($me);
12489

12590
if (empty($userId)) {
12691
// If we didn't find the user

0 commit comments

Comments
 (0)