summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDan Callaghan <dcallagh@redhat.com>2017-10-06 14:26:30 +1000
committerDan Callaghan <dcallagh@redhat.com>2017-10-12 06:29:04 +0000
commit32416d9e38f34cf5cce899302667a39be28ed90e (patch)
tree6543bd6e48e5ea9321283caee8bdf38c7ac8d23a
parent54ed1cfcbce6c8871487de6c8b018f1d8a53c5a6 (diff)
transfer pool ownership when removing a user
Similar to how we transfer system ownership. Bug: 1498374 Change-Id: I2803163812ddf1772af4deecb5ff1ec948103e24
-rw-r--r--IntegrationTests/src/bkr/inttest/client/test_remove_account.py8
-rw-r--r--IntegrationTests/src/bkr/inttest/server/selenium/test_users.py7
-rw-r--r--Server/assets/jst/user.html2
-rw-r--r--Server/bkr/server/user.py7
4 files changed, 21 insertions, 3 deletions
diff --git a/IntegrationTests/src/bkr/inttest/client/test_remove_account.py b/IntegrationTests/src/bkr/inttest/client/test_remove_account.py
index 189d5bc..959f527 100644
--- a/IntegrationTests/src/bkr/inttest/client/test_remove_account.py
+++ b/IntegrationTests/src/bkr/inttest/client/test_remove_account.py
@@ -67,6 +67,7 @@ class RemoveAccountTest(ClientTestCase):
reserved_system.reserve_manually(service=u'testdata', user=user)
reserved_system.custom_access_policy.add_rule(
SystemPermission.reserve, user=user)
+ owned_pool = data_setup.create_system_pool(owning_user=user)
group = data_setup.create_group(owner=user)
run_client(['bkr', 'remove-account', user.user_name])
with session.begin():
@@ -108,6 +109,13 @@ class RemoveAccountTest(ClientTestCase):
self.assertEqual(owned_system.activity[0].action, u'Changed')
self.assertEqual(owned_system.activity[0].old_value, user.user_name)
self.assertEqual(owned_system.activity[0].new_value, data_setup.ADMIN_USER)
+ # pools owned by the user should be transferred to the caller
+ self.assertEqual(owned_pool.owner.user_name, data_setup.ADMIN_USER)
+ self.assertEqual(owned_pool.activity[0].user.user_name, data_setup.ADMIN_USER)
+ self.assertEqual(owned_pool.activity[0].field_name, u'Owner')
+ self.assertEqual(owned_pool.activity[0].action, u'Changed')
+ self.assertEqual(owned_pool.activity[0].old_value, user.user_name)
+ self.assertEqual(owned_pool.activity[0].new_value, data_setup.ADMIN_USER)
# group membership/ownership should be removed
self.assertNotIn(group, user.groups)
self.assertNotIn(user, group.users)
diff --git a/IntegrationTests/src/bkr/inttest/server/selenium/test_users.py b/IntegrationTests/src/bkr/inttest/server/selenium/test_users.py
index 91f3174..9bc43f6 100644
--- a/IntegrationTests/src/bkr/inttest/server/selenium/test_users.py
+++ b/IntegrationTests/src/bkr/inttest/server/selenium/test_users.py
@@ -537,6 +537,7 @@ class UserHTTPTest(DatabaseTestCase):
reserved_system.reserve_manually(service=u'testdata', user=user)
reserved_system.custom_access_policy.add_rule(
SystemPermission.reserve, user=user)
+ owned_pool = data_setup.create_system_pool(owning_user=user)
group = data_setup.create_group(owner=user)
s = requests.Session()
requests_login(s)
@@ -569,6 +570,12 @@ class UserHTTPTest(DatabaseTestCase):
self.assertEqual(owned_system.activity[0].action, u'Changed')
self.assertEqual(owned_system.activity[0].old_value, user.user_name)
self.assertEqual(owned_system.activity[0].new_value, data_setup.ADMIN_USER)
+ # pools owned by the user should be transferred to the caller
+ self.assertEqual(owned_pool.owner.user_name, data_setup.ADMIN_USER)
+ self.assertEqual(owned_pool.activity[0].field_name, u'Owner')
+ self.assertEqual(owned_pool.activity[0].action, u'Changed')
+ self.assertEqual(owned_pool.activity[0].old_value, user.user_name)
+ self.assertEqual(owned_pool.activity[0].new_value, data_setup.ADMIN_USER)
# group membership/ownership should be removed
self.assertNotIn(group, user.groups)
self.assertNotIn(user, group.users)
diff --git a/Server/assets/jst/user.html b/Server/assets/jst/user.html
index 0b13821..9718c87 100644
--- a/Server/assets/jst/user.html
+++ b/Server/assets/jst/user.html
@@ -92,7 +92,7 @@
<p>The user’s running jobs will be cancelled and their outstanding
system reservations and loans will be returned. They will be removed
from all groups and system access policies. Ownership of the user’s
- systems will be transferred to you.</p>
+ systems and system pools will be transferred to you.</p>
<p><strong class="text-error">This operation is destructive and cannot be undone.</strong></p>
<p>
<button class="btn btn-danger delete" data-loading-text="<i class='fa fa-trash-o fa-spin'></i> Deleting&hellip;"><i class="fa fa-trash-o"></i> Delete</button>
diff --git a/Server/bkr/server/user.py b/Server/bkr/server/user.py
index 36cd0b8..16a9639 100644
--- a/Server/bkr/server/user.py
+++ b/Server/bkr/server/user.py
@@ -40,8 +40,9 @@ class Users(RPCRoot):
* it is removed from all groups and access policies
* any running jobs owned by the account are cancelled
* any systems reserved by or loaned to the account are returned
- * any systems owned by the account are transferred to the admin running this
- command, or some other user if specified using the *newowner* parameter
+ * any systems and system pools owned by the account are transferred to
+ the admin running this command, or some other user if specified using
+ the *newowner* parameter
* the account is disabled for further login
:param username: An existing username
@@ -100,6 +101,8 @@ def _remove(user, method, **kw):
system.record_activity(user=identity.current.user, service=method,
action=u'Changed', field=u'Owner',
old=u'%s' % user, new=u'%s' % newowner)
+ for pool in SystemPool.query.filter(SystemPool.owning_user == user):
+ pool.change_owner(user=newowner, service=method)
# Remove the user from all groups
for group in user.groups:
if not group.membership_type == GroupMembershipType.inverted: