Skip to content

Commit

Permalink
Merge pull request #6003 from AngelFQC/BT21930-2
Browse files Browse the repository at this point in the history
Plugin: Azure: Add option to filter groups by display name
  • Loading branch information
NicoDucou authored Dec 30, 2024
2 parents 2485899 + 38d8bce commit bf8f2dd
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 @@ -50,3 +50,5 @@
$strings['script_users_delta_help'] = 'Get newly created, updated, or deleted users without having to perform a full read of the entire user collection. By default, is <code>No</code>.';
$strings['script_usergroups_delta'] = 'Delta query for usergroups';
$strings['script_usergroups_delta_help'] = 'Get newly created, updated, or deleted groups, including group membership changes, without having to perform a full read of the entire group collection. By default, is <code>No</code>.';
$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 @@ -50,3 +50,5 @@
$strings['script_users_delta_help'] = 'Get newly created, updated, or deleted users without having to perform a full read of the entire user collection. By default, is <code>No</code>.';
$strings['script_usergroups_delta'] = 'Delta query for usergroups';
$strings['script_usergroups_delta_help'] = 'Get newly created, updated, or deleted groups, including group membership changes, without having to perform a full read of the entire group collection. By default, is <code>No</code>.';
$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 @@ -50,3 +50,5 @@
$strings['script_users_delta_help'] = 'Get newly created, updated, or deleted users without having to perform a full read of the entire user collection. By default, is <code>No</code>.';
$strings['script_usergroups_delta'] = 'Requête delta pour les groupes d\'utilisateurs';
$strings['script_usergroups_delta_help'] = 'Get newly created, updated, or deleted groups, including group membership changes, without having to perform a full read of the entire group collection. By default, is <code>No</code>.';
$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 @@ -50,3 +50,5 @@
$strings['script_users_delta_help'] = 'Obtiene usuarios recién creados, actualizados o eliminados sin tener que realizar una lectura completa de toda la colección de usuarios. De forma predeterminada, es <code>No</code>.';
$strings['script_usergroups_delta'] = 'Consulta delta para grupos de usuarios';
$strings['script_usergroups_delta_help'] = 'Obtiene grupos recién creados, actualizados o eliminados, incluidos los cambios de membresía del grupo, sin tener que realizar una lectura completa de toda la colección de grupos. De forma predeterminada, es <code>No</code>';
$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 @@ -33,6 +33,7 @@ class AzureActiveDirectory extends Plugin
public const SETTING_DEACTIVATE_NONEXISTING_USERS = 'deactivate_nonexisting_users';
public const SETTING_GET_USERS_DELTA = 'script_users_delta';
public const SETTING_GET_USERGROUPS_DELTA = 'script_usergroups_delta';
public const SETTING_GROUP_FILTER = 'group_filter_regex';

public const URL_TYPE_AUTHORIZE = 'login';
public const URL_TYPE_LOGOUT = 'logout';
Expand Down Expand Up @@ -66,6 +67,7 @@ protected function __construct()
self::SETTING_DEACTIVATE_NONEXISTING_USERS => 'boolean',
self::SETTING_GET_USERS_DELTA => 'boolean',
self::SETTING_GET_USERGROUPS_DELTA => 'boolean',
self::SETTING_GROUP_FILTER => 'text',
];

parent::__construct('2.5', '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 @@ -121,6 +121,8 @@ protected function getAzureUsers(): Generator
*/
protected function getAzureGroups(): Generator
{
$groupFilter = $this->plugin->get(AzureActiveDirectory::SETTING_GROUP_FILTER);

$groupFields = [
'id',
'displayName',
Expand Down Expand Up @@ -161,6 +163,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 bf8f2dd

Please sign in to comment.