7
7
from sign_client .error import AssertionException as ClientException
8
8
9
9
from sign_client .model import DetailedUserInfo , GroupInfo , UserGroupsInfo , UserGroupInfo , DetailedGroupInfo , UserStateInfo
10
+ import re
10
11
11
12
12
13
class SignSyncEngine :
@@ -130,6 +131,18 @@ def log_action_summary(self):
130
131
for description , count in self .action_summary .items ():
131
132
self .logger .info (' {}: {}' .format (description .rjust (pad , ' ' ), count ))
132
133
134
+ def sign_user_excluded (self , user , user_groups , connector ):
135
+ if 'users' in connector .exclusion_options :
136
+ for rule in connector .exclusion_options ['users' ]:
137
+ if rule .match (user .email .lower ()):
138
+ return True
139
+ if 'groups' in connector .exclusion_options :
140
+ user_group_names = set ([ug .name .lower () for ug in user_groups ])
141
+ for group in connector .exclusion_options ['groups' ]:
142
+ if group .lower () in user_group_names :
143
+ return True
144
+ return False
145
+
133
146
def update_sign_users (self , directory_users , sign_connector : SignConnector , org_name ):
134
147
"""
135
148
Updates user details or inserts new user
@@ -139,9 +152,12 @@ def update_sign_users(self, directory_users, sign_connector: SignConnector, org_
139
152
:return:
140
153
"""
141
154
# Fetch the list of active Sign users
142
- sign_users = {user .email : user for user in sign_connector .get_users ().values () if user .status != 'INACTIVE' }
143
- inactive_sign_users = {user .email : user for user in sign_connector .get_users ().values () if user .status == 'INACTIVE' }
144
155
sign_user_groups = sign_connector .get_user_groups ()
156
+ all_users = sign_connector .get_users ().values ()
157
+ filtered_users = {user .email : user for user in all_users if not self .sign_user_excluded (user , sign_user_groups [user .id ], sign_connector )}
158
+ sign_users = {user .email : user for user in filtered_users .values () if user .status != 'INACTIVE' }
159
+ inactive_sign_users = {user .email : user for user in filtered_users .values () if user .status == 'INACTIVE' }
160
+ self .excluded_users = {user .email : user for user in all_users if self .sign_user_excluded (user , sign_user_groups [user .id ], sign_connector )}
145
161
self .sign_user_primary_groups [org_name ] = {id : [g for g in groups if g .isPrimaryGroup ][0 ] for id , groups in sign_user_groups .items ()}
146
162
users_update_list = []
147
163
user_groups_update_list = []
@@ -161,6 +177,9 @@ def update_sign_users(self, directory_users, sign_connector: SignConnector, org_
161
177
assignment_group = self .default_groups [org_name ].groupName
162
178
user_roles = self .retrieve_admin_role (directory_user )
163
179
if sign_user is None :
180
+ if directory_user ['email' ] in self .excluded_users :
181
+ self .logger .debug ("(%s) Found excluded user %s directory user list, skipping" , org_name , directory_user ['email' ])
182
+ continue
164
183
if sign_connector .create_users :
165
184
inactive_user = inactive_sign_users .get (directory_user_key )
166
185
# if Standalone user is inactive, we need to reactivate instead of trying to create new account
0 commit comments