self delete and role categorized
This commit is contained in:
@@ -91,8 +91,10 @@ class RoleController:
|
|||||||
"category": ra.access.category,
|
"category": ra.access.category,
|
||||||
"name": ra.access.name,
|
"name": ra.access.name,
|
||||||
"parent_id": str(ra.access.parent_id) if ra.access.parent_id else None,
|
"parent_id": str(ra.access.parent_id) if ra.access.parent_id else None,
|
||||||
|
"module_name": "SaaS (Internal)",
|
||||||
}
|
}
|
||||||
for ra in role.role_accesses
|
for ra in role.role_accesses
|
||||||
|
if ra.access
|
||||||
]
|
]
|
||||||
|
|
||||||
accesses.extend([
|
accesses.extend([
|
||||||
@@ -102,8 +104,11 @@ class RoleController:
|
|||||||
"category": rma.module_access.category,
|
"category": rma.module_access.category,
|
||||||
"name": rma.module_access.name,
|
"name": rma.module_access.name,
|
||||||
"parent_id": str(rma.module_access.parent_id) if rma.module_access.parent_id else None,
|
"parent_id": str(rma.module_access.parent_id) if rma.module_access.parent_id else None,
|
||||||
|
"module_id": str(rma.module_access.module_id) if rma.module_access.module_id else None,
|
||||||
|
"module_name": rma.module_access.module.module_name if (rma.module_access and rma.module_access.module) else "DocQube",
|
||||||
}
|
}
|
||||||
for rma in role.role_module_accesses
|
for rma in role.role_module_accesses
|
||||||
|
if rma.module_access
|
||||||
])
|
])
|
||||||
|
|
||||||
return RoleWithAccessesResponse(
|
return RoleWithAccessesResponse(
|
||||||
|
|||||||
@@ -173,7 +173,12 @@ class RoleService:
|
|||||||
equality `get_all_roles` and the paginated list already apply, so global
|
equality `get_all_roles` and the paginated list already apply, so global
|
||||||
(tenant-less) roles stay invisible to tenants.
|
(tenant-less) roles stay invisible to tenants.
|
||||||
"""
|
"""
|
||||||
query = db.query(Role).filter(Role.id == role_id)
|
query = db.query(Role).options(
|
||||||
|
joinedload(Role.role_accesses).joinedload(RoleAccess.access),
|
||||||
|
joinedload(Role.role_module_accesses)
|
||||||
|
.joinedload(RoleModuleAccess.module_access)
|
||||||
|
.joinedload(ModuleAccess.module),
|
||||||
|
).filter(Role.id == role_id)
|
||||||
|
|
||||||
if not actor_is_superadmin:
|
if not actor_is_superadmin:
|
||||||
if actor_tenant_id is None:
|
if actor_tenant_id is None:
|
||||||
|
|||||||
@@ -177,6 +177,12 @@ class UserService:
|
|||||||
if tenant_id:
|
if tenant_id:
|
||||||
update_dict.pop("tenant_id", None)
|
update_dict.pop("tenant_id", None)
|
||||||
|
|
||||||
|
if str(user_id) == str(user.id) and update_dict.get("status") in ["inactive", "disabled"]:
|
||||||
|
raise HTTPException(
|
||||||
|
status_code=status.HTTP_400_BAD_REQUEST,
|
||||||
|
detail="You cannot deactivate your own account.",
|
||||||
|
)
|
||||||
|
|
||||||
if update_dict.get("status") == "active" and user.status != "active":
|
if update_dict.get("status") == "active" and user.status != "active":
|
||||||
SeatService.assert_seat_available(db, user.tenant_id)
|
SeatService.assert_seat_available(db, user.tenant_id)
|
||||||
|
|
||||||
@@ -292,6 +298,12 @@ class UserService:
|
|||||||
@staticmethod
|
@staticmethod
|
||||||
def delete_user(db: Session, user_id: uuid.UUID, tenant_id: uuid.UUID = None,
|
def delete_user(db: Session, user_id: uuid.UUID, tenant_id: uuid.UUID = None,
|
||||||
actor_id: uuid.UUID = None):
|
actor_id: uuid.UUID = None):
|
||||||
|
if actor_id and str(actor_id) == str(user_id):
|
||||||
|
raise HTTPException(
|
||||||
|
status_code=status.HTTP_400_BAD_REQUEST,
|
||||||
|
detail="You cannot delete your own account.",
|
||||||
|
)
|
||||||
|
|
||||||
user = UserService.get_user_by_id(db, user_id, tenant_id)
|
user = UserService.get_user_by_id(db, user_id, tenant_id)
|
||||||
|
|
||||||
targets = []
|
targets = []
|
||||||
|
|||||||
Reference in New Issue
Block a user