perf: Pam rbac

This commit is contained in:
feng
2025-07-22 18:59:32 +08:00
committed by ZhaoJiSen
parent 299e52cd11
commit 1df04d2a94
5 changed files with 22 additions and 8 deletions

View File

@@ -215,6 +215,10 @@ class RoleMixin:
def workbench_orgs(self):
return self.cached_orgs.get("workbench_orgs", [])
@lazyproperty
def pam_orgs(self):
return self.cached_orgs.get("pam_orgs", [])
@lazyproperty
def joined_orgs(self):
from rbac.models import RoleBinding
@@ -229,6 +233,7 @@ class RoleMixin:
data = cache.get(key)
if data:
return data
pam_orgs = RoleBinding.get_user_has_the_perm_orgs("rbac.view_pam", self)
console_orgs = RoleBinding.get_user_has_the_perm_orgs("rbac.view_console", self)
audit_orgs = RoleBinding.get_user_has_the_perm_orgs("rbac.view_audit", self)
workbench_orgs = RoleBinding.get_user_has_the_perm_orgs(
@@ -239,6 +244,7 @@ class RoleMixin:
audit_orgs = list(set(audit_orgs) - set(console_orgs))
data = {
"pam_orgs": pam_orgs,
"console_orgs": console_orgs,
"audit_orgs": audit_orgs,
"workbench_orgs": workbench_orgs,

View File

@@ -188,6 +188,7 @@ class UserOrgSerializer(serializers.Serializer):
class UserPermsSerializer(serializers.Serializer):
id = serializers.CharField(label=_("User ID"), read_only=True)
username = serializers.CharField(label=_("Username"), read_only=True)
pam_orgs = UserOrgSerializer(many=True, read_only=True)
console_orgs = UserOrgSerializer(many=True, read_only=True)
audit_orgs = UserOrgSerializer(many=True, read_only=True)
workbench_orgs = UserOrgSerializer(many=True, read_only=True)