Skip to content

Node.js based forum software built for the modern web

closes #1883, no upgrade script #successkid

barisusakli8113ed6a4d88
diff --git a/public/src/forum/admin/groups.js b/public/src/forum/admin/groups.js
index ea270fa1a6..5e4f0c34d1 100644
--- a/public/src/forum/admin/groups.js
+++ b/public/src/forum/admin/groups.js
@@ -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);
diff --git a/src/groups.js b/src/groups.js
index e881926c92..23c8fd2d01 100644
--- a/src/groups.js
+++ b/src/groups.js
@@ -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) {