Don't link to the user details of admin or staff

Signed-off-by: Roberto Rosario <roberto.rosario.gonzalez@gmail.com>
This commit is contained in:
Roberto Rosario
2019-04-30 12:59:55 -04:00
parent 3faefd653c
commit 11e13cea1d
2 changed files with 26 additions and 3 deletions

View File

@@ -29,6 +29,13 @@ class ObjectLinkWidget(object):
except AttributeError:
url = None
if getattr(value, 'is_staff', None) or getattr(value, 'is_superuser', None):
# Don't display a anchor to for the user details view for
# superusers and staff, the details view filters them. Staff
# and admin users are not manageable by the normal user views.
url = '#'
return '{}{}'.format(object_type, label)
return self.template.render(
context=Context(
{'label': label, 'object_type': object_type, 'url': url or '#'}

View File

@@ -163,9 +163,11 @@ class GroupViewsTestCase(GroupTestMixin, GroupViewTestMixin, UserTestMixin, Gene
class SuperUserViewTestCase(UserTestMixin, UserViewTestMixin, GenericViewTestCase):
def test_superuser_delete_view_with_access(self):
def setUp(self):
super(SuperUserViewTestCase, self).setUp()
self._create_test_superuser()
def test_superuser_delete_view_with_access(self):
superuser_count = get_user_model().objects.filter(is_superuser=True).count()
self.grant_access(
obj=self.test_superuser, permission=permission_user_delete
@@ -178,14 +180,28 @@ class SuperUserViewTestCase(UserTestMixin, UserViewTestMixin, GenericViewTestCas
)
def test_superuser_detail_view_with_access(self):
self._create_test_superuser()
self.grant_access(
obj=self.test_superuser, permission=permission_user_view
)
response = self._request_test_superuser_detail_view()
self.assertEqual(response.status_code, 404)
def _request_test_user_detail_view(self):
return self.get(
viewname='user_management:user_details', kwargs={
'pk': self.test_user.pk
}
)
def test_superuser_normal_user_detail_view_with_access(self):
self.grant_access(
obj=self.test_superuser, permission=permission_user_view
)
self.test_user = self.test_superuser
response = self._request_test_user_detail_view()
self.assertEqual(response.status_code, 404)
class UserViewTestCase(UserTestMixin, UserViewTestMixin, GenericViewTestCase):
def test_user_create_view_no_permission(self):