Update api

pull/530/head
ibuler 2016-10-19 19:30:55 +08:00
parent 6164896793
commit df380c343e
7 changed files with 51 additions and 7 deletions

View File

@ -24,7 +24,7 @@ urlpatterns = [
url(r'^$', TemplateView.as_view(template_name='base.html'), name='index'), url(r'^$', TemplateView.as_view(template_name='base.html'), name='index'),
url(r'^(api/)?users/', include('users.urls')), url(r'^(api/)?users/', include('users.urls')),
url(r'^assets/', include('assets.urls')), url(r'^assets/', include('assets.urls')),
url(r'^perms/', include('perms.urls')), url(r'^(api/)?perms/', include('perms.urls')),
url(r'^(api/)?audits/', include('audits.urls')), url(r'^(api/)?audits/', include('audits.urls')),
url(r'^(api/)?terminal/', include('terminal.urls')), url(r'^(api/)?terminal/', include('terminal.urls')),
] ]

View File

@ -1,3 +1,30 @@
# ~*~ coding: utf-8 ~*~ # ~*~ coding: utf-8 ~*~
# #
from rest_framework.views import APIView, Response
from users.backends import IsValidUser
from .utils import get_user_granted_assets, get_user_granted_asset_groups
class UserAssetsGrantedApi(APIView):
permission_classes = (IsValidUser,)
def get(self, request, *args, **kwargs):
assets_json = []
user = request.user
if user:
assets = get_user_granted_assets(user)
for asset, system_users in assets.items():
assets_json.append({
'id': asset.id,
'hostname': asset.hostname,
'ip': asset.ip,
'port': asset.port,
'system_users': [system_user.name for system_user in system_users],
'comment': asset.comment
})
return Response(assets_json, status=200)

View File

@ -1,12 +1,8 @@
# ~*~ coding: utf-8 ~*~ # ~*~ coding: utf-8 ~*~
# #
from django.db import models
from django.utils.translation import ugettext_lazy as _
from users.utils import AdminUserRequiredMixin from users.utils import AdminUserRequiredMixin
# from users.backends import IsValdiUser
from users.models import User, UserGroup from users.models import User, UserGroup
from assets.models import Asset, AssetGroup, SystemUser from assets.models import Asset, AssetGroup, SystemUser

14
apps/perms/serializers.py Normal file
View File

@ -0,0 +1,14 @@
# -*- coding: utf-8 -*-
#
from rest_framework import serializers
class TerminalHeatbeatSerializer(serializers.ModelSerializer):
class Meta:
model = TerminalHeatbeat
fields = ['terminal']
if __name__ == '__main__':
pass

View File

@ -2,6 +2,7 @@
from django.conf.urls import url from django.conf.urls import url
import views import views
import api
app_name = 'perms' app_name = 'perms'
@ -20,3 +21,8 @@ urlpatterns = [
name='asset-permission-asset-list'), name='asset-permission-asset-list'),
] ]
urlpatterns += [
url(r'^v1/user/assets/granted/$', api.UserAssetsGrantedApi.as_view(),
name='user-assets-granted'),
]

View File

@ -6,6 +6,7 @@ from rest_framework.compat import is_authenticated
from django.utils.translation import ugettext as _ from django.utils.translation import ugettext as _
from common.utils import unsign, get_object_or_none from common.utils import unsign, get_object_or_none
from .hands import Terminal from .hands import Terminal

View File

@ -10,6 +10,6 @@
:license: GPL v2, see LICENSE for more details. :license: GPL v2, see LICENSE for more details.
""" """
from terminal.models import Terminal
from perms.models import AssetPermission from perms.models import AssetPermission
from perms.utils import get_user_granted_assets, get_user_granted_asset_groups from perms.utils import get_user_granted_assets, get_user_granted_asset_groups
from terminal.models import Terminal