diff --git a/seahub/api2/endpoints/admin/devices.py b/seahub/api2/endpoints/admin/devices.py index c77bd7f12b..c081054fe5 100644 --- a/seahub/api2/endpoints/admin/devices.py +++ b/seahub/api2/endpoints/admin/devices.py @@ -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' diff --git a/seahub/api2/views.py b/seahub/api2/views.py index 4e8e846edd..070c08ce6c 100644 --- a/seahub/api2/views.py +++ b/seahub/api2/views.py @@ -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, diff --git a/static/scripts/sysadmin-app/models/device.js b/static/scripts/sysadmin-app/models/device.js index bc1049ded2..9129586446 100644 --- a/static/scripts/sysadmin-app/models/device.js +++ b/static/scripts/sysadmin-app/models/device.js @@ -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); + } } }); }, diff --git a/static/scripts/sysadmin-app/views/device.js b/static/scripts/sysadmin-app/views/device.js index 99cb2073a8..10be0ac384 100644 --- a/static/scripts/sysadmin-app/views/device.js +++ b/static/scripts/sysadmin-app/views/device.js @@ -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; });