mirror of
https://github.com/haiwen/seahub.git
synced 2025-09-02 15:38:15 +00:00
add remote wipe option when admin unlink device
This commit is contained in:
@@ -16,7 +16,7 @@ from seahub.views import is_registered_user
|
||||
from seahub.api2.authentication import TokenAuthentication
|
||||
from seahub.api2.throttling import UserRateThrottle
|
||||
from seahub.api2.utils import api_error
|
||||
from seahub.api2.models import TokenV2
|
||||
from seahub.api2.models import TokenV2, DESKTOP_PLATFORMS
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
@@ -56,6 +56,11 @@ class AdminDevices(APIView):
|
||||
result['last_login_ip'] = device.last_login_ip
|
||||
result['user'] = device.user
|
||||
result['platform'] = device.platform
|
||||
|
||||
result['is_desktop_client'] = False
|
||||
if result['platform'] in DESKTOP_PLATFORMS:
|
||||
result['is_desktop_client'] = True
|
||||
|
||||
return_results.append(result)
|
||||
|
||||
page_info = {
|
||||
@@ -68,6 +73,7 @@ class AdminDevices(APIView):
|
||||
|
||||
platform = request.data.get('platform', '')
|
||||
device_id = request.data.get('device_id', '')
|
||||
remote_wipe = request.data.get('wipe_device', '')
|
||||
user = request.data.get('user', '')
|
||||
|
||||
if not platform:
|
||||
@@ -82,8 +88,10 @@ class AdminDevices(APIView):
|
||||
error_msg = 'user invalid.'
|
||||
return api_error(status.HTTP_400_BAD_REQUEST, error_msg)
|
||||
|
||||
remote_wipe = True if remote_wipe == 'true' else False
|
||||
|
||||
try:
|
||||
do_unlink_device(user, platform, device_id)
|
||||
do_unlink_device(user, platform, device_id, remote_wipe=remote_wipe)
|
||||
except SearpcError as e:
|
||||
logger.error(e)
|
||||
error_msg = 'Internal Server Error'
|
||||
|
@@ -1900,6 +1900,8 @@ class DevicesView(APIView):
|
||||
error_msg = 'device_id invalid.'
|
||||
return api_error(status.HTTP_400_BAD_REQUEST, error_msg)
|
||||
|
||||
remote_wipe = True if remote_wipe == 'true' else False
|
||||
|
||||
try:
|
||||
do_unlink_device(request.user.username,
|
||||
platform,
|
||||
|
@@ -12,6 +12,9 @@ define([
|
||||
'device_id': this.get('device_id'),
|
||||
'user': this.get('user')
|
||||
};
|
||||
if (options.wipe_device) {
|
||||
data['wipe_device'] = 'true';
|
||||
}
|
||||
|
||||
$.ajax({
|
||||
url: Common.getUrl({name: 'admin-devices'}),
|
||||
@@ -28,6 +31,11 @@ define([
|
||||
if (options.error) {
|
||||
options.error(xhr);
|
||||
}
|
||||
},
|
||||
complete: function(xhr) {
|
||||
if (options.complete) {
|
||||
options.complete(xhr);
|
||||
}
|
||||
}
|
||||
});
|
||||
},
|
||||
|
@@ -14,7 +14,7 @@ define([
|
||||
template: _.template($('#device-item-tmpl').html()),
|
||||
|
||||
events: {
|
||||
'click .unlink-device': 'unlinkDevice'
|
||||
'click .unlink-device': 'unlinkDeviceWithConfirm'
|
||||
},
|
||||
|
||||
initialize: function() {
|
||||
@@ -33,26 +33,54 @@ define([
|
||||
return this;
|
||||
},
|
||||
|
||||
unlinkDevice: function() {
|
||||
unlinkDeviceWithConfirm: function() {
|
||||
var _this = this,
|
||||
is_desktop_client = this.model.get('is_desktop_client'),
|
||||
device_name = this.model.get('device_name');
|
||||
|
||||
this.model.unlink({
|
||||
success: function() {
|
||||
_this.remove();
|
||||
if (is_desktop_client) {
|
||||
var title = gettext('Unlink device');
|
||||
var content = gettext('Are you sure you want to unlink this device?');
|
||||
var extraOption = gettext('Delete files from this device the next time it comes online.');
|
||||
|
||||
var msg = gettext("Successfully unlink %(name)s.")
|
||||
.replace('%(name)s', device_name);
|
||||
Common.feedback(msg, 'success');
|
||||
},
|
||||
error: function(xhr) {
|
||||
Common.ajaxErrorHandler(xhr);
|
||||
}
|
||||
});
|
||||
return false;
|
||||
var yesCallback = function (wipe_device) {
|
||||
_this.model.unlink({
|
||||
wipe_device: wipe_device,
|
||||
|
||||
success: function() {
|
||||
_this.remove();
|
||||
|
||||
var msg = gettext("Successfully unlink %(name)s.")
|
||||
.replace('%(name)s', device_name);
|
||||
Common.feedback(msg, 'success');
|
||||
},
|
||||
error: function(xhr) {
|
||||
Common.ajaxErrorHandler(xhr);
|
||||
},
|
||||
complete: function() {
|
||||
$.modal.close();
|
||||
}
|
||||
});
|
||||
return false;
|
||||
};
|
||||
Common.showConfirmWithExtraOption(title, content, extraOption, yesCallback);
|
||||
} else {
|
||||
_this.model.unlink({
|
||||
wipe_device: true,
|
||||
success: function() {
|
||||
_this.remove();
|
||||
|
||||
var msg = gettext("Successfully unlink %(name)s.")
|
||||
.replace('%(name)s', device_name);
|
||||
Common.feedback(msg, 'success');
|
||||
},
|
||||
error: function(xhr) {
|
||||
Common.ajaxErrorHandler(xhr);
|
||||
}
|
||||
});
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
return DeviceView;
|
||||
});
|
||||
|
Reference in New Issue
Block a user