You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
32 lines
941 B
JavaScript
32 lines
941 B
JavaScript
10 years ago
|
'use strict';
|
||
|
|
||
|
var db = require('./../database');
|
||
|
|
||
|
module.exports = function(Groups) {
|
||
|
|
||
|
Groups.ownership = {};
|
||
|
|
||
|
Groups.ownership.isOwner = function(uid, groupName, callback) {
|
||
|
// Note: All admins automatically become owners upon joining
|
||
|
db.isSetMember('group:' + groupName + ':owners', uid, callback);
|
||
|
};
|
||
|
|
||
|
Groups.ownership.grant = function(toUid, groupName, callback) {
|
||
|
// Note: No ownership checking is done here on purpose!
|
||
|
db.setAdd('group:' + groupName + ':owners', toUid, callback);
|
||
|
};
|
||
|
|
||
|
Groups.ownership.rescind = function(toUid, groupName, callback) {
|
||
|
// Note: No ownership checking is done here on purpose!
|
||
|
|
||
|
// If the owners set only contains one member, error out!
|
||
|
db.setCount('group:' + groupName + ':owners', function(err, numOwners) {
|
||
|
if (numOwners <= 1) {
|
||
|
return callback(new Error('[[error:group-needs-owner]]'));
|
||
|
}
|
||
|
|
||
|
db.setRemove('group:' + groupName + ':owners', toUid, callback);
|
||
|
});
|
||
|
};
|
||
|
};
|