Merge pull request #19124 from nextcloud/bug/13647/ignore-delete-groups

Exclude groups from sharing: Skip delete groups
This commit is contained in:
Morris Jobke 2020-05-04 10:02:32 +02:00 committed by GitHub
commit 6aceb39714
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 77 additions and 73 deletions

View File

@ -6,9 +6,9 @@
OC.Settings = OC.Settings || {}; OC.Settings = OC.Settings || {};
OC.Settings = _.extend(OC.Settings, { OC.Settings = _.extend(OC.Settings, {
_cachedGroups: null, _cachedGroups: null,
/** /**
* Setup selection box for group selection. * Setup selection box for group selection.
* *
* Values need to be separated by a pipe "|" character. * Values need to be separated by a pipe "|" character.
@ -20,77 +20,81 @@ OC.Settings = _.extend(OC.Settings, {
* @param {Array} [options] extra options * @param {Array} [options] extra options
* @param {Array} [options.excludeAdmins=false] flag whether to exclude admin groups * @param {Array} [options.excludeAdmins=false] flag whether to exclude admin groups
*/ */
setupGroupsSelect: function($elements, extraOptions, options) { setupGroupsSelect: function($elements, extraOptions, options) {
var self = this; var self = this;
options = options || {}; options = options || {};
if ($elements.length > 0) { if ($elements.length > 0) {
// Let's load the data and THEN init our select // Let's load the data and THEN init our select
$.ajax({ $.ajax({
url: OC.linkToOCS('cloud/groups', 2) + 'details', url: OC.linkToOCS('cloud/groups', 2) + 'details',
dataType: 'json', dataType: 'json',
success: function(data) { success: function(data) {
var results = []; var results = [];
if (data.ocs.data.groups && data.ocs.data.groups.length > 0) { if (data.ocs.data.groups && data.ocs.data.groups.length > 0) {
data.ocs.data.groups.forEach(function(group) { data.ocs.data.groups.forEach(function(group) {
if (!options.excludeAdmins || group.id !== 'admin') { if (!options.excludeAdmins || group.id !== 'admin') {
results.push({ id: group.id, displayname: group.displayname }); results.push({ id: group.id, displayname: group.displayname });
} }
}) })
// note: settings are saved through a "change" event registered // note: settings are saved through a "change" event registered
// on all input fields // on all input fields
$elements.select2(_.extend({ $elements.select2(_.extend({
placeholder: t('core', 'Groups'), placeholder: t('core', 'Groups'),
allowClear: true, allowClear: true,
multiple: true, multiple: true,
toggleSelect: true, toggleSelect: true,
separator: '|', separator: '|',
data: { results: results, text: 'displayname' }, data: { results: results, text: 'displayname' },
initSelection: function(element, callback) { initSelection: function(element, callback) {
var groups = $(element).val(); var groups = $(element).val();
var selection; var selection;
if (groups && results.length > 0) { if (groups && results.length > 0) {
selection = _.map((groups || []).split('|').sort(), function(groupId) { selection = _.map(_.filter((groups || []).split('|').sort(), function(groupId) {
return { return results.find(function(group) {
id: groupId, return group.id === groupId
displayname: results.find(function (group) { }) !== undefined
return group.id === groupId; }), function(groupId) {
}).displayname return {
}; id: groupId,
}); displayname: results.find(function(group) {
} else if (groups) { return group.id === groupId
selection = _.map((groups || []).split('|').sort(), function(groupId) { }).displayname
return { }
id: groupId, })
displayname: groupId } else if (groups) {
}; selection = _.map((groups || []).split('|').sort(), function(groupId) {
}); return {
} id: groupId,
callback(selection); displayname: groupId
}, };
formatResult: function(element) { });
return escapeHTML(element.displayname); }
}, callback(selection);
formatSelection: function(element) { },
return escapeHTML(element.displayname); formatResult: function(element) {
}, return escapeHTML(element.displayname);
escapeMarkup: function(m) { },
// prevent double markup escape formatSelection: function(element) {
return m; return escapeHTML(element.displayname);
} },
}, extraOptions || {})); escapeMarkup: function(m) {
} else { // prevent double markup escape
OC.Notification.show(t('settings', 'Group list is empty'), { type: 'error' }); return m;
console.log(data); }
} }, extraOptions || {}));
}, } else {
error: function(data) { OC.Notification.show(t('settings', 'Group list is empty'), { type: 'error' });
OC.Notification.show(t('settings', 'Unable to retrieve the group list'), { type: 'error' }); console.log(data);
console.log(data); }
} },
}); error: function(data) {
} OC.Notification.show(t('settings', 'Unable to retrieve the group list'), { type: 'error' });
} console.log(data);
}); }
});
}
}
});