diff --git a/seahub/api2/endpoints/admin/sysinfo.py b/seahub/api2/endpoints/admin/sysinfo.py index 1ad51837be..7a717257fa 100644 --- a/seahub/api2/endpoints/admin/sysinfo.py +++ b/seahub/api2/endpoints/admin/sysinfo.py @@ -1,12 +1,8 @@ import logging import os -from django.utils.dateformat import DateFormat -from django.utils.translation import ugettext as _ -from django.template.defaultfilters import filesizeformat - from rest_framework.authentication import SessionAuthentication -from rest_framework.permissions import IsAuthenticated, IsAdminUser +from rest_framework.permissions import IsAdminUser from rest_framework.response import Response from rest_framework.views import APIView from rest_framework import status @@ -14,13 +10,12 @@ from rest_framework import status from seaserv import seafile_api, ccnet_api from pysearpc import SearpcError -from seahub.utils.rpc import mute_seafile_api from seahub.utils import is_pro_version from seahub.utils.licenseparse import parse_license -from seahub.api2.utils import api_error from seahub.api2.authentication import TokenAuthentication from seahub.api2.throttling import UserRateThrottle +from seahub.api2.utils import api_error import seahub.settings try: @@ -34,11 +29,16 @@ class SysInfo(APIView): """Show system info. """ authentication_classes = (TokenAuthentication, SessionAuthentication) + throttle_classes = (UserRateThrottle, ) permission_classes = (IsAdminUser,) def get(self, request, format=None): # count repos - repos_count = mute_seafile_api.count_repos() + try: + repos_count = seafile_api.count_repos() + except SearpcError as e: + logger.error(e) + repos_count = 0 # count groups try: @@ -49,14 +49,14 @@ class SysInfo(APIView): # count orgs if MULTI_TENANCY: - multi_tenacy_enabled = True + multi_tenancy_enabled = True try: org_count = ccnet_api.count_orgs() except Exception as e: logger.error(e) org_count = 0 else: - multi_tenacy_enabled = False + multi_tenancy_enabled = False org_count = 0 # count users @@ -108,7 +108,7 @@ class SysInfo(APIView): 'repos_count': repos_count, 'groups_count': groups_count, 'org_count': org_count, - 'multi_tenancy_enabled': multi_tenacy_enabled, + 'multi_tenancy_enabled': multi_tenancy_enabled, 'is_pro': is_pro, 'with_license': with_license, 'license': license_dict diff --git a/static/scripts/sysadmin-app/views/dashboard.js b/static/scripts/sysadmin-app/views/dashboard.js index fb9e67ae74..8818b6d60d 100644 --- a/static/scripts/sysadmin-app/views/dashboard.js +++ b/static/scripts/sysadmin-app/views/dashboard.js @@ -3,7 +3,7 @@ define([ 'underscore', 'backbone', 'common', - 'sysadmin-app/models/SysInfo' + 'sysadmin-app/models/sysinfo' ], function($, _, Backbone, Common, SysInfo) { 'use strict'; diff --git a/tests/api/endpoints/admin/test_sysinfo.py b/tests/api/endpoints/admin/test_sysinfo.py new file mode 100644 index 0000000000..119b3c3ab3 --- /dev/null +++ b/tests/api/endpoints/admin/test_sysinfo.py @@ -0,0 +1,21 @@ +import json + +from django.core.urlresolvers import reverse +from seahub.test_utils import BaseTestCase + +class AccountTest(BaseTestCase): + def setUp(self): + self.login_as(self.admin) + + def tearDown(self): + self.remove_repo() + + def test_get_sysinfo(self): + + url = reverse('api-v2.1-sysinfo') + resp = self.client.get(url) + json_resp = json.loads(resp.content) + + assert len(json_resp) == 9 + assert json_resp['is_pro'] == False + assert json_resp['multi_tenancy_enabled'] == False