1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-09-16 07:08:55 +00:00

add admin clean device errors api

This commit is contained in:
lian
2016-04-29 15:32:57 +08:00
parent d649038a29
commit 65dc2ff54b
4 changed files with 68 additions and 3 deletions

View File

@@ -26,7 +26,7 @@ class AdminDeviceErrors(APIView):
def get(self, request, format=None):
if not is_pro_version():
error_msg = 'Permission denied.'
error_msg = 'Feature disabled.'
return api_error(status.HTTP_403_FORBIDDEN, error_msg)
return_results = []
@@ -61,3 +61,17 @@ class AdminDeviceErrors(APIView):
return_results.append(result)
return Response(return_results)
def delete(self, request, format=None):
if not is_pro_version():
error_msg = 'Feature disabled.'
return api_error(status.HTTP_403_FORBIDDEN, error_msg)
try:
seafile_api.clear_repo_sync_errors()
except SearpcError as e:
logger.error(e)
error_msg = 'Internal Server Error'
return api_error(status.HTTP_500_INTERNAL_SERVER_ERROR, error_msg)
return Response({'success': True})

View File

@@ -180,6 +180,7 @@
<a href="#device-errors/" class="a">{% trans "Errors" %}</a>
</li>
</ul>
<button id="clean-device-errors" class="fright hide"><span class="vam">{% trans "Clean" %}</span></button>
</div>
<table class="hide">
<thead>

View File

@@ -21,12 +21,38 @@ define([
this.render();
},
events: {
'click #clean-device-errors': 'cleanDeviceErrors'
},
cleanDeviceErrors: function() {
var _this = this;
$.ajax({
url: Common.getUrl({name: 'admin-device-errors'}),
type: 'DELETE',
beforeSend: Common.prepareCSRFToken,
success: function() {
_this.$table.hide();
_this.$cleanBtn.hide();
_this.$emptyTip.show();
_this.deviceErrorsCollection.reset();
var msg = gettext("Successfully clean all errors.");
Common.feedback(msg, 'success');
},
error: function(xhr) {
Common.ajaxErrorHandler(xhr);
}
});
return false;
},
render: function() {
this.$el.html(this.template({'cur_tab': 'errors'}));
this.$table = this.$('table');
this.$tableBody = $('tbody', this.$table);
this.$loadingTip = this.$('.loading-tip');
this.$emptyTip = this.$('.empty-tips');
this.$cleanBtn = this.$('#clean-device-errors');
},
hide: function() {
@@ -75,6 +101,7 @@ define([
if (this.deviceErrorsCollection.length) {
this.deviceErrorsCollection.each(this.addOne, this);
this.$table.show();
this.$cleanBtn.show();
} else {
this.$emptyTip.show();
}

View File

@@ -7,7 +7,7 @@ try:
except ImportError:
LOCAL_PRO_DEV_ENV = False
class DevicesTest(BaseTestCase):
class DeviceErrorsTest(BaseTestCase):
@patch('seahub.views.file.is_pro_version')
def test_can_get(self, mock_is_pro_version):
@@ -18,7 +18,7 @@ class DevicesTest(BaseTestCase):
mock_is_pro_version.return_value = True
self.login_as(self.admin)
url = reverse('api-v2.1-admin-devices')
url = reverse('api-v2.1-admin-device-errors')
resp = self.client.get(url)
self.assertEqual(200, resp.status_code)
@@ -31,3 +31,26 @@ class DevicesTest(BaseTestCase):
url = reverse('api-v2.1-admin-device-errors')
resp = self.client.get(url)
self.assertEqual(403, resp.status_code)
@patch('seahub.views.file.is_pro_version')
def test_can_clean(self, mock_is_pro_version):
if not LOCAL_PRO_DEV_ENV:
return
mock_is_pro_version.return_value = True
self.login_as(self.admin)
url = reverse('api-v2.1-admin-device-errors')
resp = self.client.delete(url)
self.assertEqual(200, resp.status_code)
def test_can_not_clean_if_not_admin(self):
if not LOCAL_PRO_DEV_ENV:
return
self.login_as(self.user)
url = reverse('api-v2.1-admin-device-errors')
resp = self.client.delete(url)
self.assertEqual(403, resp.status_code)