mirror of
https://github.com/ether/etherpad-lite.git
synced 2025-05-05 06:37:10 -04:00
Merge f7d8f68c13
into a8469dcdaa
This commit is contained in:
commit
2fb1f7a3fd
5 changed files with 137 additions and 4 deletions
|
@ -35,6 +35,7 @@ var cleanText = require("./Pad").cleanText;
|
|||
/**GROUP FUNCTIONS*****/
|
||||
/**********************/
|
||||
|
||||
exports.listGroups = groupManager.listGroups;
|
||||
exports.createGroup = groupManager.createGroup;
|
||||
exports.createGroupIfNotExistsFor = groupManager.createGroupIfNotExistsFor;
|
||||
exports.deleteGroup = groupManager.deleteGroup;
|
||||
|
@ -463,6 +464,47 @@ exports.isPasswordProtected = function(padID, callback)
|
|||
});
|
||||
}
|
||||
|
||||
/**
|
||||
listAllPads() returns a array with all pads
|
||||
|
||||
Example returns:
|
||||
|
||||
{code: 0, message:"ok", data: {padIDs: []}}
|
||||
*/
|
||||
exports.listAllPads = function(callback)
|
||||
{
|
||||
allPads = [];
|
||||
|
||||
var defaultGroup = "g.defaultGroupName";
|
||||
|
||||
//get all groups
|
||||
groupManager.listGroups(function (err, groups)
|
||||
{
|
||||
groups=groups["groupIDs"];
|
||||
// if defaultGroup exists add this too, becaus ists not listed in groupManager.listGroups
|
||||
groupManager.doesGroupExist(defaultGroup, function(err, exists)
|
||||
{
|
||||
if(exists)
|
||||
{
|
||||
groups.push(defaultGroup);
|
||||
}
|
||||
});
|
||||
|
||||
for(var group in groups)
|
||||
{
|
||||
groupManager.listPads(groups[group], function(err, pads)
|
||||
{
|
||||
for(var pad in pads["padIDs"])
|
||||
{
|
||||
allPads.push(pads["padIDs"][pad]);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
callback(null, {padIDs: allPads});
|
||||
}
|
||||
|
||||
/******************************/
|
||||
/** INTERNAL HELPER FUNCTIONS */
|
||||
/******************************/
|
||||
|
|
|
@ -102,6 +102,27 @@ exports.deleteGroup = function(groupID, callback)
|
|||
//remove group and group2sessions entry
|
||||
function(callback)
|
||||
{
|
||||
// remove group from groups entry
|
||||
db.get("groups", function (err, groups)
|
||||
{
|
||||
if(ERR(err, callback)) return;
|
||||
|
||||
existingGroups = [];
|
||||
|
||||
if(groups != undefined)
|
||||
{
|
||||
for(var key in groups['groups'])
|
||||
{
|
||||
if(groupID != groups['groups'][key])
|
||||
{
|
||||
existingGroups.push(groups['groups'][key]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
db.set("groups", {groups: existingGroups});
|
||||
});
|
||||
|
||||
db.remove("group2sessions:" + groupID);
|
||||
db.remove("group:" + groupID);
|
||||
callback();
|
||||
|
@ -112,6 +133,17 @@ exports.deleteGroup = function(groupID, callback)
|
|||
callback();
|
||||
});
|
||||
}
|
||||
|
||||
exports.listGroups = function(callback)
|
||||
{
|
||||
//try to get the groups entry
|
||||
db.get("groups", function (err, groups)
|
||||
{
|
||||
if(groups == null) groups["groups"] = [];
|
||||
if(ERR(err, callback)) return;
|
||||
callback(null, {groupIDs: groups["groups"]});
|
||||
});
|
||||
}
|
||||
|
||||
exports.doesGroupExist = function(groupID, callback)
|
||||
{
|
||||
|
@ -125,9 +157,36 @@ exports.doesGroupExist = function(groupID, callback)
|
|||
|
||||
exports.createGroup = function(callback)
|
||||
{
|
||||
// load all existing groups from db
|
||||
existingGroups = [];
|
||||
|
||||
exports.listGroups(function(err, responseGroups)
|
||||
{
|
||||
if(ERR(err, callback)) return;
|
||||
if(responseGroups != undefined)
|
||||
{
|
||||
for(var key in responseGroups['groups'])
|
||||
{
|
||||
existingGroups.push(responseGroups['groups'][key]);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
//search for non existing groupID
|
||||
var groupID = "g." + randomString(16);
|
||||
|
||||
// check if group already exisits
|
||||
exports.doesGroupExist(groupID, function(err, groupExist)
|
||||
{
|
||||
if(groupExist) return;
|
||||
});
|
||||
|
||||
// add the new group to the array
|
||||
existingGroups.push(groupID);
|
||||
|
||||
// update the entry to the db, which hold all groups
|
||||
db.set("groups", {groups: existingGroups});
|
||||
|
||||
//create the group
|
||||
db.set("group:" + groupID, {pads: {}});
|
||||
callback(null, {groupID: groupID});
|
||||
|
|
|
@ -12,6 +12,7 @@ var async = require("async");
|
|||
var settings = require('../utils/Settings');
|
||||
var authorManager = require("./AuthorManager");
|
||||
var padManager = require("./PadManager");
|
||||
var groupManager = require("./GroupManager");
|
||||
var padMessageHandler = require("../handler/PadMessageHandler");
|
||||
var readOnlyManager = require("./ReadOnlyManager");
|
||||
var crypto = require("crypto");
|
||||
|
@ -351,6 +352,20 @@ Pad.prototype.init = function init(text, callback) {
|
|||
{
|
||||
var firstChangeset = Changeset.makeSplice("\n", 0, 0, exports.cleanText(text));
|
||||
|
||||
// if this is a non group pad, add this to the defaultGroup
|
||||
if(_this.id.indexOf("$")==-1)
|
||||
{
|
||||
groupID = "g.defaultGroupName";
|
||||
groupManager.doesGroupExist(groupID, function(err, exists)
|
||||
{
|
||||
if(!exists)
|
||||
{
|
||||
db.set("group:" + groupID, {pads: {}});
|
||||
}
|
||||
});
|
||||
db.setSub("group:"+groupID, ["pads", _this.id], 1);
|
||||
}
|
||||
|
||||
_this.appendRevision(firstChangeset, '');
|
||||
}
|
||||
|
||||
|
@ -391,10 +406,23 @@ Pad.prototype.remove = function remove(callback) {
|
|||
callback();
|
||||
});
|
||||
}
|
||||
//its no group pad, nothing to do here
|
||||
//its no group pad, so remove this pad from the defaultGroup
|
||||
else
|
||||
{
|
||||
callback();
|
||||
var groupID = "g.defaultGroupName";
|
||||
|
||||
db.get("group:" + groupID, function (err, group)
|
||||
{
|
||||
if(ERR(err, callback)) return;
|
||||
|
||||
//remove the pad entry
|
||||
delete group.pads[padID];
|
||||
|
||||
//set the new value
|
||||
db.set("group:" + groupID, group);
|
||||
|
||||
callback();
|
||||
});
|
||||
}
|
||||
},
|
||||
//remove the readonly entries
|
||||
|
|
|
@ -39,10 +39,12 @@ catch(e)
|
|||
|
||||
//a list of all functions
|
||||
var functions = {
|
||||
"listGroups" : [],
|
||||
"createGroup" : [],
|
||||
"createGroupIfNotExistsFor" : ["groupMapper"],
|
||||
"deleteGroup" : ["groupID"],
|
||||
"listPads" : ["groupID"],
|
||||
"listPads" : ["groupID"],
|
||||
"listAllPads" : [],
|
||||
"createPad" : ["padID", "text"],
|
||||
"createGroupPad" : ["groupID", "padName", "text"],
|
||||
"createAuthor" : ["name"],
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>API Test and Examples Page</title>
|
||||
<script type="text/javascript" src="js/jquery.min.js"></script>
|
||||
<script type="text/javascript" src="js/jquery.js"></script>
|
||||
<style type="text/css">
|
||||
body {
|
||||
font-size:9pt;
|
||||
|
@ -139,10 +139,12 @@
|
|||
</table>
|
||||
<div class="results"/>
|
||||
</div>
|
||||
<div class="define">listGroups()</div>
|
||||
<div class="define">createGroup()</div>
|
||||
<div class="define">deleteGroup(groupID)</div>
|
||||
<div class="define">createGroupIfNotExistsFor(groupMapper)</div>
|
||||
<div class="define">listPads(groupID)</div>
|
||||
<div class="define">listAllPads()</div>
|
||||
<div class="define">createPad(padID,text)</div>
|
||||
<div class="define">createGroupPad(groupID,padName,text)</div>
|
||||
<div class="define">createAuthor(name)</div>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue