Skip to content

Update umapi.py #828

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

Open
wants to merge 8 commits into
base: v2
Choose a base branch
from
Open
Show file tree
Hide file tree
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
40 changes: 25 additions & 15 deletions tests/test_umapi_engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,35 +139,45 @@ def update(up_user, up_attrs):
rp.execute_commands(commands, conn)
assert user_key in rp.updated_user_keys
return vars(conn.commands_sent)

up_attrs = {
'firstname': user['firstname'],
'lastname': user['lastname']}

'firstname': 'some',
'lastname': 'other'}
result = update(user, up_attrs)
assert result == {
'user': user['email'],
'domain': user['domain'],
'do_list': [('update', {
'firstname': user['firstname'],
'lastname': user['lastname']})]}

user['username'] = '[email protected]'
'firstname': up_attrs['firstname'],
'lastname': up_attrs['lastname']})]}

up_attrs = {
'username': 'different'}
result = update(user, up_attrs)
assert result['user'] == user['email']

user['email'] = '[email protected]'
assert result == {
'user': user['email'],
'domain': user['domain'],
'do_list': [('update', {
'username': up_attrs['username']})]}

up_attrs = {
'email': user['email']}
'username': '[email protected]'}
result = update(user, up_attrs)

assert result == {
'user': user['email'],
'domain': user['domain'],
'do_list': [('update', {
'email': '[email protected]',
'username': user['username']})]}
'username': up_attrs['username']})]}

up_attrs = {
'email': '[email protected]'}
result = update(user, up_attrs)
assert result == {
'user': user['email'],
'domain': user['domain'],
'do_list': [('update', {
'email': up_attrs['email']})]}


def test_create_umapi_commands_for_directory_user(rule_processor, mock_dir_user):
rp = rule_processor
Expand Down
20 changes: 1 addition & 19 deletions user_sync/engine/umapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -872,27 +872,9 @@ def update_umapi_user(self, umapi_info, user_key, attributes_to_update=None, gro

directory_user = self.get_from_index(self.directory_user_index, user_key)
if directory_user is not None:
identity_type = self.get_identity_type_from_directory_user(directory_user)
directory_user['email'] = umapi_user['email']
else:
directory_user = umapi_user
identity_type = umapi_user.get('type')

# if user has email-type username and it is different from email address, then we need to
# override the username with email address
if '@' in directory_user['username'] and normalize_string(directory_user['email']) != normalize_string(directory_user['username']):
if groups_to_add or groups_to_remove or attributes_to_update:
directory_user['username'] = directory_user['email']
if attributes_to_update and 'email' in attributes_to_update:
directory_user['email'] = umapi_user['email']
attributes_to_update['username'] = umapi_user['username']
directory_user['username'] = umapi_user['email']

# if email based username on umapi is differ than email on umapi and need to update email, then we need to
# override the username with email address
if '@' in umapi_user['username'] and normalize_string(umapi_user['username']) != normalize_string(umapi_user['email']):
if attributes_to_update and 'email' in attributes_to_update:
directory_user['email'] = umapi_user['email']
directory_user['username'] = umapi_user['email']

commands = user_sync.connector.connector_umapi.Commands(directory_user['email'], directory_user['domain'])
commands.update_user(attributes_to_update)
Expand Down
Loading