Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update umapi.py #826

Open
wants to merge 3 commits into
base: v2
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 21 additions & 25 deletions user_sync/engine/umapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -373,18 +373,35 @@ def read_desired_user_groups(self, mappings, directory_connector):
all_users=directory_group_filter is None)

for directory_user in directory_users:
# only if there actually is hook code: set up rest of hook scope, invoke hook, update user attributes
if options['after_mapping_hook'] is not None:
self.after_mapping_hook_scope['source_attributes'] = directory_user['source_attributes'].copy()
target_attributes = dict()
target_attributes['email'] = directory_user.get('email')
target_attributes['username'] = directory_user.get('username')
target_attributes['domain'] = directory_user.get('domain')
target_attributes['firstname'] = directory_user.get('firstname')
target_attributes['lastname'] = directory_user.get('lastname')
target_attributes['country'] = directory_user.get('country')
self.after_mapping_hook_scope['target_attributes'] = target_attributes

# invoke the customer's hook code
self.log_after_mapping_hook_scope(before_call=True)
exec(options['after_mapping_hook'], self.after_mapping_hook_scope)
self.log_after_mapping_hook_scope(after_call=True)

# copy modified attributes back to the user object
directory_user.update(self.after_mapping_hook_scope['target_attributes'])

user_key = self.get_directory_user_key(directory_user)
if not user_key:
self.logger.warning("Ignoring directory user with empty user key: %s", directory_user)
continue

self.directory_user_index.add(directory_user)

if not self.is_directory_user_in_groups(directory_user, directory_group_filter):
continue
if not self.is_selected_user_key(user_key):
continue

self.directory_user_index.add(directory_user)
self.filtered_directory_user_index.add(directory_user)
umapi_info = self.get_umapi_info(PRIMARY_TARGET_NAME)
umapi_info.add_desired_group_for(directory_user['identity_type'], directory_user['domain'],
Expand All @@ -400,27 +417,6 @@ def read_desired_user_groups(self, mappings, directory_connector):
for adobe_group in adobe_groups:
self.after_mapping_hook_scope['target_groups'].add(adobe_group.get_qualified_name())

# only if there actually is hook code: set up rest of hook scope, invoke hook, update user attributes
if options['after_mapping_hook'] is not None:
self.after_mapping_hook_scope['source_attributes'] = directory_user['source_attributes'].copy()

target_attributes = dict()
target_attributes['email'] = directory_user.get('email')
target_attributes['username'] = directory_user.get('username')
target_attributes['domain'] = directory_user.get('domain')
target_attributes['firstname'] = directory_user.get('firstname')
target_attributes['lastname'] = directory_user.get('lastname')
target_attributes['country'] = directory_user.get('country')
self.after_mapping_hook_scope['target_attributes'] = target_attributes

# invoke the customer's hook code
self.log_after_mapping_hook_scope(before_call=True)
exec(options['after_mapping_hook'], self.after_mapping_hook_scope)
self.log_after_mapping_hook_scope(after_call=True)

# copy modified attributes back to the user object
directory_user.update(self.after_mapping_hook_scope['target_attributes'])

for target_group_qualified_name in self.after_mapping_hook_scope['target_groups']:
target_group = AdobeGroup.lookup(target_group_qualified_name)
if target_group is not None:
Expand Down
Loading