Skip to content

Commit

Permalink
Plugin: Azure: Add option to filter groups by display name - refs BT#…
Browse files Browse the repository at this point in the history
…21930
  • Loading branch information
AngelFQC committed Dec 27, 2024
1 parent 10b6d61 commit 6178340
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 0 deletions.
2 changes: 2 additions & 0 deletions plugin/azure_active_directory/lang/dutch.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,5 @@
$strings['tenant_id_help'] = 'Required to run scripts.';
$strings['deactivate_nonexisting_users'] = 'Deactivate non-existing users';
$strings['deactivate_nonexisting_users_help'] = 'Compare registered users in Chamilo with those in Azure and deactivate accounts in Chamilo that do not exist in Azure.';
$strings['group_filter_regex'] = 'Group filter RegEx';
$strings['group_filter_regex_help'] = 'Regular expression to filter groups (only matches will be synchronized), e.g. <code>.*-FIL-.*</code> <code>.*-PAR-.*</code> <code>.*(FIL|PAR).*</code> <code>^(FIL|PAR).*</code>';
2 changes: 2 additions & 0 deletions plugin/azure_active_directory/lang/english.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,5 @@
$strings['tenant_id_help'] = 'Required to run scripts.';
$strings['deactivate_nonexisting_users'] = 'Deactivate non-existing users';
$strings['deactivate_nonexisting_users_help'] = 'Compare registered users in Chamilo with those in Azure and deactivate accounts in Chamilo that do not exist in Azure.';
$strings['group_filter_regex'] = 'Group filter RegEx';
$strings['group_filter_regex_help'] = 'Regular expression to filter groups (only matches will be synchronized), e.g. <code>.*-FIL-.*</code> <code>.*-PAR-.*</code> <code>.*(FIL|PAR).*</code> <code>^(FIL|PAR).*</code>';
2 changes: 2 additions & 0 deletions plugin/azure_active_directory/lang/french.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,5 @@
$strings['tenant_id_help'] = 'Nécessaire pour exécuter des scripts.';
$strings['deactivate_nonexisting_users'] = 'Deactivate non-existing users';
$strings['deactivate_nonexisting_users_help'] = 'Compare registered users in Chamilo with those in Azure and deactivate accounts in Chamilo that do not exist in Azure.';
$strings['group_filter_regex'] = 'Group filter RegEx';
$strings['group_filter_regex_help'] = 'Regular expression to filter groups (only matches will be synchronized), e.g. <code>.*-FIL-.*</code> <code>.*-PAR-.*</code> <code>.*(FIL|PAR).*</code> <code>^(FIL|PAR).*</code>';
2 changes: 2 additions & 0 deletions plugin/azure_active_directory/lang/spanish.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,5 @@
$strings['tenant_id_help'] = 'Necesario para ejecutar scripts.';
$strings['deactivate_nonexisting_users'] = 'Desactivar usuarios no existentes';
$strings['deactivate_nonexisting_users_help'] = 'Compara los usuarios registrados en Chamilo con los de Azure y desactiva las cuentas en Chamilo que no existan en Azure.';
$strings['group_filter_regex'] = 'Group filter RegEx';
$strings['group_filter_regex_help'] = 'Expresión regular para filtrar grupos (solo las coincidencias serán sincronizadas), p.ej. <code>.*-FIL-.*</code> <code>.*-PAR-.*</code> <code>.*(FIL|PAR).*</code> <code>^(FIL|PAR).*</code>';
2 changes: 2 additions & 0 deletions plugin/azure_active_directory/src/AzureActiveDirectory.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class AzureActiveDirectory extends Plugin
public const SETTING_EXISTING_USER_VERIFICATION_ORDER = 'existing_user_verification_order';
public const SETTING_TENANT_ID = 'tenant_id';
public const SETTING_DEACTIVATE_NONEXISTING_USERS = 'deactivate_nonexisting_users';
public const SETTING_GROUP_FILTER = 'group_filter_regex';

public const URL_TYPE_AUTHORIZE = 'login';
public const URL_TYPE_LOGOUT = 'logout';
Expand Down Expand Up @@ -59,6 +60,7 @@ protected function __construct()
self::SETTING_EXISTING_USER_VERIFICATION_ORDER => 'text',
self::SETTING_TENANT_ID => 'text',
self::SETTING_DEACTIVATE_NONEXISTING_USERS => 'boolean',
self::SETTING_GROUP_FILTER => 'text',
];

parent::__construct('2.4', 'Angel Fernando Quiroz Campos, Yannick Warnier', $settings);
Expand Down
8 changes: 8 additions & 0 deletions plugin/azure_active_directory/src/AzureCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ protected function getAzureGroups(): Generator
implode(',', $groupFields)
);

$groupFilter = $this->plugin->get(AzureActiveDirectory::SETTING_GROUP_FILTER);

$token = null;

do {
Expand All @@ -125,6 +127,12 @@ protected function getAzureGroups(): Generator
$azureGroupsInfo = $azureGroupsRequest['value'] ?? [];

foreach ($azureGroupsInfo as $azureGroupInfo) {
if (!empty($groupFilter) &&
!preg_match("/$groupFilter/", $azureGroupInfo['displayName'])
) {
continue;
}

yield $azureGroupInfo;
}

Expand Down

0 comments on commit 6178340

Please sign in to comment.