From 4e7b665ea872b7f20230b339d6ea614e01c3a5d2 Mon Sep 17 00:00:00 2001 From: ibuler Date: Wed, 29 Mar 2017 15:26:32 +0800 Subject: [PATCH] =?UTF-8?q?[Change]=20=E6=B7=BB=E5=8A=A0=E7=BF=BB=E8=AF=91?= =?UTF-8?q?=EF=BC=8C=E5=B9=B6=E6=B7=BB=E5=8A=A0=E7=94=A8=E6=88=B7=E7=99=BB?= =?UTF-8?q?=E9=99=86=E9=A1=B5=E9=9D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/assets/api.py | 9 +- apps/assets/hands.py | 3 +- apps/assets/models/asset.py | 7 +- .../assets/templates/assets/asset_detail.html | 2 +- .../templates/assets/user_asset_list.html | 266 ++++++++++++++++++ apps/assets/urls/views_urls.py | 3 + apps/assets/views.py | 13 + apps/locale/zh/LC_MESSAGES/django.po | 48 +--- apps/perms/api.py | 26 ++ apps/perms/urls/api_urls.py | 5 +- apps/templates/_nav_user.html | 25 +- apps/templates/_user_profile.html | 1 + apps/users/templates/users/user_profile.html | 208 +++++++------- 13 files changed, 462 insertions(+), 154 deletions(-) create mode 100644 apps/assets/templates/assets/user_asset_list.html diff --git a/apps/assets/api.py b/apps/assets/api.py index 37ed15c5c..29e694f6f 100644 --- a/apps/assets/api.py +++ b/apps/assets/api.py @@ -11,7 +11,7 @@ from django.shortcuts import get_object_or_404 from common.mixins import IDInFilterMixin from common.utils import get_object_or_none, signer -from .hands import IsSuperUser, IsAppUser +from .hands import IsSuperUser, IsAppUser, IsValidUser, get_user_granted_assets from .models import AssetGroup, Asset, IDC, SystemUser, AdminUser from . import serializers @@ -20,10 +20,13 @@ class AssetViewSet(IDInFilterMixin, BulkModelViewSet): """API endpoint that allows Asset to be viewed or edited.""" queryset = Asset.objects.all() serializer_class = serializers.AssetSerializer - permission_classes = (IsSuperUser,) + permission_classes = (IsValidUser,) def get_queryset(self): - queryset = super(AssetViewSet, self).get_queryset() + if self.request.user.is_superuser: + queryset = super(AssetViewSet, self).get_queryset() + else: + queryset = get_user_granted_assets(self.request.user) idc_id = self.request.query_params.get('idc_id', '') system_users_id = self.request.query_params.get('system_user_id', '') asset_group_id = self.request.query_params.get('asset_group_id', '') diff --git a/apps/assets/hands.py b/apps/assets/hands.py index 633a995f6..61d432db2 100644 --- a/apps/assets/hands.py +++ b/apps/assets/hands.py @@ -12,5 +12,6 @@ from users.utils import AdminUserRequiredMixin -from users.permissions import IsAppUser, IsSuperUser +from users.permissions import IsAppUser, IsSuperUser, IsValidUser from users.models import User, UserGroup +from perms.utils import get_user_granted_assets \ No newline at end of file diff --git a/apps/assets/models/asset.py b/apps/assets/models/asset.py index 54a2d4820..8a6d0bad6 100644 --- a/apps/assets/models/asset.py +++ b/apps/assets/models/asset.py @@ -99,7 +99,12 @@ class Asset(models.Model): return False, warning def to_json(self): - pass + return { + 'id': self.id, + 'hostname': self.hostname, + 'ip': self.ip, + 'port': self.port, + } def _to_secret_json(self): """Ansible use it create inventory""" diff --git a/apps/assets/templates/assets/asset_detail.html b/apps/assets/templates/assets/asset_detail.html index 81c4f7a69..9878e1f0d 100644 --- a/apps/assets/templates/assets/asset_detail.html +++ b/apps/assets/templates/assets/asset_detail.html @@ -16,7 +16,7 @@