mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-12 17:05:51 +01:00
closes #1883, no upgrade script #successkid
This commit is contained in:
@@ -80,7 +80,7 @@ define('forum/admin/groups', ['forum/admin/iconSelect'], function(iconSelect) {
|
||||
socket.emit('admin.groups.get', groupName, function(err, groupObj) {
|
||||
var formEl = detailsModal.find('form');
|
||||
|
||||
formEl.find('#change-group-name').val(groupObj.name);
|
||||
formEl.find('#change-group-name').val(groupObj.name).prop('readonly', groupObj.system);
|
||||
formEl.find('#change-group-desc').val(groupObj.description);
|
||||
formEl.find('#change-group-user-title').val(groupObj.userTitle);
|
||||
formEl.find('#group-icon').attr('class', 'fa fa-2x ' + groupObj.icon).attr('value', groupObj.icon);
|
||||
|
||||
@@ -244,10 +244,79 @@
|
||||
icon: values.icon || '',
|
||||
labelColor: values.labelColor || '#000000',
|
||||
hidden: values.hidden || '0'
|
||||
}, callback);
|
||||
}, function(err) {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
}
|
||||
|
||||
renameGroup(groupName, values.name, callback);
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
function renameGroup(oldName, newName, callback) {
|
||||
if (oldName === newName || newName.length === 0) {
|
||||
return callback();
|
||||
}
|
||||
|
||||
db.getObject('group:' + oldName, function(err, group) {
|
||||
if (err || !group) {
|
||||
return callback(err);
|
||||
}
|
||||
|
||||
if (parseInt(group.system, 10) === 1 || parseInt(group.hidden, 10) === 1) {
|
||||
return callback();
|
||||
}
|
||||
|
||||
Groups.exists(newName, function(err, exists) {
|
||||
if (err || exists) {
|
||||
return callback(err || new Error('[[error:group-already-exists]]'));
|
||||
}
|
||||
|
||||
async.series([
|
||||
function(next) {
|
||||
db.setObjectField('group:' + oldName, 'name', newName, next);
|
||||
},
|
||||
function(next) {
|
||||
db.getSetMembers('groups', function(err, groups) {
|
||||
if (err) {
|
||||
return next(err);
|
||||
}
|
||||
async.each(groups, function(group, next) {
|
||||
renameGroupMember('group:' + group + ':members', oldName, newName, next);
|
||||
}, next);
|
||||
});
|
||||
},
|
||||
function(next) {
|
||||
db.rename('group:' + oldName, 'group:' + newName, next);
|
||||
},
|
||||
function(next) {
|
||||
db.rename('group:' + oldName + ':members', 'group:' + newName + ':members', next);
|
||||
},
|
||||
function(next) {
|
||||
renameGroupMember('groups', oldName, newName, next);
|
||||
}
|
||||
], callback);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function renameGroupMember(group, oldName, newName, callback) {
|
||||
db.isSetMember(group, oldName, function(err, isMember) {
|
||||
if (err || !isMember) {
|
||||
return callback(err);
|
||||
}
|
||||
async.series([
|
||||
function (next) {
|
||||
db.setRemove(group, oldName, next);
|
||||
},
|
||||
function (next) {
|
||||
db.setAdd(group, newName, next);
|
||||
}
|
||||
], callback);
|
||||
});
|
||||
}
|
||||
|
||||
Groups.destroy = function(groupName, callback) {
|
||||
async.parallel([
|
||||
function(next) {
|
||||
|
||||
Reference in New Issue
Block a user