forked from retoor/devplacepy
feat: restrict backup archive download to primary admin and hide admin-hidden projects from other admins
- Add `get_admin_uids()` and `get_primary_admin_uid()` to database.py for resolving the earliest-created admin - Modify `can_view_project()` in content.py so a project hidden by an admin is invisible to other admins (both web UI and REST API) - Update `_download_url()` and `_backup_payload()` in admin/backups.py to accept a `can_download` flag, gating the download endpoint with `is_primary_admin()` - Remove `role` from `_user_facts()` in docs_live.py to avoid leaking admin status in live docs - Update doc summaries in docs_api.py to reflect the new admin-visibility and backup-download semantics
This commit is contained in:
@@ -0,0 +1,61 @@
|
||||
# retoor <retoor@molodetz.nl>
|
||||
|
||||
from devplacepy.routers.admin.users import _is_senior_admin, _seniority_key
|
||||
|
||||
SENIOR_ADMIN = {
|
||||
"uid": "senior",
|
||||
"role": "Admin",
|
||||
"created_at": "2024-01-01T00:00:00+00:00",
|
||||
"id": 1,
|
||||
}
|
||||
JUNIOR_ADMIN = {
|
||||
"uid": "junior",
|
||||
"role": "Admin",
|
||||
"created_at": "2025-01-01T00:00:00+00:00",
|
||||
"id": 9,
|
||||
}
|
||||
OLD_MEMBER = {
|
||||
"uid": "member",
|
||||
"role": "Member",
|
||||
"created_at": "2020-01-01T00:00:00+00:00",
|
||||
"id": 0,
|
||||
}
|
||||
|
||||
|
||||
def test_junior_admin_cannot_manage_senior_admin():
|
||||
assert _is_senior_admin(JUNIOR_ADMIN, SENIOR_ADMIN) is True
|
||||
|
||||
|
||||
def test_senior_admin_can_manage_junior_admin():
|
||||
assert _is_senior_admin(SENIOR_ADMIN, JUNIOR_ADMIN) is False
|
||||
|
||||
|
||||
def test_members_are_never_protected():
|
||||
assert _is_senior_admin(JUNIOR_ADMIN, OLD_MEMBER) is False
|
||||
assert _is_senior_admin(SENIOR_ADMIN, OLD_MEMBER) is False
|
||||
|
||||
|
||||
def test_acting_on_self_is_not_protected():
|
||||
assert _is_senior_admin(SENIOR_ADMIN, SENIOR_ADMIN) is False
|
||||
assert _is_senior_admin(JUNIOR_ADMIN, JUNIOR_ADMIN) is False
|
||||
|
||||
|
||||
def test_none_target_is_not_protected():
|
||||
assert _is_senior_admin(SENIOR_ADMIN, None) is False
|
||||
|
||||
|
||||
def test_equal_created_at_tiebreaks_on_id():
|
||||
earlier = {"uid": "e1", "role": "Admin", "created_at": "2024-01-01T00:00:00", "id": 3}
|
||||
later = {"uid": "e2", "role": "Admin", "created_at": "2024-01-01T00:00:00", "id": 5}
|
||||
assert _is_senior_admin(later, earlier) is True
|
||||
assert _is_senior_admin(earlier, later) is False
|
||||
|
||||
|
||||
def test_missing_created_at_sorts_oldest_failsafe():
|
||||
no_date = {"uid": "nc", "role": "Admin", "created_at": None, "id": 2}
|
||||
assert _is_senior_admin(SENIOR_ADMIN, no_date) is True
|
||||
|
||||
|
||||
def test_seniority_key_orders_by_created_at_then_id():
|
||||
assert _seniority_key(SENIOR_ADMIN) < _seniority_key(JUNIOR_ADMIN)
|
||||
assert _seniority_key({"created_at": None, "id": 0}) == ("", 0)
|
||||
Reference in New Issue
Block a user