24 lines
694 B
Python
24 lines
694 B
Python
from __future__ import annotations
|
|
|
|
from sqlalchemy.orm import Session
|
|
|
|
from app.core.menu_guard import SUPER_ADMIN_ROLE, get_user_menu_codes
|
|
|
|
PLAN_CERT_UPLOAD_PERM = "pl:plan-cert:upload"
|
|
PLAN_CERT_READY_PERM = "pl:plan-cert:ready"
|
|
|
|
|
|
def user_has_menu_perm(db: Session, user, perm: str) -> bool:
|
|
if getattr(user, "role", None) == SUPER_ADMIN_ROLE:
|
|
return True
|
|
codes = get_user_menu_codes(db, user.id)
|
|
return perm in codes
|
|
|
|
|
|
def user_can_upload_plan_cert(db: Session, user) -> bool:
|
|
return user_has_menu_perm(db, user, PLAN_CERT_UPLOAD_PERM)
|
|
|
|
|
|
def user_can_manage_plan_cert_ready(db: Session, user) -> bool:
|
|
return user_has_menu_perm(db, user, PLAN_CERT_READY_PERM)
|