forked from rapidpro/rapidpro
-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Prevent workspace admins to modify the system user on a workspace
- Loading branch information
Showing
6 changed files
with
66 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1728,6 +1728,13 @@ class UserCRUDLTest(TembaTest, CRUDLTestMixin): | |
def test_list(self): | ||
list_url = reverse("orgs.user_list") | ||
|
||
system_user = self.create_user("[email protected]") | ||
system_user.settings.is_system = True | ||
system_user.settings.save(update_fields=("is_system",)) | ||
|
||
# add system user to workspace | ||
self.org.add_user(system_user, OrgRole.ADMINISTRATOR) | ||
|
||
# nobody can access if users feature not enabled | ||
response = self.requestView(list_url, self.admin) | ||
self.assertRedirect(response, reverse("orgs.org_workspace")) | ||
|
@@ -1775,6 +1782,10 @@ def test_team(self): | |
self.assertContentMenu(team_url, self.admin, ["Edit", "Delete"]) | ||
|
||
def test_update(self): | ||
system_user = self.create_user("[email protected]") | ||
system_user.settings.is_system = True | ||
system_user.settings.save(update_fields=("is_system",)) | ||
|
||
update_url = reverse("orgs.user_update", args=[self.agent.id]) | ||
|
||
# nobody can access if users feature not enabled | ||
|
@@ -1825,16 +1836,34 @@ def test_update(self): | |
self.assertEqual({self.user, self.editor}, set(self.org.get_users(roles=[OrgRole.EDITOR]))) | ||
self.assertEqual({self.admin}, set(self.org.get_users(roles=[OrgRole.ADMINISTRATOR]))) | ||
|
||
# even if we add system user to workspace | ||
self.org.add_user(system_user, OrgRole.ADMINISTRATOR) | ||
response = self.assertUpdateSubmit(update_url, self.admin, {"role": "E"}, object_unchanged=self.admin) | ||
self.assertRedirect(response, reverse("orgs.user_list")) | ||
self.assertEqual({self.user, self.editor}, set(self.org.get_users(roles=[OrgRole.EDITOR]))) | ||
self.assertEqual({self.admin, system_user}, set(self.org.get_users(roles=[OrgRole.ADMINISTRATOR]))) | ||
|
||
# add another admin to workspace and try again | ||
self.org.add_user(self.admin2, OrgRole.ADMINISTRATOR) | ||
|
||
response = self.assertUpdateSubmit(update_url, self.admin, {"role": "E"}, object_unchanged=self.admin) | ||
self.assertRedirect(response, reverse("orgs.org_start")) # no longer have access to user list page | ||
|
||
self.assertEqual({self.user, self.editor, self.admin}, set(self.org.get_users(roles=[OrgRole.EDITOR]))) | ||
self.assertEqual({self.admin2}, set(self.org.get_users(roles=[OrgRole.ADMINISTRATOR]))) | ||
self.assertEqual({self.admin2, system_user}, set(self.org.get_users(roles=[OrgRole.ADMINISTRATOR]))) | ||
|
||
# cannot update system user on a workspace | ||
update_url = reverse("orgs.user_update", args=[system_user.id]) | ||
response = self.requestView(update_url, self.admin2) | ||
self.assertRedirect(response, reverse("orgs.org_choose")) | ||
self.assertEqual({self.user, self.editor, self.admin}, set(self.org.get_users(roles=[OrgRole.EDITOR]))) | ||
self.assertEqual({self.admin2, system_user}, set(self.org.get_users(roles=[OrgRole.ADMINISTRATOR]))) | ||
|
||
def test_delete(self): | ||
system_user = self.create_user("[email protected]") | ||
system_user.settings.is_system = True | ||
system_user.settings.save(update_fields=("is_system",)) | ||
|
||
delete_url = reverse("orgs.user_delete", args=[self.agent.id]) | ||
|
||
# nobody can access if users feature not enabled | ||
|
@@ -1868,6 +1897,16 @@ def test_delete(self): | |
self.assertRedirect(response, reverse("orgs.user_list")) | ||
self.assertEqual({self.user, self.editor, self.admin}, set(self.org.get_users())) | ||
|
||
# cannot still even when the other admin is a system user | ||
self.org.add_user(system_user, OrgRole.ADMINISTRATOR) | ||
response = self.assertDeleteSubmit(delete_url, self.admin, object_unchanged=self.admin) | ||
self.assertRedirect(response, reverse("orgs.user_list")) | ||
self.assertEqual({self.user, self.editor, self.admin, system_user}, set(self.org.get_users())) | ||
|
||
# cannot remove system user too | ||
self.assertRequestDisallowed(reverse("orgs.user_delete", args=[system_user.id]), [self.admin]) | ||
self.assertEqual({self.user, self.editor, self.admin, system_user}, set(self.org.get_users())) | ||
|
||
# add another admin to workspace and try again | ||
self.org.add_user(self.admin2, OrgRole.ADMINISTRATOR) | ||
|
||
|
@@ -1876,7 +1915,7 @@ def test_delete(self): | |
# this time we could remove ourselves | ||
response = self.assertDeleteSubmit(delete_url, self.admin, object_unchanged=self.admin) | ||
self.assertRedirect(response, reverse("orgs.org_choose")) | ||
self.assertEqual({self.user, self.editor, self.admin2}, set(self.org.get_users())) | ||
self.assertEqual({self.user, self.editor, self.admin2, system_user}, set(self.org.get_users())) | ||
|
||
def test_account(self): | ||
self.login(self.agent) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters