From 06b2c623cb17ee601210243ce43f227e56a303e6 Mon Sep 17 00:00:00 2001 From: ibuler Date: Fri, 16 Sep 2016 17:23:47 +0800 Subject: [PATCH] Modify some bug --- apps/perms/models.py | 25 ++++++------------- .../perms/asset_permission_asset_list.html | 4 +-- .../perms/asset_permission_detail.html | 6 +---- .../perms/asset_permission_user_list.html | 4 +-- apps/perms/utils.py | 11 ++++---- apps/users/templates/users/user_detail.html | 8 +++--- 6 files changed, 24 insertions(+), 34 deletions(-) diff --git a/apps/perms/models.py b/apps/perms/models.py index 25ac3640d..ac0257af4 100644 --- a/apps/perms/models.py +++ b/apps/perms/models.py @@ -32,38 +32,29 @@ class AssetPermission(models.Model): return True return True - @staticmethod - def set_inherited(obj, inherited_from=None): - setattr(obj, 'inherited', True) - setattr(obj, 'inherited_from', inherited_from) - return obj - - @staticmethod - def set_non_inherited(obj): - setattr(obj, 'inherited', False) - return obj - def get_granted_users(self): - users_granted_direct = map(self.set_non_inherited, self.users.all()) - return list(set(users_granted_direct) | self.get_granted_user_groups_member()) + return list(set(self.users.all()) | self.get_granted_user_groups_member()) def get_granted_user_groups_member(self): users = set() for user_group in self.user_groups.all(): for user in user_group.users.all(): - user = self.set_inherited(user, inherited_from=user_group) + setattr(user, 'is_inherit_from_user_groups', True) + setattr(user, 'inherit_from_user_groups', + getattr(user, b'inherit_from_user_groups', set()).add(user_group)) users.add(user) return users def get_granted_assets(self): - assets_granted_direct = map(self.set_non_inherited, self.assets.all()) - return list(set(assets_granted_direct or []) | self.get_granted_asset_groups_member()) + return list(set(self.assets.all()) | self.get_granted_asset_groups_member()) def get_granted_asset_groups_member(self): assets = set() for asset_group in self.asset_groups.all(): for asset in asset_group.assets.all(): - asset = self.set_inherited(asset, inherited_from=asset_group) + setattr(asset, 'is_inherit_from_asset_groups', True) + setattr(asset, 'inherit_from_asset_groups', + getattr(asset, b'inherit_from_user_groups', set()).add(asset_group)) assets.add(asset) return assets diff --git a/apps/perms/templates/perms/asset_permission_asset_list.html b/apps/perms/templates/perms/asset_permission_asset_list.html index baad101d1..b6c0cfb00 100644 --- a/apps/perms/templates/perms/asset_permission_asset_list.html +++ b/apps/perms/templates/perms/asset_permission_asset_list.html @@ -26,7 +26,7 @@
  • - {% trans 'Assets and asset gruops' %} + {% trans 'Assets and asset groups' %}