mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-12 17:05:51 +01:00
updating groups so that members leave a group when it is deleted
This commit is contained in:
@@ -178,6 +178,9 @@
|
||||
},
|
||||
function(next) {
|
||||
db.setRemove('groups', groupName, next);
|
||||
},
|
||||
function(next) {
|
||||
db.delete('group:' + groupName + ':members', next);
|
||||
}
|
||||
], callback);
|
||||
};
|
||||
|
||||
@@ -433,10 +433,11 @@ Upgrade.upgrade = function(callback) {
|
||||
function(next) {
|
||||
Groups.list({ showAllGroups: true }, function(err, groups) {
|
||||
async.each(groups, function(group, next) {
|
||||
// If empty, delete group
|
||||
if (group.memberCount === 0) {
|
||||
// If empty, delete group
|
||||
Groups.destroy(group.name, next);
|
||||
} else if (group.hidden && !isValidHiddenGroup.test(group.name)) {
|
||||
// If invalidly named hidden group, delete
|
||||
Groups.destroy(group.name, next);
|
||||
} else {
|
||||
next();
|
||||
|
||||
@@ -184,6 +184,10 @@ describe('Groups', function() {
|
||||
});
|
||||
|
||||
describe('.destroy()', function() {
|
||||
before(function(done) {
|
||||
Groups.join('foo', 1, done);
|
||||
});
|
||||
|
||||
it('should destroy a group', function(done) {
|
||||
Groups.destroy('foo', function(err) {
|
||||
if (err) return done(err);
|
||||
@@ -196,6 +200,16 @@ describe('Groups', function() {
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it('should also remove the members set', function(done) {
|
||||
db.exists('group:foo:members', function(err, exists) {
|
||||
if (err) return done(err);
|
||||
|
||||
assert.strictEqual(false, exists);
|
||||
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('.join()', function() {
|
||||
@@ -235,7 +249,7 @@ describe('Groups', function() {
|
||||
Groups.leaveAllGroups(1, function(err) {
|
||||
if (err) return done(err);
|
||||
|
||||
var groups = ['Test', 'Hidden', 'foo'];
|
||||
var groups = ['Test', 'Hidden'];
|
||||
async.every(groups, function(group, next) {
|
||||
Groups.isMember(1, group, function(err, isMember) {
|
||||
if (err) done(err);
|
||||
|
||||
Reference in New Issue
Block a user