mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-12 17:05:51 +01:00
ephemeral groups - guests
This commit is contained in:
@@ -7,7 +7,10 @@
|
|||||||
db = require('./database'),
|
db = require('./database'),
|
||||||
utils = require('../public/src/utils'),
|
utils = require('../public/src/utils'),
|
||||||
|
|
||||||
filterGroups = function(groups, options) {
|
ephemeralGroups = ['guests'],
|
||||||
|
|
||||||
|
internals = {
|
||||||
|
filterGroups: function(groups, options) {
|
||||||
// Remove system, hidden, or deleted groups from this list
|
// Remove system, hidden, or deleted groups from this list
|
||||||
if (groups && !options.showAllGroups) {
|
if (groups && !options.showAllGroups) {
|
||||||
return groups.filter(function (group) {
|
return groups.filter(function (group) {
|
||||||
@@ -20,19 +23,33 @@
|
|||||||
} else {
|
} else {
|
||||||
return groups;
|
return groups;
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
getEphemeralGroup: function(groupName, options, callback) {
|
||||||
|
Groups.exists(groupName, function(err, exists) {
|
||||||
|
if (!err && exists) {
|
||||||
|
Groups.get.apply(null, arguments);
|
||||||
|
} else {
|
||||||
|
callback(null, {
|
||||||
|
name: groupName,
|
||||||
|
description: '',
|
||||||
|
deleted: '0',
|
||||||
|
hidden: '0',
|
||||||
|
system: '1'
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
Groups.list = function(options, callback) {
|
Groups.list = function(options, callback) {
|
||||||
db.getSetMembers('groups', function (err, groupNames) {
|
db.getSetMembers('groups', function (err, groupNames) {
|
||||||
if (groupNames.length > 0) {
|
groupNames = groupNames.concat(ephemeralGroups);
|
||||||
|
|
||||||
async.map(groupNames, function (groupName, next) {
|
async.map(groupNames, function (groupName, next) {
|
||||||
Groups.get(groupName, options, next);
|
Groups.get(groupName, options, next);
|
||||||
}, function (err, groups) {
|
}, function (err, groups) {
|
||||||
callback(err, filterGroups(groups, options));
|
callback(err, internals.filterGroups(groups, options));
|
||||||
});
|
});
|
||||||
} else {
|
|
||||||
callback(null, []);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -42,6 +59,7 @@
|
|||||||
|
|
||||||
async.parallel({
|
async.parallel({
|
||||||
base: function (next) {
|
base: function (next) {
|
||||||
|
if (ephemeralGroups.indexOf(groupName) === -1) {
|
||||||
db.getObject('group:' + groupName, function(err, groupObj) {
|
db.getObject('group:' + groupName, function(err, groupObj) {
|
||||||
if (err) {
|
if (err) {
|
||||||
next(err);
|
next(err);
|
||||||
@@ -51,6 +69,9 @@
|
|||||||
next(err, groupObj);
|
next(err, groupObj);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
} else {
|
||||||
|
internals.getEphemeralGroup(groupName, options, next);
|
||||||
|
}
|
||||||
},
|
},
|
||||||
users: function (next) {
|
users: function (next) {
|
||||||
db.getSetMembers('group:' + groupName + ':members', function (err, uids) {
|
db.getSetMembers('group:' + groupName + ':members', function (err, uids) {
|
||||||
@@ -103,7 +124,7 @@
|
|||||||
async.map(groups, function(groupName, next) {
|
async.map(groups, function(groupName, next) {
|
||||||
Groups.get(groupName, options, next);
|
Groups.get(groupName, options, next);
|
||||||
}, function(err, groups) {
|
}, function(err, groups) {
|
||||||
callback(err, filterGroups(groups, options));
|
callback(err, internals.filterGroups(groups, options));
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
Reference in New Issue
Block a user