Skip to content

Commit 3923a3d

Browse files
committed
Don't show deleted users on admin pages
1 parent 41e805b commit 3923a3d

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

h/views/admin/users.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,23 @@ def users_index(request):
4242
if user is None:
4343
user = models.User.get_by_email(request.db, username, authority)
4444

45+
if (user is not None) and user.deleted:
46+
# Don't show users that're marked as deleted on admin pages.
47+
#
48+
# Users that're marked as deleted can't login or authenticate requests
49+
# in any way. They're in the process of being purged by a background
50+
# task and will soon be really deleted from the DB.
51+
#
52+
# Showing these users on admin pages is confusing because admins may
53+
# have already deleted a user (so the user has been marked as deleted
54+
# and is now going to be purged) and then think that the user has not
55+
# been deleted successfully because they still show up on the admin
56+
# pages.
57+
#
58+
# Also we don't want admins to be able to do things like rename users
59+
# who're marked as deleted and in the process of being purged.
60+
user = None
61+
4562
if user is not None:
4663
svc = request.find_service(name="annotation_stats")
4764
user_meta["annotations_count"] = svc.total_user_annotation_count(user.userid)

tests/unit/h/views/admin/users_test.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,24 @@ def test_users_index_no_user_found(models, pyramid_request):
9494
}
9595

9696

97+
@users_index_fixtures
98+
def test_users_index_user_marked_as_deleted(models, pyramid_request, factories):
99+
pyramid_request.params = {"username": "bob", "authority": "foo.org"}
100+
user = factories.User.build(username="bob", authority="foo.org", deleted=True)
101+
models.User.get_by_username.return_value = user
102+
103+
result = users_index(pyramid_request)
104+
105+
assert result == {
106+
"default_authority": "example.com",
107+
"username": "bob",
108+
"authority": "foo.org",
109+
"user": None,
110+
"user_meta": {},
111+
"format_date": format_date,
112+
}
113+
114+
97115
@users_index_fixtures
98116
def test_users_index_user_found(
99117
models, pyramid_request, factories, annotation_stats_service

0 commit comments

Comments
 (0)