make renameGroup public for #5706

v1.18.x
Barış Soner Uşaklı 8 years ago
parent f6ac92111b
commit 466e6d7c53

@ -70,7 +70,7 @@ module.exports = function (Groups) {
} }
}, },
async.apply(db.setObject, 'group:' + groupName, payload), async.apply(db.setObject, 'group:' + groupName, payload),
async.apply(renameGroup, groupName, values.name), async.apply(Groups.renameGroup, groupName, values.name),
], next); ], next);
}, },
function (result, next) { function (result, next) {
@ -166,15 +166,30 @@ module.exports = function (Groups) {
} }
async.waterfall([ async.waterfall([
function (next) { function (next) {
async.parallel({
group: function (next) {
db.getObject('group:' + currentName, next);
},
exists: function (next) {
Groups.existsBySlug(newSlug, next); Groups.existsBySlug(newSlug, next);
}, },
function (exists, next) { }, next);
next(exists ? new Error('[[error:group-already-exists]]') : null); },
function (results, next) {
if (results.exists) {
return next(new Error('[[error:group-already-exists]]'));
}
if (parseInt(results.group.system, 10) === 1) {
return next(new Error('[[error:not-allowed-to-rename-system-group]]'));
}
next();
}, },
], callback); ], callback);
} }
function renameGroup(oldName, newName, callback) { Groups.renameGroup = function (oldName, newName, callback) {
if (oldName === newName || !newName || newName.length === 0) { if (oldName === newName || !newName || newName.length === 0) {
return setImmediate(callback); return setImmediate(callback);
} }
@ -189,10 +204,6 @@ module.exports = function (Groups) {
return callback(); return callback();
} }
if (parseInt(group.system, 10) === 1) {
return callback(new Error('[[error:not-allowed-to-rename-system-group]]'));
}
Groups.exists(newName, next); Groups.exists(newName, next);
}, },
function (exists, next) { function (exists, next) {
@ -237,7 +248,7 @@ module.exports = function (Groups) {
], function (err) { ], function (err) {
callback(err); callback(err);
}); });
} };
function renameGroupMember(group, oldName, newName, callback) { function renameGroupMember(group, oldName, newName, callback) {
var score; var score;

@ -348,6 +348,22 @@ describe('Groups', function () {
done(); done();
}); });
}); });
it('should fail to rename group to an existing group', function (done) {
Groups.create({
name: 'group2',
system: 0,
hidden: 0,
}, function (err) {
assert.ifError(err);
Groups.update('group2', {
name: 'updateTestGroup?',
}, function (err) {
assert.equal(err.message, '[[error:group-already-exists]]');
done();
});
});
});
}); });
describe('.destroy()', function () { describe('.destroy()', function () {

Loading…
Cancel
Save