mirror of
https://github.com/haiwen/seahub.git
synced 2025-08-25 10:11:24 +00:00
commit
ad6591fb82
@ -15,7 +15,7 @@ from seahub.api2.utils import api_error
|
|||||||
|
|
||||||
from seahub.base.templatetags.seahub_tags import email2nickname
|
from seahub.base.templatetags.seahub_tags import email2nickname
|
||||||
from seahub.utils.timeutils import datetime_to_isoformat_timestr
|
from seahub.utils.timeutils import datetime_to_isoformat_timestr
|
||||||
from seahub.utils import EVENTS_ENABLED
|
from seahub.utils import is_pro_version
|
||||||
|
|
||||||
class FileAudit(APIView):
|
class FileAudit(APIView):
|
||||||
|
|
||||||
@ -25,7 +25,7 @@ class FileAudit(APIView):
|
|||||||
|
|
||||||
def get(self, request):
|
def get(self, request):
|
||||||
|
|
||||||
if not EVENTS_ENABLED:
|
if not is_pro_version():
|
||||||
error_msg = 'Feature disabled.'
|
error_msg = 'Feature disabled.'
|
||||||
return api_error(status.HTTP_403_FORBIDDEN, error_msg)
|
return api_error(status.HTTP_403_FORBIDDEN, error_msg)
|
||||||
|
|
||||||
|
@ -15,7 +15,7 @@ from seahub.api2.utils import api_error
|
|||||||
|
|
||||||
from seahub.base.templatetags.seahub_tags import email2nickname
|
from seahub.base.templatetags.seahub_tags import email2nickname
|
||||||
from seahub.utils.timeutils import datetime_to_isoformat_timestr
|
from seahub.utils.timeutils import datetime_to_isoformat_timestr
|
||||||
from seahub.utils import EVENTS_ENABLED
|
from seahub.utils import is_pro_version
|
||||||
|
|
||||||
class FileUpdate(APIView):
|
class FileUpdate(APIView):
|
||||||
|
|
||||||
@ -25,7 +25,7 @@ class FileUpdate(APIView):
|
|||||||
|
|
||||||
def get(self, request):
|
def get(self, request):
|
||||||
|
|
||||||
if not EVENTS_ENABLED:
|
if not is_pro_version():
|
||||||
error_msg = 'Feature disabled.'
|
error_msg = 'Feature disabled.'
|
||||||
return api_error(status.HTTP_403_FORBIDDEN, error_msg)
|
return api_error(status.HTTP_403_FORBIDDEN, error_msg)
|
||||||
|
|
||||||
|
@ -8,8 +8,8 @@ from rest_framework import status
|
|||||||
|
|
||||||
from .utils import check_time_period_valid
|
from .utils import check_time_period_valid
|
||||||
from seahub.base.templatetags.seahub_tags import email2nickname
|
from seahub.base.templatetags.seahub_tags import email2nickname
|
||||||
from seahub_extra.sysadmin_extra.models import UserLoginLog
|
|
||||||
from seahub.utils.timeutils import datetime_to_isoformat_timestr
|
from seahub.utils.timeutils import datetime_to_isoformat_timestr
|
||||||
|
from seahub.utils import is_pro_version
|
||||||
from seahub.api2.authentication import TokenAuthentication
|
from seahub.api2.authentication import TokenAuthentication
|
||||||
from seahub.api2.throttling import UserRateThrottle
|
from seahub.api2.throttling import UserRateThrottle
|
||||||
from seahub.api2.utils import api_error
|
from seahub.api2.utils import api_error
|
||||||
@ -24,6 +24,10 @@ class Login(APIView):
|
|||||||
|
|
||||||
def get(self, request):
|
def get(self, request):
|
||||||
|
|
||||||
|
if not is_pro_version():
|
||||||
|
error_msg = 'Feature disabled.'
|
||||||
|
return api_error(status.HTTP_403_FORBIDDEN, error_msg)
|
||||||
|
|
||||||
# check the date format, should be like '2015-10-10'
|
# check the date format, should be like '2015-10-10'
|
||||||
start = request.GET.get('start', None)
|
start = request.GET.get('start', None)
|
||||||
end = request.GET.get('end', None)
|
end = request.GET.get('end', None)
|
||||||
@ -37,6 +41,7 @@ class Login(APIView):
|
|||||||
end = end + ' 23:59:59'
|
end = end + ' 23:59:59'
|
||||||
|
|
||||||
result = []
|
result = []
|
||||||
|
from seahub_extra.sysadmin_extra.models import UserLoginLog
|
||||||
logs = UserLoginLog.objects.filter(login_date__range=(start, end))
|
logs = UserLoginLog.objects.filter(login_date__range=(start, end))
|
||||||
for log in logs:
|
for log in logs:
|
||||||
result.append({
|
result.append({
|
||||||
|
@ -15,7 +15,7 @@ from seahub.api2.utils import api_error
|
|||||||
|
|
||||||
from seahub.base.templatetags.seahub_tags import email2nickname
|
from seahub.base.templatetags.seahub_tags import email2nickname
|
||||||
from seahub.utils.timeutils import datetime_to_isoformat_timestr
|
from seahub.utils.timeutils import datetime_to_isoformat_timestr
|
||||||
from seahub.utils import EVENTS_ENABLED
|
from seahub.utils import is_pro_version
|
||||||
|
|
||||||
class PermAudit(APIView):
|
class PermAudit(APIView):
|
||||||
|
|
||||||
@ -25,9 +25,10 @@ class PermAudit(APIView):
|
|||||||
|
|
||||||
def get(self, request):
|
def get(self, request):
|
||||||
|
|
||||||
if not EVENTS_ENABLED:
|
if not is_pro_version():
|
||||||
error_msg = 'Feature disabled.'
|
error_msg = 'Feature disabled.'
|
||||||
return api_error(status.HTTP_403_FORBIDDEN, error_msg)
|
return api_error(status.HTTP_403_FORBIDDEN, error_msg)
|
||||||
|
|
||||||
# check the date format, should be like '2015-10-10'
|
# check the date format, should be like '2015-10-10'
|
||||||
start = request.GET.get('start', None)
|
start = request.GET.get('start', None)
|
||||||
end = request.GET.get('end', None)
|
end = request.GET.get('end', None)
|
||||||
|
@ -5,10 +5,19 @@ from mock import patch
|
|||||||
from django.core.urlresolvers import reverse
|
from django.core.urlresolvers import reverse
|
||||||
from seahub.test_utils import BaseTestCase
|
from seahub.test_utils import BaseTestCase
|
||||||
|
|
||||||
|
try:
|
||||||
|
from seahub.settings import LOCAL_PRO_DEV_ENV
|
||||||
|
except ImportError:
|
||||||
|
LOCAL_PRO_DEV_ENV = False
|
||||||
|
|
||||||
class AccountTest(BaseTestCase):
|
class AccountTest(BaseTestCase):
|
||||||
|
|
||||||
@patch('seahub.views.file.is_pro_version')
|
@patch('seahub.views.file.is_pro_version')
|
||||||
def test_can_not_get_if_start_time_invalid(self, mock_is_pro_version):
|
def test_can_not_get_if_start_time_invalid(self, mock_is_pro_version):
|
||||||
|
|
||||||
|
if not LOCAL_PRO_DEV_ENV:
|
||||||
|
return
|
||||||
|
|
||||||
mock_is_pro_version.return_value = True
|
mock_is_pro_version.return_value = True
|
||||||
|
|
||||||
self.login_as(self.admin)
|
self.login_as(self.admin)
|
||||||
@ -25,6 +34,10 @@ class AccountTest(BaseTestCase):
|
|||||||
|
|
||||||
@patch('seahub.views.file.is_pro_version')
|
@patch('seahub.views.file.is_pro_version')
|
||||||
def test_can_not_get_if_end_time_invalid(self, mock_is_pro_version):
|
def test_can_not_get_if_end_time_invalid(self, mock_is_pro_version):
|
||||||
|
|
||||||
|
if not LOCAL_PRO_DEV_ENV:
|
||||||
|
return
|
||||||
|
|
||||||
mock_is_pro_version.return_value = True
|
mock_is_pro_version.return_value = True
|
||||||
|
|
||||||
self.login_as(self.admin)
|
self.login_as(self.admin)
|
||||||
@ -40,6 +53,10 @@ class AccountTest(BaseTestCase):
|
|||||||
self.assertEqual(400, resp.status_code)
|
self.assertEqual(400, resp.status_code)
|
||||||
|
|
||||||
def test_can_not_get_if_not_admin(self):
|
def test_can_not_get_if_not_admin(self):
|
||||||
|
|
||||||
|
if not LOCAL_PRO_DEV_ENV:
|
||||||
|
return
|
||||||
|
|
||||||
self.login_as(self.user)
|
self.login_as(self.user)
|
||||||
|
|
||||||
start_timestamp = time.time() - 7 * 24 * 60 * 60
|
start_timestamp = time.time() - 7 * 24 * 60 * 60
|
||||||
|
@ -5,10 +5,19 @@ from mock import patch
|
|||||||
from django.core.urlresolvers import reverse
|
from django.core.urlresolvers import reverse
|
||||||
from seahub.test_utils import BaseTestCase
|
from seahub.test_utils import BaseTestCase
|
||||||
|
|
||||||
|
try:
|
||||||
|
from seahub.settings import LOCAL_PRO_DEV_ENV
|
||||||
|
except ImportError:
|
||||||
|
LOCAL_PRO_DEV_ENV = False
|
||||||
|
|
||||||
class AccountTest(BaseTestCase):
|
class AccountTest(BaseTestCase):
|
||||||
|
|
||||||
@patch('seahub.views.file.is_pro_version')
|
@patch('seahub.views.file.is_pro_version')
|
||||||
def test_can_not_get_if_start_time_invalid(self, mock_is_pro_version):
|
def test_can_not_get_if_start_time_invalid(self, mock_is_pro_version):
|
||||||
|
|
||||||
|
if not LOCAL_PRO_DEV_ENV:
|
||||||
|
return
|
||||||
|
|
||||||
mock_is_pro_version.return_value = True
|
mock_is_pro_version.return_value = True
|
||||||
|
|
||||||
self.login_as(self.admin)
|
self.login_as(self.admin)
|
||||||
@ -25,6 +34,10 @@ class AccountTest(BaseTestCase):
|
|||||||
|
|
||||||
@patch('seahub.views.file.is_pro_version')
|
@patch('seahub.views.file.is_pro_version')
|
||||||
def test_can_not_get_if_end_time_invalid(self, mock_is_pro_version):
|
def test_can_not_get_if_end_time_invalid(self, mock_is_pro_version):
|
||||||
|
|
||||||
|
if not LOCAL_PRO_DEV_ENV:
|
||||||
|
return
|
||||||
|
|
||||||
mock_is_pro_version.return_value = True
|
mock_is_pro_version.return_value = True
|
||||||
|
|
||||||
self.login_as(self.admin)
|
self.login_as(self.admin)
|
||||||
@ -40,6 +53,10 @@ class AccountTest(BaseTestCase):
|
|||||||
self.assertEqual(400, resp.status_code)
|
self.assertEqual(400, resp.status_code)
|
||||||
|
|
||||||
def test_can_not_get_if_not_admin(self):
|
def test_can_not_get_if_not_admin(self):
|
||||||
|
|
||||||
|
if not LOCAL_PRO_DEV_ENV:
|
||||||
|
return
|
||||||
|
|
||||||
self.login_as(self.user)
|
self.login_as(self.user)
|
||||||
|
|
||||||
start_timestamp = time.time() - 7 * 24 * 60 * 60
|
start_timestamp = time.time() - 7 * 24 * 60 * 60
|
||||||
|
@ -5,8 +5,18 @@ import datetime
|
|||||||
from django.core.urlresolvers import reverse
|
from django.core.urlresolvers import reverse
|
||||||
from seahub.test_utils import BaseTestCase
|
from seahub.test_utils import BaseTestCase
|
||||||
|
|
||||||
class AccountTest(BaseTestCase):
|
try:
|
||||||
|
from seahub.settings import LOCAL_PRO_DEV_ENV
|
||||||
|
except ImportError:
|
||||||
|
LOCAL_PRO_DEV_ENV = False
|
||||||
|
|
||||||
|
class LoginLogTest(BaseTestCase):
|
||||||
|
|
||||||
def test_get_login_log(self):
|
def test_get_login_log(self):
|
||||||
|
|
||||||
|
if not LOCAL_PRO_DEV_ENV:
|
||||||
|
return
|
||||||
|
|
||||||
self.login_as(self.admin)
|
self.login_as(self.admin)
|
||||||
|
|
||||||
end_timestamp = time.time()
|
end_timestamp = time.time()
|
||||||
@ -22,6 +32,10 @@ class AccountTest(BaseTestCase):
|
|||||||
assert json_resp[0]['email'] == self.admin.email
|
assert json_resp[0]['email'] == self.admin.email
|
||||||
|
|
||||||
def test_can_not_get_if_start_time_invalid(self):
|
def test_can_not_get_if_start_time_invalid(self):
|
||||||
|
|
||||||
|
if not LOCAL_PRO_DEV_ENV:
|
||||||
|
return
|
||||||
|
|
||||||
self.login_as(self.admin)
|
self.login_as(self.admin)
|
||||||
|
|
||||||
end_timestamp = time.time()
|
end_timestamp = time.time()
|
||||||
@ -35,6 +49,10 @@ class AccountTest(BaseTestCase):
|
|||||||
self.assertEqual(400, resp.status_code)
|
self.assertEqual(400, resp.status_code)
|
||||||
|
|
||||||
def test_can_not_get_if_end_time_invalid(self):
|
def test_can_not_get_if_end_time_invalid(self):
|
||||||
|
|
||||||
|
if not LOCAL_PRO_DEV_ENV:
|
||||||
|
return
|
||||||
|
|
||||||
self.login_as(self.admin)
|
self.login_as(self.admin)
|
||||||
|
|
||||||
end_timestamp = time.time()
|
end_timestamp = time.time()
|
||||||
@ -48,6 +66,10 @@ class AccountTest(BaseTestCase):
|
|||||||
self.assertEqual(400, resp.status_code)
|
self.assertEqual(400, resp.status_code)
|
||||||
|
|
||||||
def test_can_not_get_if_not_admin(self):
|
def test_can_not_get_if_not_admin(self):
|
||||||
|
|
||||||
|
if not LOCAL_PRO_DEV_ENV:
|
||||||
|
return
|
||||||
|
|
||||||
self.login_as(self.user)
|
self.login_as(self.user)
|
||||||
|
|
||||||
end_timestamp = time.time()
|
end_timestamp = time.time()
|
||||||
|
@ -5,10 +5,19 @@ from mock import patch
|
|||||||
from django.core.urlresolvers import reverse
|
from django.core.urlresolvers import reverse
|
||||||
from seahub.test_utils import BaseTestCase
|
from seahub.test_utils import BaseTestCase
|
||||||
|
|
||||||
|
try:
|
||||||
|
from seahub.settings import LOCAL_PRO_DEV_ENV
|
||||||
|
except ImportError:
|
||||||
|
LOCAL_PRO_DEV_ENV = False
|
||||||
|
|
||||||
class AccountTest(BaseTestCase):
|
class AccountTest(BaseTestCase):
|
||||||
|
|
||||||
@patch('seahub.views.file.is_pro_version')
|
@patch('seahub.views.file.is_pro_version')
|
||||||
def test_can_not_get_if_start_time_invalid(self, mock_is_pro_version):
|
def test_can_not_get_if_start_time_invalid(self, mock_is_pro_version):
|
||||||
|
|
||||||
|
if not LOCAL_PRO_DEV_ENV:
|
||||||
|
return
|
||||||
|
|
||||||
mock_is_pro_version.return_value = True
|
mock_is_pro_version.return_value = True
|
||||||
|
|
||||||
self.login_as(self.admin)
|
self.login_as(self.admin)
|
||||||
@ -25,6 +34,10 @@ class AccountTest(BaseTestCase):
|
|||||||
|
|
||||||
@patch('seahub.views.file.is_pro_version')
|
@patch('seahub.views.file.is_pro_version')
|
||||||
def test_can_not_get_if_end_time_invalid(self, mock_is_pro_version):
|
def test_can_not_get_if_end_time_invalid(self, mock_is_pro_version):
|
||||||
|
|
||||||
|
if not LOCAL_PRO_DEV_ENV:
|
||||||
|
return
|
||||||
|
|
||||||
mock_is_pro_version.return_value = True
|
mock_is_pro_version.return_value = True
|
||||||
|
|
||||||
self.login_as(self.admin)
|
self.login_as(self.admin)
|
||||||
@ -40,6 +53,10 @@ class AccountTest(BaseTestCase):
|
|||||||
self.assertEqual(400, resp.status_code)
|
self.assertEqual(400, resp.status_code)
|
||||||
|
|
||||||
def test_can_not_get_if_not_admin(self):
|
def test_can_not_get_if_not_admin(self):
|
||||||
|
|
||||||
|
if not LOCAL_PRO_DEV_ENV:
|
||||||
|
return
|
||||||
|
|
||||||
self.login_as(self.user)
|
self.login_as(self.user)
|
||||||
|
|
||||||
start_timestamp = time.time() - 7 * 24 * 60 * 60
|
start_timestamp = time.time() - 7 * 24 * 60 * 60
|
||||||
|
Loading…
Reference in New Issue
Block a user