From 0b7631ee979f3b5498317652765c3a14e8f4c3ef Mon Sep 17 00:00:00 2001 From: Benjamin Dauvergne Date: Tue, 7 Jul 2020 12:00:47 +0200 Subject: [PATCH 2/5] hobo_notify: set is_active attribute (#42428) --- tests/test_hobo_notify.py | 4 ++++ wcs/ctl/hobo_notify.py | 7 +++++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/tests/test_hobo_notify.py b/tests/test_hobo_notify.py index 7e2c8579..43e7bbaf 100644 --- a/tests/test_hobo_notify.py +++ b/tests/test_hobo_notify.py @@ -514,6 +514,7 @@ def test_process_notification_user_provision(pub): u'email': u'john.doe@example.net', u'zipcode': u'13400', u'is_superuser': False, + 'is_active': True, u'roles': [ { u'uuid': u'12345', @@ -542,6 +543,7 @@ def test_process_notification_user_provision(pub): assert user.form_data['_birthdate'] is None assert user.name_identifiers == ['a'*32] assert user.is_admin is False + assert user.is_active is True assert set(user.roles) == set([new_role.id, old_role.id]) notification = { @@ -559,6 +561,7 @@ def test_process_notification_user_provision(pub): u'zipcode': u'13600', u'birthdate': u'2000-01-01', u'is_superuser': True, + 'is_active': False, u'roles': [ { u'uuid': u'xyz', @@ -587,6 +590,7 @@ def test_process_notification_user_provision(pub): assert user.form_data['_birthdate'].tm_year == 2000 assert user.name_identifiers == ['a'*32] assert user.is_admin is True + assert user.is_active is False assert set(user.roles) == set([old_role.id]) for birthdate in ('baddate', '', None): diff --git a/wcs/ctl/hobo_notify.py b/wcs/ctl/hobo_notify.py index 8391d025..7ab6be1f 100644 --- a/wcs/ctl/hobo_notify.py +++ b/wcs/ctl/hobo_notify.py @@ -191,6 +191,7 @@ class CmdHoboNotify(Command): user.form_data[field.id] = field_value user.name_identifiers = [uuid] # reset roles + user.is_active = o.get('is_active', True) user.is_admin = o.get('is_superuser', False) user.roles = [] for role_ref in o.get('roles', []): @@ -208,8 +209,10 @@ class CmdHoboNotify(Command): elif action == 'deprovision': if 'uuid' not in o: raise KeyError('user without uuid') - # do not remove for real - pass + # make user inactive, he will be deleted later + for user in User.get_users_with_name_identifier(uuid): + user.is_active = False + user.store() except Exception as e: publisher.notify_of_exception(sys.exc_info(), context='[PROVISIONNING]') -- 2.26.2