mirror of
https://github.com/ether/etherpad-lite.git
synced 2025-04-23 08:56:17 -04:00
Add listAllGroups API endpoint
Adds a database key that lists all groups
This commit is contained in:
parent
9cfcafb852
commit
f8f002adc0
5 changed files with 107 additions and 2 deletions
|
@ -35,6 +35,7 @@ var cleanText = require("./Pad").cleanText;
|
|||
/**GROUP FUNCTIONS*****/
|
||||
/**********************/
|
||||
|
||||
exports.listAllGroups = groupManager.listAllGroups;
|
||||
exports.createGroup = groupManager.createGroup;
|
||||
exports.createGroupIfNotExistsFor = groupManager.createGroupIfNotExistsFor;
|
||||
exports.deleteGroup = groupManager.deleteGroup;
|
||||
|
|
|
@ -26,6 +26,24 @@ var db = require("./DB").db;
|
|||
var async = require("async");
|
||||
var padManager = require("./PadManager");
|
||||
var sessionManager = require("./SessionManager");
|
||||
|
||||
exports.listAllGroups = function(callback) {
|
||||
db.get("groups", function (err, groups) {
|
||||
if(ERR(err, callback)) return;
|
||||
|
||||
// there are no groups
|
||||
if(groups == null) {
|
||||
callback(null, {groupIDs: []});
|
||||
return;
|
||||
}
|
||||
|
||||
var groupIDs = [];
|
||||
for ( var groupID in groups ) {
|
||||
groupIDs.push(groupID);
|
||||
}
|
||||
callback(null, {groupIDs: groupIDs});
|
||||
});
|
||||
}
|
||||
|
||||
exports.deleteGroup = function(groupID, callback)
|
||||
{
|
||||
|
@ -105,6 +123,39 @@ exports.deleteGroup = function(groupID, callback)
|
|||
db.remove("group2sessions:" + groupID);
|
||||
db.remove("group:" + groupID);
|
||||
callback();
|
||||
},
|
||||
//unlist the group
|
||||
function(callback)
|
||||
{
|
||||
exports.listAllGroups(function(err, groups) {
|
||||
if(ERR(err, callback)) return;
|
||||
groups = groups? groups.groupIDs : [];
|
||||
|
||||
// it's not listed
|
||||
if(groups.indexOf(groupID) == -1) {
|
||||
callback();
|
||||
return;
|
||||
}
|
||||
|
||||
groups.splice(groups.indexOf(groupID), 1);
|
||||
|
||||
// store empty groupe list
|
||||
if(groups.length == 0) {
|
||||
db.set("groups", {});
|
||||
callback();
|
||||
return;
|
||||
}
|
||||
|
||||
// regenerate group list
|
||||
var newGroups = {};
|
||||
async.forEach(groups, function(group, cb) {
|
||||
newGroups[group] = 1;
|
||||
cb();
|
||||
},function() {
|
||||
db.set("groups", newGroups);
|
||||
callback();
|
||||
});
|
||||
});
|
||||
}
|
||||
], function(err)
|
||||
{
|
||||
|
@ -130,7 +181,24 @@ exports.createGroup = function(callback)
|
|||
|
||||
//create the group
|
||||
db.set("group:" + groupID, {pads: {}});
|
||||
callback(null, {groupID: groupID});
|
||||
|
||||
//list the group
|
||||
exports.listAllGroups(function(err, groups) {
|
||||
if(ERR(err, callback)) return;
|
||||
groups = groups? groups.groupIDs : [];
|
||||
|
||||
groups.push(groupID);
|
||||
|
||||
// regenerate group list
|
||||
var newGroups = {};
|
||||
async.forEach(groups, function(group, cb) {
|
||||
newGroups[group] = 1;
|
||||
cb();
|
||||
},function() {
|
||||
db.set("groups", newGroups);
|
||||
callback(null, {groupID: groupID});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
exports.createGroupIfNotExistsFor = function(groupMapper, callback)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue