1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-09-02 23:48:47 +00:00

add remote wipe option when admin unlink device

This commit is contained in:
lian
2017-01-17 11:05:48 +08:00
parent b4599bf6b0
commit f13b61e497
4 changed files with 64 additions and 18 deletions

View File

@@ -16,7 +16,7 @@ from seahub.views import is_registered_user
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
from seahub.api2.models import TokenV2 from seahub.api2.models import TokenV2, DESKTOP_PLATFORMS
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
@@ -56,6 +56,11 @@ class AdminDevices(APIView):
result['last_login_ip'] = device.last_login_ip result['last_login_ip'] = device.last_login_ip
result['user'] = device.user result['user'] = device.user
result['platform'] = device.platform result['platform'] = device.platform
result['is_desktop_client'] = False
if result['platform'] in DESKTOP_PLATFORMS:
result['is_desktop_client'] = True
return_results.append(result) return_results.append(result)
page_info = { page_info = {
@@ -68,6 +73,7 @@ class AdminDevices(APIView):
platform = request.data.get('platform', '') platform = request.data.get('platform', '')
device_id = request.data.get('device_id', '') device_id = request.data.get('device_id', '')
remote_wipe = request.data.get('wipe_device', '')
user = request.data.get('user', '') user = request.data.get('user', '')
if not platform: if not platform:
@@ -82,8 +88,10 @@ class AdminDevices(APIView):
error_msg = 'user invalid.' error_msg = 'user invalid.'
return api_error(status.HTTP_400_BAD_REQUEST, error_msg) return api_error(status.HTTP_400_BAD_REQUEST, error_msg)
remote_wipe = True if remote_wipe == 'true' else False
try: try:
do_unlink_device(user, platform, device_id) do_unlink_device(user, platform, device_id, remote_wipe=remote_wipe)
except SearpcError as e: except SearpcError as e:
logger.error(e) logger.error(e)
error_msg = 'Internal Server Error' error_msg = 'Internal Server Error'

View File

@@ -1900,6 +1900,8 @@ class DevicesView(APIView):
error_msg = 'device_id invalid.' error_msg = 'device_id invalid.'
return api_error(status.HTTP_400_BAD_REQUEST, error_msg) return api_error(status.HTTP_400_BAD_REQUEST, error_msg)
remote_wipe = True if remote_wipe == 'true' else False
try: try:
do_unlink_device(request.user.username, do_unlink_device(request.user.username,
platform, platform,

View File

@@ -12,6 +12,9 @@ define([
'device_id': this.get('device_id'), 'device_id': this.get('device_id'),
'user': this.get('user') 'user': this.get('user')
}; };
if (options.wipe_device) {
data['wipe_device'] = 'true';
}
$.ajax({ $.ajax({
url: Common.getUrl({name: 'admin-devices'}), url: Common.getUrl({name: 'admin-devices'}),
@@ -28,6 +31,11 @@ define([
if (options.error) { if (options.error) {
options.error(xhr); options.error(xhr);
} }
},
complete: function(xhr) {
if (options.complete) {
options.complete(xhr);
}
} }
}); });
}, },

View File

@@ -14,7 +14,7 @@ define([
template: _.template($('#device-item-tmpl').html()), template: _.template($('#device-item-tmpl').html()),
events: { events: {
'click .unlink-device': 'unlinkDevice' 'click .unlink-device': 'unlinkDeviceWithConfirm'
}, },
initialize: function() { initialize: function() {
@@ -33,26 +33,54 @@ define([
return this; return this;
}, },
unlinkDevice: function() { unlinkDeviceWithConfirm: function() {
var _this = this, var _this = this,
is_desktop_client = this.model.get('is_desktop_client'),
device_name = this.model.get('device_name'); device_name = this.model.get('device_name');
this.model.unlink({ if (is_desktop_client) {
success: function() { var title = gettext('Unlink device');
_this.remove(); 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.") var yesCallback = function (wipe_device) {
.replace('%(name)s', device_name); _this.model.unlink({
Common.feedback(msg, 'success'); wipe_device: wipe_device,
},
error: function(xhr) { success: function() {
Common.ajaxErrorHandler(xhr); _this.remove();
}
}); var msg = gettext("Successfully unlink %(name)s.")
return false; .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; return DeviceView;
}); });