Commit d80fec6e authored by ibuler's avatar ibuler

Update some api

parent d56f030d
......@@ -12,7 +12,7 @@ from rest_framework.decorators import api_view
from .models import Terminal, TerminalHeatbeat
from .serializers import TerminalSerializer, TerminalHeatbeatSerializer
from .hands import IsSuperUserOrAppUser, User
from .hands import IsSuperUserOrAppUser, IsAppUser, User
from common.utils import get_object_or_none
......@@ -39,7 +39,8 @@ class TerminalRegisterView(ListCreateAPIView):
data['access_key_secret'] = access_key.secret
return Response(data, status=201)
else:
return Response(serializer.errors, status=400)
data = {'msg': 'Not valid', 'detail': ';'.join(serializer.errors)}
return Response(data, status=400)
def list(self, request, *args, **kwargs):
return Response('', status=404)
......@@ -57,10 +58,16 @@ class TerminalViewSet(viewsets.ModelViewSet):
class TerminalHeatbeatViewSet(viewsets.ModelViewSet):
queryset = TerminalHeatbeat.objects.all()
serializer_class = TerminalHeatbeatSerializer
permission_classes = (IsSuperUserOrAppUser,)
permission_classes = (IsAppUser,)
def create(self, request, *args, **kwargs):
terminal = request.user
terminal = request.user.terminal
TerminalHeatbeat.objects.create(terminal=terminal)
return Response({'msg': 'Success'})
return Response({'msg': 'Success'}, status=201)
class TestHeatbeat(APIView):
permission_classes = (IsAppUser,)
def post(self, request):
return Response({'hello': 'world'})
\ No newline at end of file
......@@ -2,5 +2,5 @@
#
from users.models import User
from users.permissions import IsSuperUserOrAppUser
from users.permissions import IsSuperUserOrAppUser, IsAppUser
from audits.models import ProxyLog
\ No newline at end of file
......@@ -14,7 +14,7 @@ class Terminal(models.Model):
name = models.CharField(max_length=30, unique=True, verbose_name=_('Name'))
remote_addr = models.GenericIPAddressField(verbose_name=_('Remote address'), blank=True, null=True)
type = models.CharField(choices=TYPE_CHOICES, max_length=3, blank=True, verbose_name=_('Terminal type'))
user = models.OneToOneField(User, verbose_name='Application user', null=True)
user = models.OneToOneField(User, related_name='terminal', verbose_name='Application user', null=True)
url = models.CharField(max_length=100, blank=True, verbose_name=_('URL to login'))
is_accepted = models.BooleanField(default=False, verbose_name='Is Accepted')
date_created = models.DateTimeField(auto_now_add=True)
......
......@@ -10,11 +10,12 @@ from .. import api
app_name = 'applications'
router = routers.DefaultRouter()
router.register(r'v1/terminal', api.TerminalViewSet, 'terminal')
router.register(r'v1/terminal/heatbeat', api.TerminalHeatbeatViewSet, 'terminal-heatbeat')
router.register(r'v1/terminal', api.TerminalViewSet, 'terminal')
urlpatterns = [
url(r'v1/terminal/register$', api.TerminalRegisterView.as_view(), name='terminal-register')
url(r'^v1/terminal/register/$', api.TerminalRegisterView.as_view(), name='terminal-register'),
# url(r'^v1/terminal/heatbeat/$', api.TestHeatbeat.as_view())
]
urlpatterns += router.urls
\ No newline at end of file
......@@ -51,6 +51,7 @@ class TerminalModelAccept(AdminUserRequiredMixin, JSONResponseMixin, UpdateView)
def form_valid(self, form):
terminal = form.save()
terminal.is_accepted = True
terminal.is_active = True
terminal.save()
data = {
'success': True,
......
......@@ -14,12 +14,12 @@ router.register(r'v1/admin-user', api.AdminUserViewSet, 'admin-user')
router.register(r'v1/system-user', api.SystemUserViewSet, 'system-user')
urlpatterns = [
url(r'^v1/assets_bulk$', api.AssetListUpdateApi.as_view(), name='asset-bulk-update'),
url(r'^v1/assets_bulk/$', api.AssetListUpdateApi.as_view(), name='asset-bulk-update'),
# url(r'^v1/idc/(?P<pk>[0-9]+)/assets/$', api.IDCAssetsApi.as_view(), name='api-idc-assets'),
url(r'^v1/system-user/auth', api.SystemUserAuthApi.as_view(), name='system-user-auth'),
url(r'^v1/assets/(?P<pk>\d+)/groups$',
url(r'^v1/system-user/auth/', api.SystemUserAuthApi.as_view(), name='system-user-auth'),
url(r'^v1/assets/(?P<pk>\d+)/groups/$',
api.AssetUpdateGroupApi.as_view(), name='asset-update-group'),
url(r'^v1/assets/(?P<pk>\d+)/system-users$',
url(r'^v1/assets/(?P<pk>\d+)/system-users/$',
api.SystemUserUpdateApi.as_view(), name='asset-update-systemusers'),
]
......
......@@ -7,8 +7,8 @@ app_name = 'audits'
router = routers.DefaultRouter()
router.register(r'v1/proxy-log', api.ProxyLogViewSet, 'proxy-log')
router.register(r'v1/command-log', api.CommandLogViewSet, 'command-log')
router.register(r'v1/proxy-log/', api.ProxyLogViewSet, 'proxy-log')
router.register(r'v1/command-log/', api.CommandLogViewSet, 'command-log')
urlpatterns = router.urls
......@@ -28,7 +28,7 @@ class IsAppUser(IsValidUser, permissions.BasePermission):
def has_permission(self, request, view):
return super(IsAppUser, self).has_permission(request, view) \
and request.user.is_app()
and request.user.is_app
class IsSuperUser(IsValidUser, permissions.BasePermission):
......
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