mirror of
https://github.com/ether/etherpad-lite.git
synced 2025-04-21 16:06:16 -04:00
added getMappedGroup4 and createGroup
This commit is contained in:
parent
de0e341b4b
commit
178b4a95ec
4 changed files with 101 additions and 10 deletions
|
@ -21,6 +21,7 @@
|
|||
var padManager = require("./PadManager");
|
||||
var padMessageHandler = require("../handler/PadMessageHandler");
|
||||
var readOnlyManager = require("./ReadOnlyManager");
|
||||
var groupManager = require("./GroupManager");
|
||||
var async = require("async");
|
||||
|
||||
/**********************/
|
||||
|
@ -34,10 +35,7 @@ Example returns:
|
|||
|
||||
{code: 0, message:"ok", data: {groupID: 5}}
|
||||
*/
|
||||
exports.createGroup = function (callback)
|
||||
{
|
||||
|
||||
}
|
||||
exports.createGroup = groupManager.createGroup;
|
||||
|
||||
/**
|
||||
getMappedGroup4(groupMapper) this functions helps you to map your application group ids to etherpad lite group ids
|
||||
|
@ -46,10 +44,7 @@ Example returns:
|
|||
|
||||
{code: 0, message:"ok", data: {groupID: 7}}
|
||||
*/
|
||||
exports.getMappedGroup4 = function (groupMapper, callback)
|
||||
{
|
||||
|
||||
}
|
||||
exports.getMappedGroup4 = groupManager.getMappedGroup4;
|
||||
|
||||
/**
|
||||
deleteGroup(groupID) deletes a group
|
||||
|
|
|
@ -18,4 +18,100 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
var db = require("./DB").db;
|
||||
var async = require("async");
|
||||
|
||||
exports.doesGroupExist = function(groupID, callback)
|
||||
{
|
||||
//try to get the group entry
|
||||
db.get("group:" + groupID, function (err, group)
|
||||
{
|
||||
callback(err, group != null);
|
||||
});
|
||||
}
|
||||
|
||||
exports.createGroup = function(callback)
|
||||
{
|
||||
//search for non existing groupID
|
||||
var groupID;
|
||||
var foundNonExistingGroupID = false;
|
||||
async.whilst(
|
||||
function () { return !foundNonExistingGroupID; },
|
||||
function (callback)
|
||||
{
|
||||
//generate a random 10 digit groupID
|
||||
groupID = "";
|
||||
for(var i=0;i<10;i++)
|
||||
{
|
||||
groupID+=Math.floor(Math.random()*10);
|
||||
}
|
||||
|
||||
//check if this groupID already exisits
|
||||
exports.doesGroupExist(groupID, function(err, exists)
|
||||
{
|
||||
foundNonExistingGroupID = !exists;
|
||||
callback(err);
|
||||
})
|
||||
},
|
||||
//we found a non existing groupID or an error happend
|
||||
function (err)
|
||||
{
|
||||
//check for errors
|
||||
if(err)
|
||||
{
|
||||
callback(err);
|
||||
return;
|
||||
}
|
||||
|
||||
//create the group
|
||||
db.set("group:" + groupID, {pads: {}});
|
||||
callback(null, {groupID: groupID});
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
exports.getMappedGroup4 = function(groupMapper, callback)
|
||||
{
|
||||
//ensure mapper is optional
|
||||
if(typeof groupMapper != "string")
|
||||
{
|
||||
callback({stop: "groupMapper is no string"});
|
||||
return;
|
||||
}
|
||||
|
||||
//try to get a group for this mapper
|
||||
db.get("mapper2group:"+groupMapper, function(err, groupID)
|
||||
{
|
||||
if(err)
|
||||
{
|
||||
callback(err);
|
||||
return;
|
||||
}
|
||||
|
||||
//there is no group for this mapper, let's create a group
|
||||
if(groupID == null)
|
||||
{
|
||||
exports.createGroup(function(err, responseObj)
|
||||
{
|
||||
//check for errors
|
||||
if(err)
|
||||
{
|
||||
callback(err);
|
||||
return;
|
||||
}
|
||||
|
||||
//create the mapper entry for this group
|
||||
db.set("mapper2group:"+groupMapper, responseObj.groupID);
|
||||
callback(null, responseObj);
|
||||
});
|
||||
}
|
||||
//there is a group for this mapper, let's return it
|
||||
else
|
||||
{
|
||||
callback(err, {groupID: groupID});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -35,8 +35,8 @@ catch(e)
|
|||
|
||||
//a list of all functions
|
||||
var functions = {
|
||||
// "createGroup" : [],
|
||||
// "getMappedGroup4" : ["groupMapper"],
|
||||
"createGroup" : [],
|
||||
"getMappedGroup4" : ["groupMapper"],
|
||||
// "deleteGroup" : ["groupID"],
|
||||
// "listPads" : ["groupID"],
|
||||
"createPad" : ["padID", "text"],
|
||||
|
|
BIN
static/favicon.ico
Normal file
BIN
static/favicon.ico
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.1 KiB |
Loading…
Add table
Add a link
Reference in a new issue