浏览代码

[IMP] resources

Gogs 7 年之前
父节点
当前提交
8bc0a9dc1b
共有 4 个文件被更改,包括 15 次插入3 次删除
  1. 2 1
      api/resources/docker_resource.py
  2. 3 0
      api/resources/git_resource.py
  3. 9 1
      api/resources/odoo_resource.py
  4. 1 1
      ui/templates/index.html

+ 2 - 1
api/resources/docker_resource.py

@@ -122,4 +122,5 @@ class DockerResource(Resource):
             
             
         return self.create_response(request, {
         return self.create_response(request, {
             'container': container_data
             'container': container_data
-        })
+        })
+        

+ 3 - 0
api/resources/git_resource.py

@@ -4,11 +4,13 @@ from django.conf.urls import url
 from django.conf import settings
 from django.conf import settings
 from tastypie.resources import Resource
 from tastypie.resources import Resource
 from tastypie.utils import trailing_slash
 from tastypie.utils import trailing_slash
+from api.utils.jwt_authentication import JWTAuthentication
 from api.utils.git_api import get_odoo_modules_repos_names
 from api.utils.git_api import get_odoo_modules_repos_names
 
 
 class GitResource(Resource):
 class GitResource(Resource):
     class Meta:
     class Meta:
         resource_name = 'git'
         resource_name = 'git'
+        authentication = JWTAuthentication()
 
 
     '''
     '''
     '''
     '''
@@ -21,6 +23,7 @@ class GitResource(Resource):
     '''
     '''
     def get_repositories(self, request, **kwargs):
     def get_repositories(self, request, **kwargs):
         self.method_check(request, allowed='get')
         self.method_check(request, allowed='get')
+        self.is_authenticated(request)
 
 
         return self.create_response(request, {
         return self.create_response(request, {
             'repositories': get_odoo_modules_repos_names()
             'repositories': get_odoo_modules_repos_names()

+ 9 - 1
api/resources/odoo_resource.py

@@ -20,6 +20,8 @@ from api.utils.odoo_api import (
     get_odoo_internal_ip,
     get_odoo_internal_ip,
     install_modules
     install_modules
 )
 )
+from api.utils.git_api import get_odoo_modules_repos_names
+from api.utils.docker_api import get_all_containers
 from api.utils.jwt_token import get_user
 from api.utils.jwt_token import get_user
 from api.utils.jwt_authentication import JWTAuthentication
 from api.utils.jwt_authentication import JWTAuthentication
 from api.utils.logger import (
 from api.utils.logger import (
@@ -258,7 +260,7 @@ class OdooResource(Resource):
     def install_odoo_modules(self, request, **kwargs):
     def install_odoo_modules(self, request, **kwargs):
         info('odoo module installation is requested')
         info('odoo module installation is requested')
 
 
-        self.method_check(request, allowed='post')
+        self.method_check(request, allowed=['get', 'post'])
         self.is_authenticated(request)
         self.is_authenticated(request)
 
 
         authorization_header = request.META.get(settings.JWT_ACCEPT_HEADER)
         authorization_header = request.META.get(settings.JWT_ACCEPT_HEADER)
@@ -266,6 +268,12 @@ class OdooResource(Resource):
         user = get_user(authorization_header[prefix_length + 1:])
         user = get_user(authorization_header[prefix_length + 1:])
 
 
         info('%s is authenticated' % user.username)
         info('%s is authenticated' % user.username)
+
+        if request.META.get('REQUEST_METHOD') == 'GET':
+            return self.create_response(request, {
+                'odoos': map(lambda x: x['name'], get_all_containers()),
+                'modules': get_odoo_modules_repos_names()
+            })
         
         
         err = {'error_message': None}
         err = {'error_message': None}
         data = None
         data = None

+ 1 - 1
ui/templates/index.html

@@ -10,6 +10,6 @@
     </head>
     </head>
     <body>
     <body>
         <div id="root"></div>
         <div id="root"></div>
-        <script src="{% static 'main.087fc63f.js' %}"></script>
+        <script src="{% static 'main.5d06f93e.js' %}"></script>
     </body>
     </body>
 </html>
 </html>