From 3b30eb3278bd5650127156777395ff2f3d0bbeb7 Mon Sep 17 00:00:00 2001 From: ibuler Date: Tue, 15 Nov 2016 23:09:36 +0800 Subject: [PATCH] Weiteng --- apps/perms/api.py | 32 ++++++++++++++++++- apps/perms/urls.py | 8 ++++- .../users/user_group_asset_permission.html | 2 +- .../templates/users/user_group_detail.html | 2 +- apps/users/urls.py | 2 +- apps/users/views.py | 2 +- 6 files changed, 42 insertions(+), 6 deletions(-) diff --git a/apps/perms/api.py b/apps/perms/api.py index bb499bc95..b84901241 100644 --- a/apps/perms/api.py +++ b/apps/perms/api.py @@ -7,7 +7,7 @@ from rest_framework import viewsets from users.backends import IsValidUser, IsSuperUser from common.utils import get_object_or_none from .utils import get_user_granted_assets, get_user_granted_asset_groups, get_user_asset_permissions, \ - get_user_group_asset_permissions, get_user_group_granted_assets + get_user_group_asset_permissions, get_user_group_granted_assets, get_user_group_granted_asset_groups from .models import AssetPermission from .hands import AssetGrantedSerializer, User, UserGroup, AssetGroup, Asset, AssetGroup, AssetGroupSerializer from . import serializers @@ -155,3 +155,33 @@ class MyAssetGroupAssetsApi(ListAPIView): if asset_group in asset.groups.all(): queryset.append(asset) return queryset + + +class UserGroupGrantedAssetsApi(ListAPIView): + permission_classes = (IsSuperUser,) + serializer_class = AssetGrantedSerializer + + def get_queryset(self): + user_group_id = self.kwargs.get('pk', '') + + if user_group_id: + user_group = get_object_or_404(User, id=user_group_id) + queryset = get_user_group_granted_assets(user_group) + else: + queryset = [] + return queryset + + +class UserGroupGrantedAssetGroupsApi(ListAPIView): + permission_classes = (IsSuperUser,) + serializer_class = AssetGroupSerializer + + def get_queryset(self): + user_group_id = self.kwargs.get('pk', '') + + if user_group_id: + user_group = get_object_or_404(User, id=user_group_id) + queryset = get_user_group_granted_asset_groups(user_group) + else: + queryset = [] + return queryset \ No newline at end of file diff --git a/apps/perms/urls.py b/apps/perms/urls.py index 1c23b5987..cdd6e67ae 100644 --- a/apps/perms/urls.py +++ b/apps/perms/urls.py @@ -31,11 +31,17 @@ urlpatterns += [ url(r'^v1/user/my/asset-group/(?P[0-9]+)/assets/$', api.MyAssetGroupAssetsApi.as_view(), name='user-my-asset-group-assets'), - # Select user or user group permission of asset or asset group + # Select user permission of asset and asset group url(r'^v1/user/(?P[0-9]+)/assets/$', api.UserGrantedAssetsApi.as_view(), name='api-user-assets'), url(r'^v1/user/(?P[0-9]+)/asset-groups/$', api.UserGrantedAssetGroupsApi.as_view(), name='api-user-asset-groups'), + # Select user group permission of asset and asset group + url(r'^v1/user-group/(?P[0-9]+)/assets/$', api.UserGroupGrantedAssetsApi.as_view(), name='api-user-group-assets'), + url(r'^v1/user-group/(?P[0-9]+)/asset-groups/$', api.UserGroupGrantedAssetGroupsApi.as_view(), + name='api-user-group-asset-groups'), + + # Revoke permission api url(r'^v1/asset-permissions/user/revoke/', api.RevokeUserAssetPermission.as_view(), name='revoke-user-asset-permission'), diff --git a/apps/users/templates/users/user_group_asset_permission.html b/apps/users/templates/users/user_group_asset_permission.html index e2458ffa4..d9edcdd35 100644 --- a/apps/users/templates/users/user_group_asset_permission.html +++ b/apps/users/templates/users/user_group_asset_permission.html @@ -23,7 +23,7 @@ {% trans 'Asset permission' %}
  • - {% trans 'Asset granted' %} + {% trans 'Asset granted' %}
  • diff --git a/apps/users/templates/users/user_group_detail.html b/apps/users/templates/users/user_group_detail.html index cffa9930a..909d13f55 100644 --- a/apps/users/templates/users/user_group_detail.html +++ b/apps/users/templates/users/user_group_detail.html @@ -25,7 +25,7 @@ {% trans 'Asset permission' %}
  • - {% trans 'Asset granted' %} + {% trans 'Asset granted' %}
  • Update diff --git a/apps/users/urls.py b/apps/users/urls.py index 7ede4e38c..3e939eb3a 100644 --- a/apps/users/urls.py +++ b/apps/users/urls.py @@ -36,7 +36,7 @@ urlpatterns = [ url(r'^user-group/(?P[0-9]+)/update$', views.UserGroupUpdateView.as_view(), name='user-group-update'), url(r'^user-group/(?P[0-9]+)/asset-permission$', views.UserGroupAssetPermissionView.as_view(), name='user-group-asset-permission'), - url(r'^user-group/(?P[0-9]+)/asset-permission/create$', views.UserAssetPermissionCreateView.as_view(), + url(r'^user-group/(?P[0-9]+)/asset-permission/create$', views.UserGroupAssetPermissionCreateView.as_view(), name='user-group-asset-permission-create'), url(r'^user-group/(?P[0-9]+)/assets', views.UserGroupGrantedAssetView.as_view(), name='user-group-granted-asset'), diff --git a/apps/users/views.py b/apps/users/views.py index 0a0f4ff75..3203363f8 100644 --- a/apps/users/views.py +++ b/apps/users/views.py @@ -414,7 +414,7 @@ class UserAssetPermissionCreateView(AdminUserRequiredMixin, CreateView): class UserGroupAssetPermissionCreateView(AdminUserRequiredMixin, CreateView): - form_class = forms.UserPrivateAssetPermissionForm + form_class = forms.UserGroupPrivateAssetPermissionForm model = AssetPermission def get(self, request, *args, **kwargs):