From abc4c1400183872d34fcaaccd22777dab87a8283 Mon Sep 17 00:00:00 2001 From: Lucian N Date: Mon, 9 Oct 2023 22:52:16 +0300 Subject: [PATCH 1/6] Update umapi.py Fixes #827 --- user_sync/engine/umapi.py | 18 +----------------- 1 file changed, 1 insertion(+), 17 deletions(-) diff --git a/user_sync/engine/umapi.py b/user_sync/engine/umapi.py index ef14303a..a739fa4f 100644 --- a/user_sync/engine/umapi.py +++ b/user_sync/engine/umapi.py @@ -869,27 +869,11 @@ 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) commands.remove_groups(groups_to_remove) From 6133dbdad563a147449fc59032f203cfdcd23cf4 Mon Sep 17 00:00:00 2001 From: Lucian N Date: Mon, 9 Oct 2023 23:20:26 +0300 Subject: [PATCH 2/6] Update test_umapi_engine.py --- tests/test_umapi_engine.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/test_umapi_engine.py b/tests/test_umapi_engine.py index 2592506b..7a8cd590 100644 --- a/tests/test_umapi_engine.py +++ b/tests/test_umapi_engine.py @@ -156,9 +156,9 @@ def update(up_user, up_attrs): result = update(user, up_attrs) assert result['user'] == user['email'] - user['email'] = 'different@example.com' + user['email'] = 'user1@example.com' up_attrs = { - 'email': user['email']} + 'email': 'different@example.com'} result = update(user, up_attrs) assert result == { From 28062e0ab632ee9da2cf6b313a3e2e73473c5037 Mon Sep 17 00:00:00 2001 From: Lucian N Date: Mon, 9 Oct 2023 23:44:48 +0300 Subject: [PATCH 3/6] Update test_umapi_engine.py --- tests/test_umapi_engine.py | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/tests/test_umapi_engine.py b/tests/test_umapi_engine.py index 7a8cd590..22dea968 100644 --- a/tests/test_umapi_engine.py +++ b/tests/test_umapi_engine.py @@ -143,7 +143,6 @@ def update(up_user, up_attrs): up_attrs = { 'firstname': user['firstname'], 'lastname': user['lastname']} - result = update(user, up_attrs) assert result == { 'user': user['email'], @@ -152,21 +151,40 @@ def update(up_user, up_attrs): 'firstname': user['firstname'], 'lastname': user['lastname']})]} + up_attrs = {'username': 'different@example.com'} user['username'] = 'different@example.com' result = update(user, up_attrs) assert result['user'] == user['email'] - user['email'] = 'user1@example.com' + up_attrs = {'username': 'different@example.com'} + user['username'] = 'different@example.com' + result = update(user, up_attrs) + assert result == { + 'user': user['email'], + 'domain': user['domain'], + 'do_list': [('update', { + 'username': user['username'] })]} + up_attrs = { 'email': 'different@example.com'} result = update(user, up_attrs) - assert result == { 'user': user['email'], 'domain': user['domain'], 'do_list': [('update', { - 'email': 'different@example.com', - 'username': user['username']})]} + 'email': 'different@example.com'})]} + + user['username'] = 'example1' + user['domain'] = 'example.com' + user['email'] = 'example1@example.com' + up_attrs = { + 'email': 'differentone@example.com'} + result = update(user, up_attrs) + assert result == { + 'user': user['username'], + 'domain': user['domain'], + 'do_list': [('update', { + 'email': 'differentone@example.com'})]} def test_create_umapi_commands_for_directory_user(rule_processor, mock_dir_user): From 8af0070df3e76ff990676228903d729def4f61e0 Mon Sep 17 00:00:00 2001 From: Lucian N Date: Mon, 9 Oct 2023 23:46:07 +0300 Subject: [PATCH 4/6] Update test_umapi_engine.py fix tests From 49f44bb3d7b0d69c2feb1cdf53ba78e7d5889b83 Mon Sep 17 00:00:00 2001 From: Lucian N Date: Tue, 10 Oct 2023 01:19:28 +0300 Subject: [PATCH 5/6] Update test_umapi_engine.py update tests --- tests/test_umapi_engine.py | 38 +++++++++++++++----------------------- 1 file changed, 15 insertions(+), 23 deletions(-) diff --git a/tests/test_umapi_engine.py b/tests/test_umapi_engine.py index 22dea968..38828671 100644 --- a/tests/test_umapi_engine.py +++ b/tests/test_umapi_engine.py @@ -139,53 +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']})]} - - up_attrs = {'username': 'different@example.com'} - user['username'] = 'different@example.com' - result = update(user, up_attrs) - assert result['user'] == user['email'] - - up_attrs = {'username': 'different@example.com'} - user['username'] = 'different@example.com' + 'firstname': up_attrs['firstname'], + 'lastname': up_attrs['lastname']})]} + + up_attrs = { + 'username': 'different'} result = update(user, up_attrs) assert result == { 'user': user['email'], 'domain': user['domain'], 'do_list': [('update', { - 'username': user['username'] })]} + 'username': up_attrs['username']})]} up_attrs = { - 'email': 'different@example.com'} + 'username': 'different@example.com'} result = update(user, up_attrs) assert result == { 'user': user['email'], 'domain': user['domain'], 'do_list': [('update', { - 'email': 'different@example.com'})]} + 'username': up_attrs['username']})]} - user['username'] = 'example1' - user['domain'] = 'example.com' - user['email'] = 'example1@example.com' up_attrs = { - 'email': 'differentone@example.com'} + 'email': 'different@example.com'} result = update(user, up_attrs) assert result == { - 'user': user['username'], + 'user': user['email'], 'domain': user['domain'], 'do_list': [('update', { - 'email': 'differentone@example.com'})]} - + 'email': up_attrs['email']})]} + def test_create_umapi_commands_for_directory_user(rule_processor, mock_dir_user): rp = rule_processor From 18086af5ca7c9f72b85feddf32c91067d9414d86 Mon Sep 17 00:00:00 2001 From: Lucian N Date: Tue, 10 Oct 2023 09:29:59 +0300 Subject: [PATCH 6/6] Update umapi.py removing other useless lines in update_umapi_user function --- user_sync/engine/umapi.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/user_sync/engine/umapi.py b/user_sync/engine/umapi.py index a739fa4f..52e5af59 100644 --- a/user_sync/engine/umapi.py +++ b/user_sync/engine/umapi.py @@ -868,11 +868,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') commands = user_sync.connector.connector_umapi.Commands(directory_user['email'], directory_user['domain']) commands.update_user(attributes_to_update)