X Tutup
Skip to content

Commit ba2d7ba

Browse files
fix: proper error handling when deleting users/groups is failing (#41077)
1 parent dddaec5 commit ba2d7ba

File tree

5 files changed

+17
-89
lines changed

5 files changed

+17
-89
lines changed

changelog/unreleased/41077

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Bugfix: Proper error handling when deleting users or groups
2+
3+
https://github.com/owncloud/core/pull/41077
4+
https://github.com/owncloud/core/pull/41075

settings/js/users/deleteHandler.js

Lines changed: 9 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,9 @@
1616
* marking the object for deletion.
1717
* @param {removeCallback} removeCallback the function to be called after
1818
* successful delete.
19+
* @param {undoCallback} undoCallback called after "undo" was clicked
1920
*/
20-
function DeleteHandler(endpoint, paramID, markCallback, removeCallback) {
21+
function DeleteHandler(endpoint, paramID, markCallback, removeCallback, undoCallback) {
2122
this.oidToDelete = false;
2223
this.canceled = false;
2324

@@ -26,69 +27,8 @@ function DeleteHandler(endpoint, paramID, markCallback, removeCallback) {
2627

2728
this.markCallback = markCallback;
2829
this.removeCallback = removeCallback;
29-
this.undoCallback = false;
30-
31-
this.notifier = false;
32-
this.notificationDataID = false;
33-
this.notificationMessage = false;
34-
this.notificationPlaceholder = '%oid';
35-
}
36-
37-
/**
38-
* Number of milliseconds after which the operation is performed.
39-
*/
40-
DeleteHandler.TIMEOUT_MS = 7000;
41-
42-
/**
43-
* Timer after which the action will be performed anyway.
44-
*/
45-
DeleteHandler.prototype._timeout = null;
46-
47-
/**
48-
* enabled the notification system. Required for undo UI.
49-
*
50-
* @param {object} notifier Usually OC.Notification
51-
* @param {string} dataID an identifier for the notifier, e.g. 'deleteuser'
52-
* @param {string} message the message that should be shown upon delete. %oid
53-
* will be replaced with the affected id of the item to be deleted
54-
* @param {undoCallback} undoCallback called after "undo" was clicked
55-
*/
56-
DeleteHandler.prototype.setNotification = function(notifier, dataID, message, undoCallback) {
57-
this.notifier = notifier;
58-
this.notificationDataID = dataID;
59-
this.notificationMessage = message;
6030
this.undoCallback = undoCallback;
61-
62-
var dh = this;
63-
64-
$('#notification')
65-
.off('click.deleteHandler_' + dataID)
66-
.on('click.deleteHandler_' + dataID, '.undo', function () {
67-
if ($('#notification').data(dh.notificationDataID)) {
68-
var oid = dh.oidToDelete;
69-
dh.cancel();
70-
if(typeof dh.undoCallback !== 'undefined') {
71-
dh.undoCallback(oid);
72-
}
73-
}
74-
dh.notifier.hide();
75-
});
76-
};
77-
78-
/**
79-
* shows the Undo Notification (if configured)
80-
*/
81-
DeleteHandler.prototype.showNotification = function() {
82-
if(this.notifier !== false) {
83-
if(!this.notifier.isHidden()) {
84-
this.hideNotification();
85-
}
86-
$('#notification').data(this.notificationDataID, true);
87-
var msg = this.notificationMessage.replace(
88-
this.notificationPlaceholder, escapeHTML(decodeURIComponent(this.oidToDelete)));
89-
this.notifier.showHtml(msg);
90-
}
91-
};
31+
}
9232

9333
/**
9434
* initializes the delete operation for a given object id
@@ -105,20 +45,14 @@ DeleteHandler.prototype.mark = function(oid) {
10545
* initialized by mark(). On error, it will show a message via
10646
* OC.dialogs.alert. On success, a callback is fired so that the client can
10747
* update the web interface accordingly.
108-
*
109-
* @param {boolean} [keepNotification] true to keep the notification, false to hide
110-
* it, defaults to false
11148
*/
112-
DeleteHandler.prototype.deleteEntry = function(keepNotification) {
49+
DeleteHandler.prototype.deleteEntry = function() {
11350
var deferred = $.Deferred();
11451
if(this.oidToDelete === false) {
11552
return deferred.resolve().promise();
11653
}
11754

11855
var dh = this;
119-
if(!keepNotification && $('#notification').data(this.notificationDataID) === true) {
120-
dh.hideNotification();
121-
}
12256

12357
var payload = {};
12458
payload[dh.ajaxParamID] = dh.oidToDelete;
@@ -134,9 +68,12 @@ DeleteHandler.prototype.deleteEntry = function(keepNotification) {
13468
dh.removeCallback(dh.oidToDelete);
13569
},
13670
error: function (jqXHR) {
137-
OC.dialogs.alert(jqXHR.responseJSON.data.message, t('settings', 'Unable to delete {objName}', {objName: decodeURIComponent(dh.oidToDelete)}));
71+
var msg = 'Unknown error';
72+
if (jqXHR.responseJSON && jqXHR.responseJSON.data && jqXHR.responseJSON.data.message) {
73+
msg = jqXHR.responseJSON.data.message;
74+
}
75+
OC.dialogs.alert(msg, t('settings', 'Unable to delete {objName}', {objName: decodeURIComponent(dh.oidToDelete)}));
13876
dh.undoCallback(dh.oidToDelete);
139-
14077
}
14178
});
14279
};

settings/js/users/groups.js

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
*/
77

88
var GroupList;
9+
var GroupDeleteHandler;
910

1011
(function () {
1112
GroupList = {
@@ -287,12 +288,7 @@ var GroupList;
287288
initDeleteHandling: function () {
288289
//set up handler
289290
GroupDeleteHandler = new DeleteHandler('/settings/users/groups', 'groupname',
290-
GroupList.hide, GroupList.remove);
291-
292-
var msg = escapeHTML(t('settings', 'deleted {groupName}', {groupName: '%oid'})) + '<span class="undo">' +
293-
escapeHTML(t('settings', 'undo')) + '</span>';
294-
GroupDeleteHandler.setNotification(OC.Notification, 'deletegroup', msg,
295-
GroupList.remove);
291+
GroupList.hide, GroupList.remove, GroupList.show);
296292

297293
//when to mark user for delete
298294
this.$userGroupList.on('click', '.delete', function () {

settings/js/users/users.js

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -349,14 +349,7 @@ var UserList = {
349349
initDeleteHandling: function() {
350350
//set up handler
351351
UserDeleteHandler = new DeleteHandler('/settings/users/users', 'username',
352-
UserList.markRemove, UserList.remove);
353-
354-
//configure undo
355-
OC.Notification.hide();
356-
var msg = escapeHTML(t('settings', 'deleted {userName}', {userName: '%oid'})) + '<span class="undo">' +
357-
escapeHTML(t('settings', 'undo')) + '</span>';
358-
UserDeleteHandler.setNotification(OC.Notification, 'deleteuser', msg,
359-
UserList.undoRemove);
352+
UserList.markRemove, UserList.remove, UserList.undoRemove);
360353

361354
//when to mark user for delete
362355
$userListBody.on('click', '.delete', function () {

settings/tests/js/users/deleteHandlerSpec.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,7 @@ describe('DeleteHandler tests', function() {
2828
var undoCallback;
2929

3030
function init(markCallback, removeCallback, undoCallback) {
31-
var handler = new DeleteHandler('dummyendpoint.php', 'paramid', markCallback, removeCallback);
32-
handler.setNotification(OC.Notification, 'dataid', 'removed %oid entry', undoCallback);
33-
return handler;
31+
return new DeleteHandler('dummyendpoint.php', 'paramid', markCallback, removeCallback, undoCallback);
3432
}
3533

3634
beforeEach(function() {

0 commit comments

Comments
 (0)
X Tutup