mirror of
https://github.com/ether/etherpad-lite.git
synced 2025-04-20 15:36:16 -04:00
added listSessionsOfGroup and listSessionsOfAuthor
This commit is contained in:
parent
4b48380a2f
commit
dbf9dc6dfb
4 changed files with 89 additions and 90 deletions
|
@ -62,8 +62,8 @@ a session between an author and a group
|
||||||
### author2sessions:$AUTHORID
|
### author2sessions:$AUTHORID
|
||||||
saves the sessions of an author
|
saves the sessions of an author
|
||||||
|
|
||||||
* **sessions** - object with sessionIDs in it, values are 1
|
* **sessionsIDs** - object with sessionIDs in it, values are 1
|
||||||
|
|
||||||
### group2sessions:$GROUPID
|
### group2sessions:$GROUPID
|
||||||
|
|
||||||
* **sessions** - object with sessionIDs in it, values are 1
|
* **sessionsIDs** - object with sessionIDs in it, values are 1
|
||||||
|
|
|
@ -152,10 +152,7 @@ Example returns:
|
||||||
{code: 0, message:"ok", data: {32: {authorID: 5, groupID: 7, validUntil: 1312201246}, 53: {authorID: 3, groupID: 2, validUntil: 1312201216}}}
|
{code: 0, message:"ok", data: {32: {authorID: 5, groupID: 7, validUntil: 1312201246}, 53: {authorID: 3, groupID: 2, validUntil: 1312201216}}}
|
||||||
{code: 1, message:"groupID does not exist", data: null}
|
{code: 1, message:"groupID does not exist", data: null}
|
||||||
*/
|
*/
|
||||||
exports.listSessionsOfGroup = function(groupID, callback)
|
exports.listSessionsOfGroup = sessionManager.listSessionsOfGroup;
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
listSessionsOfAuthor(authorID) returns all sessions of an author
|
listSessionsOfAuthor(authorID) returns all sessions of an author
|
||||||
|
@ -165,36 +162,7 @@ Example returns:
|
||||||
{code: 0, message:"ok", data: {32: {authorID: 5, groupID: 7, validUntil: 1312201246}, 53: {authorID: 3, groupID: 2, validUntil: 1312201216}}}
|
{code: 0, message:"ok", data: {32: {authorID: 5, groupID: 7, validUntil: 1312201246}, 53: {authorID: 3, groupID: 2, validUntil: 1312201216}}}
|
||||||
{code: 1, message:"authorID does not exist", data: null}
|
{code: 1, message:"authorID does not exist", data: null}
|
||||||
*/
|
*/
|
||||||
exports.listSessionsOfAuthor = function(authorID, callback)
|
exports.listSessionsOfAuthor = sessionManager.listSessionsOfAuthor;
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
deleteAllSessionsOfGroup(groupID) deletes all sessions of a group
|
|
||||||
|
|
||||||
Example returns:
|
|
||||||
|
|
||||||
{code: 0, message:"ok", data: null}
|
|
||||||
{code: 1, message:"groupID does not exist", data: null}
|
|
||||||
*/
|
|
||||||
exports.deleteAllSessionsOfGroup = function(groupID, callback)
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
deleteAllSessionsOfAuthor(authorID) deletes all sessions of an author
|
|
||||||
|
|
||||||
Example returns:
|
|
||||||
|
|
||||||
{code: 0, message:"ok", data: null}
|
|
||||||
{code: 1, message:"authorID does not exist", data: null}
|
|
||||||
*/
|
|
||||||
exports.deleteAllSessionsOfAuthor = function(authorID, callback)
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/************************/
|
/************************/
|
||||||
/**PAD CONTENT FUNCTIONS*/
|
/**PAD CONTENT FUNCTIONS*/
|
||||||
|
|
|
@ -87,7 +87,7 @@ exports.createSession = function(groupID, authorID, validUntil, callback)
|
||||||
//check validUntil and create the session db entry
|
//check validUntil and create the session db entry
|
||||||
function(callback)
|
function(callback)
|
||||||
{
|
{
|
||||||
//check if validUntil is a number
|
//check if rev is a number
|
||||||
if(typeof validUntil != "number")
|
if(typeof validUntil != "number")
|
||||||
{
|
{
|
||||||
//try to parse the number
|
//try to parse the number
|
||||||
|
@ -117,7 +117,7 @@ exports.createSession = function(groupID, authorID, validUntil, callback)
|
||||||
}
|
}
|
||||||
|
|
||||||
//check if validUntil is in the future
|
//check if validUntil is in the future
|
||||||
if(new Date().getTime()/1000 > validUntil)
|
if(Math.floor(new Date().getTime()/1000) > validUntil)
|
||||||
{
|
{
|
||||||
callback({stop: "validUntil is in the past"});
|
callback({stop: "validUntil is in the past"});
|
||||||
return;
|
return;
|
||||||
|
@ -147,11 +147,14 @@ exports.createSession = function(groupID, authorID, validUntil, callback)
|
||||||
//the entry doesn't exist so far, let's create it
|
//the entry doesn't exist so far, let's create it
|
||||||
if(group2sessions == null)
|
if(group2sessions == null)
|
||||||
{
|
{
|
||||||
group2sessions = {sessions : {}};
|
group2sessions = {sessionIDs : {}};
|
||||||
}
|
}
|
||||||
|
|
||||||
//add the entry for this session
|
//add the entry for this session
|
||||||
group2sessions.sessions[sessionID] = 1;
|
group2sessions.sessionIDs[sessionID] = 1;
|
||||||
|
|
||||||
|
//save the new element back
|
||||||
|
db.set("group2sessions:" + groupID, group2sessions);
|
||||||
|
|
||||||
callback();
|
callback();
|
||||||
});
|
});
|
||||||
|
@ -172,11 +175,14 @@ exports.createSession = function(groupID, authorID, validUntil, callback)
|
||||||
//the entry doesn't exist so far, let's create it
|
//the entry doesn't exist so far, let's create it
|
||||||
if(author2sessions == null)
|
if(author2sessions == null)
|
||||||
{
|
{
|
||||||
author2sessions = {sessions : {}};
|
author2sessions = {sessionIDs : {}};
|
||||||
}
|
}
|
||||||
|
|
||||||
//add the entry for this session
|
//add the entry for this session
|
||||||
author2sessions.sessions[sessionID] = 1;
|
author2sessions.sessionIDs[sessionID] = 1;
|
||||||
|
|
||||||
|
//save the new element back
|
||||||
|
db.set("author2sessions:" + authorID, author2sessions);
|
||||||
|
|
||||||
callback();
|
callback();
|
||||||
});
|
});
|
||||||
|
@ -222,60 +228,87 @@ exports.deleteSession = function(sessionID, callback)
|
||||||
//delete author2sessions
|
//delete author2sessions
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
returns all sessions of a group
|
|
||||||
|
|
||||||
Example returns:
|
|
||||||
|
|
||||||
{code: 0, message:"ok", data: {32: {authorID: 5, groupID: 7, validUntil: 1312201246}, 53: {authorID: 3, groupID: 2, validUntil: 1312201216}}}
|
|
||||||
{code: 1, message:"groupID does not exist", data: null}
|
|
||||||
*/
|
|
||||||
exports.listSessionsOfGroup = function(groupID, callback)
|
exports.listSessionsOfGroup = function(groupID, callback)
|
||||||
{
|
{
|
||||||
//check if group exists
|
groupMangager.doesGroupExist(groupID, function(err, exists)
|
||||||
//get the group2sessions entry
|
{
|
||||||
|
//error
|
||||||
|
if(err)
|
||||||
|
{
|
||||||
|
callback(err);
|
||||||
|
}
|
||||||
|
//group does not exist
|
||||||
|
else if(exists == false)
|
||||||
|
{
|
||||||
|
callback({stop: "groupID does not exist"});
|
||||||
|
}
|
||||||
|
//everything is fine, continue
|
||||||
|
else
|
||||||
|
{
|
||||||
|
listSessionsWithDBKey("group2sessions:" + groupID, callback);
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
listSessionsOfAuthor(authorID) returns all sessions of an author
|
|
||||||
|
|
||||||
Example returns:
|
|
||||||
|
|
||||||
{code: 0, message:"ok", data: {32: {authorID: 5, groupID: 7, validUntil: 1312201246}, 53: {authorID: 3, groupID: 2, validUntil: 1312201216}}}
|
|
||||||
{code: 1, message:"authorID does not exist", data: null}
|
|
||||||
*/
|
|
||||||
exports.listSessionsOfAuthor = function(authorID, callback)
|
exports.listSessionsOfAuthor = function(authorID, callback)
|
||||||
{
|
{
|
||||||
//check if author exists
|
authorMangager.doesAuthorExists(authorID, function(err, exists)
|
||||||
//get the author2sessions entry
|
{
|
||||||
|
//error
|
||||||
|
if(err)
|
||||||
|
{
|
||||||
|
callback(err);
|
||||||
|
}
|
||||||
|
//group does not exist
|
||||||
|
else if(exists == false)
|
||||||
|
{
|
||||||
|
callback({stop: "authorID does not exist"});
|
||||||
|
}
|
||||||
|
//everything is fine, continue
|
||||||
|
else
|
||||||
|
{
|
||||||
|
listSessionsWithDBKey("author2sessions:" + authorID, callback);
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
function listSessionsWithDBKey (dbkey, callback)
|
||||||
deleteAllSessionsOfGroup(groupID) deletes all sessions of a group
|
|
||||||
|
|
||||||
Example returns:
|
|
||||||
|
|
||||||
{code: 0, message:"ok", data: null}
|
|
||||||
{code: 1, message:"groupID does not exist", data: null}
|
|
||||||
*/
|
|
||||||
exports.deleteAllSessionsOfGroup = function(groupID, callback)
|
|
||||||
{
|
{
|
||||||
//call listsessionsofgroup
|
var sessions;
|
||||||
//foreach the group and delete the sessions
|
|
||||||
|
async.series([
|
||||||
|
function(callback)
|
||||||
|
{
|
||||||
|
//get the group2sessions entry
|
||||||
|
db.get(dbkey, function(err, sessionObject)
|
||||||
|
{
|
||||||
|
sessions = sessionObject ? sessionObject.sessionIDs : null;
|
||||||
|
callback(err);
|
||||||
|
});
|
||||||
|
},
|
||||||
|
function(callback)
|
||||||
|
{
|
||||||
|
//collect all sessionIDs in an arrary
|
||||||
|
var sessionIDs = [];
|
||||||
|
for (var i in sessions)
|
||||||
|
{
|
||||||
|
sessionIDs.push(i);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
//foreach trough the sessions and get the sessioninfos
|
||||||
deleteAllSessionsOfAuthor(authorID) deletes all sessions of an author
|
async.forEach(sessionIDs, function(sessionID, callback)
|
||||||
|
|
||||||
Example returns:
|
|
||||||
|
|
||||||
{code: 0, message:"ok", data: null}
|
|
||||||
{code: 1, message:"authorID does not exist", data: null}
|
|
||||||
*/
|
|
||||||
exports.deleteAllSessionsOfAuthor = function(authorID, callback)
|
|
||||||
{
|
{
|
||||||
//call listsessionsofauthor
|
exports.getSessionInfo(sessionID, function(err, sessionInfo)
|
||||||
//foreach the group and delete the sessions
|
{
|
||||||
|
sessions[sessionID] = sessionInfo;
|
||||||
|
callback(err);
|
||||||
|
});
|
||||||
|
}, callback);
|
||||||
|
}
|
||||||
|
], function(err)
|
||||||
|
{
|
||||||
|
callback(err, sessions);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -46,10 +46,8 @@ var functions = {
|
||||||
"createSession" : ["groupID", "authorID", "validUntil"],
|
"createSession" : ["groupID", "authorID", "validUntil"],
|
||||||
// "deleteSession" : ["sessionID"],
|
// "deleteSession" : ["sessionID"],
|
||||||
"getSessionInfo" : ["sessionID"],
|
"getSessionInfo" : ["sessionID"],
|
||||||
// "listSessionsOfGroup" : ["groupID"],
|
"listSessionsOfGroup" : ["groupID"],
|
||||||
// "listSessionsOfAuthor" : ["authorID"],
|
"listSessionsOfAuthor" : ["authorID"],
|
||||||
// "deleteAllSessionsOfGroup" : ["groupID"],
|
|
||||||
// "deleteAllSessionsOfAuthor" : ["authorID"],
|
|
||||||
"getText" : ["padID", "rev"],
|
"getText" : ["padID", "rev"],
|
||||||
"setText" : ["padID", "text"],
|
"setText" : ["padID", "text"],
|
||||||
"getRevisionsCount" : ["padID"],
|
"getRevisionsCount" : ["padID"],
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue