v1.18.x
Barış Soner Uşaklı 6 years ago
parent 96e986a865
commit afa84023a2

@ -12,7 +12,6 @@ module.exports = function (Groups) {
groupNames = [groupNames];
}
var groupObj;
var groupsData;
async.waterfall([
function (next) {
@ -23,8 +22,6 @@ module.exports = function (Groups) {
if (!groupsData.length) {
return callback();
}
// backwards compatibility
groupObj = groupsData[0];
async.parallel([
function (next) {
@ -49,19 +46,15 @@ module.exports = function (Groups) {
], groupNames, next);
},
function (next) {
var keys = groupNames.map(function (groupName) {
return groupName.toLowerCase() + ':' + groupName;
});
const keys = groupNames.map(groupName => groupName.toLowerCase() + ':' + groupName);
db.sortedSetRemove('groups:visible:name', keys, next);
},
function (next) {
var fields = groupNames.map(function (groupName) {
return utils.slugify(groupName);
});
const fields = groupNames.map(groupName => utils.slugify(groupName));
db.deleteObjectFields('groupslug:groupname', fields, next);
},
function (next) {
removeGroupsFromOtherGroups(groupNames, next);
removeGroupsFromPrivilegeGroups(groupNames, next);
},
], function (err) {
next(err);
@ -69,18 +62,16 @@ module.exports = function (Groups) {
},
function (next) {
Groups.resetCache();
plugins.fireHook('action:group.destroy', { group: groupObj });
plugins.fireHook('action:groups.destroy', { groups: groupsData });
next();
},
], callback);
};
function removeGroupsFromOtherGroups(groupNames, callback) {
function removeGroupsFromPrivilegeGroups(groupNames, callback) {
batch.processSortedSet('groups:createtime', function (otherGroups, next) {
var keys = otherGroups.map(function (group) {
return 'group:' + group + ':members';
});
const privilegeGroups = otherGroups.filter(group => Groups.isPrivilegeGroup(group));
const keys = privilegeGroups.map(group => 'group:' + group + ':members');
db.sortedSetRemove(keys, groupNames, next);
}, {
batch: 500,

@ -456,7 +456,6 @@ describe('Groups', function () {
Groups.get('foobar?', {}, function (err, groupObj) {
assert.ifError(err);
assert.strictEqual(groupObj, null);
done();
});
});
@ -465,12 +464,43 @@ describe('Groups', function () {
it('should also remove the members set', function (done) {
db.exists('group:foo:members', function (err, exists) {
assert.ifError(err);
assert.strictEqual(false, exists);
done();
});
});
it('should remove group from privilege groups', function (done) {
const privileges = require('../src/privileges');
const cid = 1;
const groupName = '1';
const uid = 1;
async.waterfall([
function (next) {
Groups.create({ name: groupName }, next);
},
function (groupData, next) {
privileges.categories.give(['topics:create'], cid, groupName, next);
},
function (next) {
Groups.isMember(groupName, 'cid:1:privileges:groups:topics:create', next);
},
function (isMember, next) {
assert(isMember);
Groups.destroy(groupName, next);
},
function (next) {
Groups.isMember(groupName, 'cid:1:privileges:groups:topics:create', next);
},
function (isMember, next) {
assert(!isMember);
Groups.isMember(uid, 'registered-users', next);
},
function (isMember, next) {
assert(isMember);
next();
},
], done);
});
});
describe('.join()', function () {

Loading…
Cancel
Save