mirror of
https://github.com/jumpserver/jumpserver.git
synced 2025-09-25 06:42:49 +00:00
perf: 批量上传添加权限校验
This commit is contained in:
@@ -42,6 +42,10 @@ class ActionChoices(BitChoices):
|
||||
def contains(cls, total, action_value):
|
||||
return action_value & total == action_value
|
||||
|
||||
@classmethod
|
||||
def contains_all(cls, total, action_values):
|
||||
return all(cls.contains(total, action) for action in action_values)
|
||||
|
||||
@classmethod
|
||||
def display(cls, value):
|
||||
return ', '.join([str(c.label) for c in cls if c.value & value == c.value])
|
||||
|
@@ -6,6 +6,7 @@ from assets.models import Asset
|
||||
from common.utils import lazyproperty
|
||||
from orgs.utils import tmp_to_org, tmp_to_root_org
|
||||
from .permission import AssetPermissionUtil
|
||||
from perms.const import ActionChoices
|
||||
|
||||
__all__ = ['PermAssetDetailUtil']
|
||||
|
||||
@@ -137,3 +138,23 @@ class PermAssetDetailUtil:
|
||||
account.date_expired = max(cleaned_accounts_expired[account])
|
||||
accounts.append(account)
|
||||
return accounts
|
||||
|
||||
def check_perm_protocols(self, protocols):
|
||||
"""
|
||||
检查用户是否有某些协议权限
|
||||
:param protocols: set
|
||||
"""
|
||||
perms_protocols = self.get_permed_protocols_for_user(only_name=True)
|
||||
if "all" in perms_protocols:
|
||||
return True
|
||||
return protocols.intersection(perms_protocols)
|
||||
|
||||
def check_perm_actions(self, account_name, actions):
|
||||
"""
|
||||
检查用户是否有某个账号的某个资产操作权限
|
||||
:param account_name: str
|
||||
:param actions: list
|
||||
"""
|
||||
perms = self.user_asset_perms
|
||||
action_bit_mapper, __ = self.parse_alias_action_date_expire(perms, self.asset)
|
||||
return ActionChoices.contains_all(action_bit_mapper.get(account_name, 0), actions)
|
||||
|
Reference in New Issue
Block a user