mirror of
https://github.com/haiwen/seahub.git
synced 2025-09-15 23:00:57 +00:00
add admin clean device errors api
This commit is contained in:
@@ -26,7 +26,7 @@ class AdminDeviceErrors(APIView):
|
|||||||
|
|
||||||
def get(self, request, format=None):
|
def get(self, request, format=None):
|
||||||
if not is_pro_version():
|
if not is_pro_version():
|
||||||
error_msg = 'Permission denied.'
|
error_msg = 'Feature disabled.'
|
||||||
return api_error(status.HTTP_403_FORBIDDEN, error_msg)
|
return api_error(status.HTTP_403_FORBIDDEN, error_msg)
|
||||||
|
|
||||||
return_results = []
|
return_results = []
|
||||||
@@ -61,3 +61,17 @@ class AdminDeviceErrors(APIView):
|
|||||||
return_results.append(result)
|
return_results.append(result)
|
||||||
|
|
||||||
return Response(return_results)
|
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})
|
||||||
|
@@ -180,6 +180,7 @@
|
|||||||
<a href="#device-errors/" class="a">{% trans "Errors" %}</a>
|
<a href="#device-errors/" class="a">{% trans "Errors" %}</a>
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
|
<button id="clean-device-errors" class="fright hide"><span class="vam">{% trans "Clean" %}</span></button>
|
||||||
</div>
|
</div>
|
||||||
<table class="hide">
|
<table class="hide">
|
||||||
<thead>
|
<thead>
|
||||||
|
@@ -21,12 +21,38 @@ define([
|
|||||||
this.render();
|
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() {
|
render: function() {
|
||||||
this.$el.html(this.template({'cur_tab': 'errors'}));
|
this.$el.html(this.template({'cur_tab': 'errors'}));
|
||||||
this.$table = this.$('table');
|
this.$table = this.$('table');
|
||||||
this.$tableBody = $('tbody', this.$table);
|
this.$tableBody = $('tbody', this.$table);
|
||||||
this.$loadingTip = this.$('.loading-tip');
|
this.$loadingTip = this.$('.loading-tip');
|
||||||
this.$emptyTip = this.$('.empty-tips');
|
this.$emptyTip = this.$('.empty-tips');
|
||||||
|
this.$cleanBtn = this.$('#clean-device-errors');
|
||||||
},
|
},
|
||||||
|
|
||||||
hide: function() {
|
hide: function() {
|
||||||
@@ -75,6 +101,7 @@ define([
|
|||||||
if (this.deviceErrorsCollection.length) {
|
if (this.deviceErrorsCollection.length) {
|
||||||
this.deviceErrorsCollection.each(this.addOne, this);
|
this.deviceErrorsCollection.each(this.addOne, this);
|
||||||
this.$table.show();
|
this.$table.show();
|
||||||
|
this.$cleanBtn.show();
|
||||||
} else {
|
} else {
|
||||||
this.$emptyTip.show();
|
this.$emptyTip.show();
|
||||||
}
|
}
|
||||||
|
@@ -7,7 +7,7 @@ try:
|
|||||||
except ImportError:
|
except ImportError:
|
||||||
LOCAL_PRO_DEV_ENV = False
|
LOCAL_PRO_DEV_ENV = False
|
||||||
|
|
||||||
class DevicesTest(BaseTestCase):
|
class DeviceErrorsTest(BaseTestCase):
|
||||||
|
|
||||||
@patch('seahub.views.file.is_pro_version')
|
@patch('seahub.views.file.is_pro_version')
|
||||||
def test_can_get(self, mock_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
|
mock_is_pro_version.return_value = True
|
||||||
self.login_as(self.admin)
|
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)
|
resp = self.client.get(url)
|
||||||
self.assertEqual(200, resp.status_code)
|
self.assertEqual(200, resp.status_code)
|
||||||
|
|
||||||
@@ -31,3 +31,26 @@ class DevicesTest(BaseTestCase):
|
|||||||
url = reverse('api-v2.1-admin-device-errors')
|
url = reverse('api-v2.1-admin-device-errors')
|
||||||
resp = self.client.get(url)
|
resp = self.client.get(url)
|
||||||
self.assertEqual(403, resp.status_code)
|
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)
|
||||||
|
Reference in New Issue
Block a user