v1.18.x
barisusakli 10 years ago
parent 240a619a72
commit 915a992448

@ -1,6 +1,8 @@
'use strict'; 'use strict';
var db = require('../database'); var async = require('async'),
db = require('../database'),
plugins = require('../plugins');
module.exports = function(Groups) { module.exports = function(Groups) {
@ -23,22 +25,35 @@ module.exports = function(Groups) {
Groups.ownership.grant = function(toUid, groupName, callback) { Groups.ownership.grant = function(toUid, groupName, callback) {
// Note: No ownership checking is done here on purpose! // Note: No ownership checking is done here on purpose!
db.setAdd('group:' + groupName + ':owners', toUid, callback); async.waterfall([
function(next) {
db.setAdd('group:' + groupName + ':owners', toUid, next);
},
function(next) {
plugins.fireHook('action:group.grantOwnership', {uid: toUid, groupName: groupName});
next();
}
], callback);
}; };
Groups.ownership.rescind = function(toUid, groupName, callback) { Groups.ownership.rescind = function(toUid, groupName, callback) {
// Note: No ownership checking is done here on purpose! // Note: No ownership checking is done here on purpose!
// If the owners set only contains one member, error out! // If the owners set only contains one member, error out!
db.setCount('group:' + groupName + ':owners', function(err, numOwners) { async.waterfall([
if (err) { function (next) {
return callback(err); db.setCount('group:' + groupName + ':owners', next);
} },
if (numOwners <= 1) { function (numOwners, next) {
return callback(new Error('[[error:group-needs-owner]]')); if (numOwners <= 1) {
return next(new Error('[[error:group-needs-owner]]'));
}
db.setRemove('group:' + groupName + ':owners', toUid, next);
},
function (next) {
plugins.fireHook('action:group.rescindOwnership', {uid: toUid, groupName: groupName});
next();
} }
], callback);
db.setRemove('group:' + groupName + ':owners', toUid, callback);
});
}; };
}; };

Loading…
Cancel
Save