Merge pull request #3065 from yueguobin/feat/project-privileges-endpoint

Add endpoint for the current user's privileges on a project
This commit is contained in:
Jeremy Grossmann authored and GitHub committed 2026-11-07 05:31:29 +01:00
commit 01c20adac5
4 files changed
+248

No files matched your search

@@ -191,6 +191,46 @@ def get_project(response: Response, project: Project = Depends(dep_project)) ->
return project_dict
@router.get(
"/{project_id}/me/privileges",
response_model=schemas.ProjectPrivileges,
responses=GET_RESPONSES,
dependencies=[Depends(has_privilege("Project.Audit"))],
)
async def get_logged_in_user_privileges_on_project(
current_user: schemas.User = Depends(get_current_active_user),
project: Project = Depends(dep_project),
rbac_repo: RbacRepository = Depends(get_repository(RbacRepository)),
) -> schemas.ProjectPrivileges:
"""
Get the effective privileges of the current user on this project.
Unlike /access/users/me/privileges (flattened across all resource paths),
each privilege is evaluated on the project's resource path, so the result
reflects ACEs scoped to this project and resource pools containing it.
This is meant for rendering purposes (e.g. showing or hiding buttons in
the project view): the server remains the authority for permission checks.
Required privilege: Project.Audit
Example: curl -X GET http://host:port/v3/projects/{project_id}/me/privileges -H "Authorization: Bearer <token>"
"""
if current_user.is_superadmin:
privilege_names = sorted(privilege.name for privilege in await rbac_repo.get_privileges())
return schemas.ProjectPrivileges(is_superadmin=True, privileges=privilege_names)
path = f"/projects/{project.id}"
# the flat view is the superset: only privileges granted somewhere can be
# granted on this path, so only those need to be evaluated against it
candidates = await rbac_repo.get_user_privileges(current_user.user_id)
project_privileges = []
for name in candidates:
if await rbac_repo.check_user_has_privilege(current_user.user_id, path, name):
project_privileges.append(name)
return schemas.ProjectPrivileges(is_superadmin=False, privileges=sorted(project_privileges))
@router.put(
"/{project_id}",
response_model=schemas.Project,
+2
View File
@@ -71,6 +71,7 @@ from .controller.projects import (
ProjectCreate,
ProjectDuplicate,
ProjectFile,
ProjectPrivileges,
ProjectStats,
ProjectUpdate,
)
@@ -351,6 +352,7 @@ __all__ = [
"ProjectDuplicate",
"ProjectFile",
"ProjectMarker",
"ProjectPrivileges",
"ProjectStats",
"ProjectUpdate",
"Qemu",
+15
View File
@@ -139,3 +139,18 @@ class ProjectStats(BaseModel):
drawings: int
snapshots: int
markers: int
class ProjectPrivileges(BaseModel):
"""
Effective privileges of the logged in user on a single project, evaluated
on the project's resource path (so ACEs scoped to that project and
resource pools containing it are reflected).
This is a hint for rendering purposes only (e.g. showing or hiding buttons
in the project view): the server remains the authority for permission
checks on each request.
"""
is_superadmin: bool
privileges: List[str]