Commit 79554b47 authored by ibuler's avatar ibuler

[Update] Merge

parents 31d2f2a7 1983533e
...@@ -17,12 +17,11 @@ from common.tree import TreeNodeSerializer ...@@ -17,12 +17,11 @@ from common.tree import TreeNodeSerializer
from common.utils import get_logger from common.utils import get_logger
from ..utils import ( from ..utils import (
AssetPermissionUtil, parse_asset_to_tree_node, parse_node_to_tree_node, AssetPermissionUtil, parse_asset_to_tree_node, parse_node_to_tree_node,
check_system_user_action,
) )
from ..hands import User, Asset, Node, SystemUser, NodeSerializer from ..hands import User, Asset, Node, SystemUser, NodeSerializer
from .. import serializers, const from .. import serializers, const
from ..mixins import AssetsFilterMixin from ..mixins import AssetsFilterMixin
from ..models import Action from ..models import ActionFlag
logger = get_logger(__name__) logger = get_logger(__name__)
...@@ -405,7 +404,7 @@ class UserGrantedNodeChildrenApi(UserPermissionCacheMixin, ListAPIView): ...@@ -405,7 +404,7 @@ class UserGrantedNodeChildrenApi(UserPermissionCacheMixin, ListAPIView):
class ValidateUserAssetPermissionApi(UserPermissionCacheMixin, APIView): class ValidateUserAssetPermissionApi(UserPermissionCacheMixin, APIView):
permission_classes = (IsOrgAdminOrAppUser,) permission_classes = (IsOrgAdminOrAppUser,)
def get(self, request, *args, **kwargs): def get(self, request, *args, **kwargs):
user_id = request.query_params.get('user_id', '') user_id = request.query_params.get('user_id', '')
asset_id = request.query_params.get('asset_id', '') asset_id = request.query_params.get('asset_id', '')
...@@ -415,17 +414,17 @@ class ValidateUserAssetPermissionApi(UserPermissionCacheMixin, APIView): ...@@ -415,17 +414,17 @@ class ValidateUserAssetPermissionApi(UserPermissionCacheMixin, APIView):
user = get_object_or_404(User, id=user_id) user = get_object_or_404(User, id=user_id)
asset = get_object_or_404(Asset, id=asset_id) asset = get_object_or_404(Asset, id=asset_id)
su = get_object_or_404(SystemUser, id=system_id) su = get_object_or_404(SystemUser, id=system_id)
action = get_object_or_404(Action, name=action_name)
util = AssetPermissionUtil(user, cache_policy=self.cache_policy) util = AssetPermissionUtil(user, cache_policy=self.cache_policy)
granted_assets = util.get_assets() granted_assets = util.get_assets()
granted_system_users = granted_assets.get(asset, []) granted_system_users = granted_assets.get(asset, {})
if su not in granted_system_users: if su not in granted_system_users:
return Response({'msg': False}, status=403) return Response({'msg': False}, status=403)
_su = next((s for s in granted_system_users if s.id == su.id), None) action = granted_system_users[su]
if not check_system_user_action(_su, action): choices = ActionFlag.value_to_choices(action)
if action_name not in choices:
return Response({'msg': False}, status=403) return Response({'msg': False}, status=403)
return Response({'msg': True}, status=200) return Response({'msg': True}, status=200)
...@@ -433,7 +432,7 @@ class ValidateUserAssetPermissionApi(UserPermissionCacheMixin, APIView): ...@@ -433,7 +432,7 @@ class ValidateUserAssetPermissionApi(UserPermissionCacheMixin, APIView):
class GetUserAssetPermissionActionsApi(UserPermissionCacheMixin, RetrieveAPIView): class GetUserAssetPermissionActionsApi(UserPermissionCacheMixin, RetrieveAPIView):
permission_classes = (IsOrgAdminOrAppUser,) permission_classes = (IsOrgAdminOrAppUser,)
serializers_class = serializers.ActionsSerializer serializer_class = serializers.ActionsSerializer
def get_object(self): def get_object(self):
user_id = self.request.query_params.get('user_id', '') user_id = self.request.query_params.get('user_id', '')
...@@ -448,6 +447,9 @@ class GetUserAssetPermissionActionsApi(UserPermissionCacheMixin, RetrieveAPIView ...@@ -448,6 +447,9 @@ class GetUserAssetPermissionActionsApi(UserPermissionCacheMixin, RetrieveAPIView
granted_assets = util.get_assets() granted_assets = util.get_assets()
granted_system_users = granted_assets.get(asset, {}) granted_system_users = granted_assets.get(asset, {})
_object = {}
if su not in granted_system_users: if su not in granted_system_users:
return {"actions": 0} _object['actions'] = 0
return granted_system_users[su] else:
_object['actions'] = granted_system_users[su]
return _object
...@@ -27,7 +27,6 @@ logger = get_logger(__file__) ...@@ -27,7 +27,6 @@ logger = get_logger(__file__)
__all__ = [ __all__ = [
'AssetPermissionUtil', 'is_obj_attr_has', 'sort_assets', 'AssetPermissionUtil', 'is_obj_attr_has', 'sort_assets',
'parse_asset_to_tree_node', 'parse_node_to_tree_node', 'parse_asset_to_tree_node', 'parse_node_to_tree_node',
'check_system_user_action',
] ]
...@@ -597,16 +596,3 @@ def parse_asset_to_tree_node(node, asset, system_users): ...@@ -597,16 +596,3 @@ def parse_asset_to_tree_node(node, asset, system_users):
} }
tree_node = TreeNode(**data) tree_node = TreeNode(**data)
return tree_node return tree_node
def check_system_user_action(system_user, action):
"""
:param system_user: SystemUser object (包含动态属性: actions)
:param action: Action object
:return: bool
"""
check_actions = [Action.get_action_all(), action]
granted_actions = getattr(system_user, 'actions', [])
actions = list(set(granted_actions).intersection(set(check_actions)))
return bool(actions)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment