Remove unnecessary odd getter from db.operations.
This commit is contained in:
+13
-6
@@ -56,17 +56,24 @@ async def check_admin_credentials() -> bool:
|
||||
bool: True if a reset link was created, False if admin already has credentials
|
||||
"""
|
||||
try:
|
||||
# Get permission organizations to find admin users
|
||||
# Find the auth:admin permission
|
||||
p = next(
|
||||
(p for p in db.data().permissions.values() if p.scope == "auth:admin"), None
|
||||
)
|
||||
if not p or not p.orgs:
|
||||
if not p:
|
||||
return False
|
||||
|
||||
# Get users from the first organization with admin permission
|
||||
first_org_uuid = next(iter(p.orgs))
|
||||
org_users = db.get_organization_users(first_org_uuid)
|
||||
admin_users = [user for user, role in org_users if role == "Administration"]
|
||||
perm_uuid = p.uuid
|
||||
|
||||
# Find all roles that have the auth:admin permission
|
||||
admin_roles = [
|
||||
r for r in db.data().roles.values() if perm_uuid in r.permissions
|
||||
]
|
||||
|
||||
# Collect all users from those roles
|
||||
admin_users = []
|
||||
for role in admin_roles:
|
||||
admin_users.extend(role.users)
|
||||
|
||||
if not admin_users:
|
||||
return False
|
||||
|
||||
@@ -48,7 +48,6 @@ from paskia.db.operations import (
|
||||
delete_sessions_for_user,
|
||||
delete_user,
|
||||
get_config,
|
||||
get_organization_users,
|
||||
get_reset_token,
|
||||
get_user_credential_ids,
|
||||
get_user_organization,
|
||||
@@ -112,7 +111,6 @@ __all__ = [
|
||||
"build_user",
|
||||
# Read ops
|
||||
"get_config",
|
||||
"get_organization_users",
|
||||
"get_reset_token",
|
||||
"get_user_credential_ids",
|
||||
"get_user_organization",
|
||||
|
||||
@@ -65,15 +65,6 @@ def get_user_organization(user_uuid: UUID) -> tuple[Org, str]:
|
||||
return role.org, role.display_name
|
||||
|
||||
|
||||
def get_organization_users(org_uuid: UUID) -> list[tuple[User, str]]:
|
||||
"""Get all users in an organization with their role names.
|
||||
|
||||
Returns list of (User, role_display_name) tuples.
|
||||
"""
|
||||
org = _db.orgs[org_uuid]
|
||||
return [(u, u.role.display_name) for role in org.roles for u in role.users]
|
||||
|
||||
|
||||
def get_user_credential_ids(user_uuid: UUID) -> list[bytes]:
|
||||
"""Get credential IDs for a user (for WebAuthn exclude lists).
|
||||
|
||||
|
||||
@@ -83,7 +83,6 @@ async def admin_list_orgs(request: Request, auth=AUTH_COOKIE):
|
||||
orgs = [o for o in orgs if o.uuid == ctx.org.uuid]
|
||||
|
||||
def org_to_dict(o):
|
||||
users = db.get_organization_users(o.uuid)
|
||||
return {
|
||||
"uuid": o.uuid,
|
||||
"display_name": o.display_name,
|
||||
@@ -101,12 +100,13 @@ async def admin_list_orgs(request: Request, auth=AUTH_COOKIE):
|
||||
{
|
||||
"uuid": u.uuid,
|
||||
"display_name": u.display_name,
|
||||
"role": role_name,
|
||||
"role": r.display_name,
|
||||
"role_uuid": u.role_uuid,
|
||||
"visits": u.visits,
|
||||
"last_seen": u.last_seen,
|
||||
}
|
||||
for (u, role_name) in users
|
||||
for r in o.roles
|
||||
for u in r.users
|
||||
],
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user