Resolve the primary administrator to an account that can authenticate

The primary administrator was the earliest Admin by created_at with no further
condition, so a soft-deleted or deactivated account could hold the role and then
be refused by the api-key path, leaving nobody able to use the database API, the
backup download or cross-owner container management. Rows with no recorded signup
time also sorted ahead of every real account. Scan the earliest admins instead and
take the first that is neither deleted nor deactivated, with missing timestamps
sorted last.

Also stop the projects listing returning 500 when project_type or description is
NULL (the dict default never applies to an existing NULL column), align the issue
test fixture with its unit twin so a combined run cannot collide on a fixed uid,
read the settings value from the database rather than a stale per-process cache,
and give the seeded and fixture admins the is_active and created_at fields that
every real signup writes.
This commit is contained in:
2026-07-26 19:58:18 +02:00
parent 535e9c5dc1
commit ca6c527e32
8 changed files with 132 additions and 8 deletions
+69
View File
@@ -0,0 +1,69 @@
# retoor <retoor@molodetz.nl>
def test_primary_admin_ignores_accounts_without_a_signup_time(local_db):
from devplacepy.database import get_primary_admin_uid, invalidate_admins_cache
users = local_db["users"]
users.insert(
{
"uid": "pa-real",
"username": "pa-real",
"role": "Admin",
"created_at": "2020-01-01T00:00:00",
"deleted_at": None,
}
)
users.insert(
{
"uid": "pa-null",
"username": "pa-null",
"role": "Admin",
"created_at": None,
"deleted_at": None,
}
)
users.insert(
{
"uid": "pa-blank",
"username": "pa-blank",
"role": "Admin",
"created_at": "",
"deleted_at": None,
}
)
invalidate_admins_cache()
try:
assert get_primary_admin_uid() == "pa-real"
finally:
for uid in ("pa-real", "pa-null", "pa-blank"):
users.delete(uid=uid)
invalidate_admins_cache()
def test_primary_admin_skips_deactivated_and_deleted_founders(local_db):
from devplacepy.database import get_primary_admin_uid, invalidate_admins_cache
users = local_db["users"]
seeded = [
("pa-deleted", "2001-01-01T00:00:00", True, "2020-01-01T00:00:00"),
("pa-inactive", "2002-01-01T00:00:00", False, None),
("pa-usable", "2003-01-01T00:00:00", True, None),
]
for uid, created_at, active, deleted_at in seeded:
users.insert(
{
"uid": uid,
"username": uid,
"role": "Admin",
"created_at": created_at,
"is_active": active,
"deleted_at": deleted_at,
}
)
invalidate_admins_cache()
try:
assert get_primary_admin_uid() == "pa-usable"
finally:
for uid, _, _, _ in seeded:
users.delete(uid=uid)
invalidate_admins_cache()