|
|
|
@ -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) {
|
|
|
|
|