mirror of
https://github.com/ether/etherpad-lite.git
synced 2025-04-23 00:46:16 -04:00
Merge branch 'develop' of git://github.com/Pita/etherpad-lite into restartserver
This commit is contained in:
commit
a0548af021
14 changed files with 320 additions and 41 deletions
|
@ -47,6 +47,8 @@ exports.createGroupPad = groupManager.createGroupPad;
|
|||
|
||||
exports.createAuthor = authorManager.createAuthor;
|
||||
exports.createAuthorIfNotExistsFor = authorManager.createAuthorIfNotExistsFor;
|
||||
exports.listPadsOfAuthor = authorManager.listPadsOfAuthor;
|
||||
exports.padUsersCount = padMessageHandler.padUsersCount;
|
||||
|
||||
/**********************/
|
||||
/**SESSION FUNCTIONS***/
|
||||
|
@ -282,6 +284,24 @@ exports.getRevisionsCount = function(padID, callback)
|
|||
});
|
||||
}
|
||||
|
||||
/**
|
||||
getLastEdited(padID) returns the timestamp of the last revision of the pad
|
||||
|
||||
Example returns:
|
||||
|
||||
{code: 0, message:"ok", data: {lastEdited: 1340815946602}}
|
||||
{code: 1, message:"padID does not exist", data: null}
|
||||
*/
|
||||
exports.getLastEdited = function(padID, callback)
|
||||
{
|
||||
//get the pad
|
||||
getPadSafe(padID, true, function(err, pad)
|
||||
{
|
||||
if(ERR(err, callback)) return;
|
||||
callback(null, {lastEdited: pad.getLastEdited()});
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
createPad(padName [, text]) creates a new pad in this group
|
||||
|
||||
|
@ -463,6 +483,26 @@ exports.isPasswordProtected = function(padID, callback)
|
|||
});
|
||||
}
|
||||
|
||||
/**
|
||||
listAuthorsOfPad(padID) returns an array of authors who contributed to this pad
|
||||
|
||||
Example returns:
|
||||
|
||||
{code: 0, message:"ok", data: {authorIDs : ["a.s8oes9dhwrvt0zif", "a.akf8finncvomlqva"]}
|
||||
{code: 1, message:"padID does not exist", data: null}
|
||||
*/
|
||||
exports.listAuthorsOfPad = function(padID, callback)
|
||||
{
|
||||
//get the pad
|
||||
getPadSafe(padID, true, function(err, pad)
|
||||
{
|
||||
if(ERR(err, callback)) return;
|
||||
|
||||
callback(null, {authorIDs: pad.getAllAuthors()});
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
/******************************/
|
||||
/** INTERNAL HELPER FUNCTIONS */
|
||||
/******************************/
|
||||
|
|
|
@ -55,6 +55,7 @@ exports.getAuthor4Token = function (token, callback)
|
|||
/**
|
||||
* Returns the AuthorID for a mapper.
|
||||
* @param {String} token The mapper
|
||||
* @param {String} name The name of the author (optional)
|
||||
* @param {Function} callback callback (err, author)
|
||||
*/
|
||||
exports.createAuthorIfNotExistsFor = function (authorMapper, name, callback)
|
||||
|
@ -153,6 +154,7 @@ exports.getAuthorColorId = function (author, callback)
|
|||
/**
|
||||
* Sets the color Id of the author
|
||||
* @param {String} author The id of the author
|
||||
* @param {String} colorId The color id of the author
|
||||
* @param {Function} callback (optional)
|
||||
*/
|
||||
exports.setAuthorColorId = function (author, colorId, callback)
|
||||
|
@ -173,9 +175,95 @@ exports.getAuthorName = function (author, callback)
|
|||
/**
|
||||
* Sets the name of the author
|
||||
* @param {String} author The id of the author
|
||||
* @param {String} name The name of the author
|
||||
* @param {Function} callback (optional)
|
||||
*/
|
||||
exports.setAuthorName = function (author, name, callback)
|
||||
{
|
||||
db.setSub("globalAuthor:" + author, ["name"], name, callback);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an array of all pads this author contributed to
|
||||
* @param {String} author The id of the author
|
||||
* @param {Function} callback (optional)
|
||||
*/
|
||||
exports.listPadsOfAuthor = function (authorID, callback)
|
||||
{
|
||||
/* There are two other places where this array is manipulated:
|
||||
* (1) When the author is added to a pad, the author object is also updated
|
||||
* (2) When a pad is deleted, each author of that pad is also updated
|
||||
*/
|
||||
//get the globalAuthor
|
||||
db.get("globalAuthor:" + authorID, function(err, author)
|
||||
{
|
||||
if(ERR(err, callback)) return;
|
||||
|
||||
//author does not exists
|
||||
if(author == null)
|
||||
{
|
||||
callback(new customError("authorID does not exist","apierror"))
|
||||
}
|
||||
//everything is fine, return the pad IDs
|
||||
else
|
||||
{
|
||||
var pads = [];
|
||||
if(author.padIDs != null)
|
||||
{
|
||||
for (var padId in author.padIDs)
|
||||
{
|
||||
pads.push(padId);
|
||||
}
|
||||
}
|
||||
callback(null, {padIDs: pads});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a new pad to the list of contributions
|
||||
* @param {String} author The id of the author
|
||||
* @param {String} padID The id of the pad the author contributes to
|
||||
*/
|
||||
exports.addPad = function (authorID, padID)
|
||||
{
|
||||
//get the entry
|
||||
db.get("globalAuthor:" + authorID, function(err, author)
|
||||
{
|
||||
if(ERR(err)) return;
|
||||
if(author == null) return;
|
||||
|
||||
//the entry doesn't exist so far, let's create it
|
||||
if(author.padIDs == null)
|
||||
{
|
||||
author.padIDs = {};
|
||||
}
|
||||
|
||||
//add the entry for this pad
|
||||
author.padIDs[padID] = 1;// anything, because value is not used
|
||||
|
||||
//save the new element back
|
||||
db.set("globalAuthor:" + authorID, author);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes a pad from the list of contributions
|
||||
* @param {String} author The id of the author
|
||||
* @param {String} padID The id of the pad the author contributes to
|
||||
*/
|
||||
exports.removePad = function (authorID, padID)
|
||||
{
|
||||
db.get("globalAuthor:" + authorID, function (err, author)
|
||||
{
|
||||
if(ERR(err)) return;
|
||||
if(author == null) return;
|
||||
|
||||
if(author.padIDs != null)
|
||||
{
|
||||
//remove pad from author
|
||||
delete author.padIDs[padID];
|
||||
db.set("globalAuthor:" + authorID, author);
|
||||
}
|
||||
});
|
||||
}
|
|
@ -80,8 +80,12 @@ Pad.prototype.appendRevision = function appendRevision(aChangeset, author) {
|
|||
newRevData.meta.atext = this.atext;
|
||||
}
|
||||
|
||||
db.set("pad:"+this.id+":revs:"+newRev, newRevData);
|
||||
db.set("pad:"+this.id+":revs:"+newRev, newRevData);
|
||||
this.saveToDatabase();
|
||||
|
||||
// set the author to pad
|
||||
if(author)
|
||||
authorManager.addPad(author, this.id);
|
||||
};
|
||||
|
||||
//save all attributes to the database
|
||||
|
@ -102,6 +106,12 @@ Pad.prototype.saveToDatabase = function saveToDatabase(){
|
|||
db.set("pad:"+this.id, dbObject);
|
||||
}
|
||||
|
||||
// get time of last edit (changeset application)
|
||||
Pad.prototype.getLastEdit = function getLastEdit(callback){
|
||||
var revNum = this.getHeadRevisionNumber();
|
||||
db.getSub("pad:"+this.id+":revs:"+revNum, ["meta", "timestamp"], callback);
|
||||
}
|
||||
|
||||
Pad.prototype.getRevisionChangeset = function getRevisionChangeset(revNum, callback) {
|
||||
db.getSub("pad:"+this.id+":revs:"+revNum, ["changeset"], callback);
|
||||
};
|
||||
|
@ -436,6 +446,18 @@ Pad.prototype.remove = function remove(callback) {
|
|||
db.remove("pad:"+padID+":revs:"+i);
|
||||
}
|
||||
|
||||
callback();
|
||||
},
|
||||
//remove pad from all authors who contributed
|
||||
function(callback)
|
||||
{
|
||||
var authorIDs = _this.getAllAuthors();
|
||||
|
||||
authorIDs.forEach(function (authorID)
|
||||
{
|
||||
authorManager.removePad(authorID, padID);
|
||||
});
|
||||
|
||||
callback();
|
||||
}
|
||||
], callback);
|
||||
|
|
|
@ -40,13 +40,14 @@ catch(e)
|
|||
//a list of all functions
|
||||
var functions = {
|
||||
"createGroup" : [],
|
||||
"createGroupIfNotExistsFor" : ["groupMapper"],
|
||||
"createGroupIfNotExistsFor" : ["groupMapper"],
|
||||
"deleteGroup" : ["groupID"],
|
||||
"listPads" : ["groupID"],
|
||||
"createPad" : ["padID", "text"],
|
||||
"createGroupPad" : ["groupID", "padName", "text"],
|
||||
"createAuthor" : ["name"],
|
||||
"createAuthorIfNotExistsFor": ["authorMapper" , "name"],
|
||||
"listPadsOfAuthor" : ["authorID"],
|
||||
"createSession" : ["groupID", "authorID", "validUntil"],
|
||||
"deleteSession" : ["sessionID"],
|
||||
"getSessionInfo" : ["sessionID"],
|
||||
|
@ -57,12 +58,15 @@ var functions = {
|
|||
"getHTML" : ["padID", "rev"],
|
||||
"setHTML" : ["padID", "html"],
|
||||
"getRevisionsCount" : ["padID"],
|
||||
"getLastEdited" : ["padID"],
|
||||
"deletePad" : ["padID"],
|
||||
"getReadOnlyID" : ["padID"],
|
||||
"setPublicStatus" : ["padID", "publicStatus"],
|
||||
"getPublicStatus" : ["padID"],
|
||||
"setPassword" : ["padID", "password"],
|
||||
"isPasswordProtected" : ["padID"]
|
||||
"isPasswordProtected" : ["padID"],
|
||||
"listAuthorsOfPad" : ["padID"],
|
||||
"padUsersCount" : ["padID"]
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
|
@ -33,6 +33,7 @@ var plugins = require("ep_etherpad-lite/static/js/pluginfw/plugins.js");
|
|||
var log4js = require('log4js');
|
||||
var messageLogger = log4js.getLogger("message");
|
||||
var _ = require('underscore');
|
||||
var hooks = require("ep_etherpad-lite/static/js/pluginfw/hooks.js");
|
||||
|
||||
/**
|
||||
* A associative array that saves which sessions belong to a pad
|
||||
|
@ -158,6 +159,11 @@ exports.handleDisconnect = function(client)
|
|||
*/
|
||||
exports.handleMessage = function(client, message)
|
||||
{
|
||||
_.map(hooks.callAll( "handleMessage", { client: client, message: message }), function ( newmessage ) {
|
||||
if ( newmessage || newmessage === null ) {
|
||||
message = newmessage;
|
||||
}
|
||||
});
|
||||
if(message == null)
|
||||
{
|
||||
messageLogger.warn("Message is null!");
|
||||
|
@ -168,31 +174,65 @@ exports.handleMessage = function(client, message)
|
|||
messageLogger.warn("Message has no type attribute!");
|
||||
return;
|
||||
}
|
||||
|
||||
//Check what type of message we get and delegate to the other methodes
|
||||
if(message.type == "CLIENT_READY") {
|
||||
handleClientReady(client, message);
|
||||
} else if(message.type == "CHANGESET_REQ") {
|
||||
handleChangesetRequest(client, message);
|
||||
} else if(message.type == "COLLABROOM") {
|
||||
if (sessioninfos[client.id].readonly) {
|
||||
messageLogger.warn("Dropped message, COLLABROOM for readonly pad");
|
||||
} else if (message.data.type == "USER_CHANGES") {
|
||||
handleUserChanges(client, message);
|
||||
} else if (message.data.type == "USERINFO_UPDATE") {
|
||||
handleUserInfoUpdate(client, message);
|
||||
} else if (message.data.type == "CHAT_MESSAGE") {
|
||||
handleChatMessage(client, message);
|
||||
} else if (message.data.type == "SAVE_REVISION") {
|
||||
handleSaveRevisionMessage(client, message);
|
||||
} else if (message.data.type == "CLIENT_MESSAGE" &&
|
||||
message.data.payload.type == "suggestUserName") {
|
||||
handleSuggestUserName(client, message);
|
||||
|
||||
var finalHandler = function () {
|
||||
//Check what type of message we get and delegate to the other methodes
|
||||
if(message.type == "CLIENT_READY") {
|
||||
handleClientReady(client, message);
|
||||
} else if(message.type == "CHANGESET_REQ") {
|
||||
handleChangesetRequest(client, message);
|
||||
} else if(message.type == "COLLABROOM") {
|
||||
if (sessioninfos[client.id].readonly) {
|
||||
messageLogger.warn("Dropped message, COLLABROOM for readonly pad");
|
||||
} else if (message.data.type == "USER_CHANGES") {
|
||||
handleUserChanges(client, message);
|
||||
} else if (message.data.type == "USERINFO_UPDATE") {
|
||||
handleUserInfoUpdate(client, message);
|
||||
} else if (message.data.type == "CHAT_MESSAGE") {
|
||||
handleChatMessage(client, message);
|
||||
} else if (message.data.type == "SAVE_REVISION") {
|
||||
handleSaveRevisionMessage(client, message);
|
||||
} else if (message.data.type == "CLIENT_MESSAGE" &&
|
||||
message.data.payload.type == "suggestUserName") {
|
||||
handleSuggestUserName(client, message);
|
||||
} else {
|
||||
messageLogger.warn("Dropped message, unknown COLLABROOM Data Type " + message.data.type);
|
||||
}
|
||||
} else {
|
||||
messageLogger.warn("Dropped message, unknown COLLABROOM Data Type " + message.data.type);
|
||||
messageLogger.warn("Dropped message, unknown Message Type " + message.type);
|
||||
}
|
||||
};
|
||||
|
||||
if (message && message.padId) {
|
||||
async.series([
|
||||
//check permissions
|
||||
function(callback)
|
||||
{
|
||||
// Note: message.sessionID is an entirely different kind of
|
||||
// session from the sessions we use here! Beware! FIXME: Call
|
||||
// our "sessions" "connections".
|
||||
// FIXME: Use a hook instead
|
||||
// FIXME: Allow to override readwrite access with readonly
|
||||
securityManager.checkAccess(message.padId, message.sessionID, message.token, message.password, function(err, statusObject)
|
||||
{
|
||||
if(ERR(err, callback)) return;
|
||||
|
||||
//access was granted
|
||||
if(statusObject.accessStatus == "grant")
|
||||
{
|
||||
callback();
|
||||
}
|
||||
//no access, send the client a message that tell him why
|
||||
else
|
||||
{
|
||||
client.json.send({accessStatus: statusObject.accessStatus})
|
||||
}
|
||||
});
|
||||
},
|
||||
finalHandler
|
||||
]);
|
||||
} else {
|
||||
messageLogger.warn("Dropped message, unknown Message Type " + message.type);
|
||||
finalHandler();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1308,3 +1348,14 @@ function composePadChangesets(padId, startNum, endNum, callback)
|
|||
callback(null, changeset);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the number of users in a pad
|
||||
*/
|
||||
exports.padUsersCount = function (padID, callback) {
|
||||
if (!pad2sessions[padID] || typeof pad2sessions[padID] != typeof []) {
|
||||
callback(null, {padUsersCount: 0});
|
||||
} else {
|
||||
callback(null, {padUsersCount: pad2sessions[padID].length});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
var padManager = require('../../db/PadManager');
|
||||
var url = require('url');
|
||||
|
||||
exports.expressCreateServer = function (hook_name, args, cb) {
|
||||
//redirects browser to the pad's sanitized url if needed. otherwise, renders the html
|
||||
|
@ -14,9 +15,11 @@ exports.expressCreateServer = function (hook_name, args, cb) {
|
|||
//the pad id was sanitized, so we redirect to the sanitized version
|
||||
if(sanitizedPadId != padId)
|
||||
{
|
||||
var real_path = req.path.replace(/^\/p\/[^\/]+/, '/p/' + sanitizedPadId);
|
||||
res.header('Location', real_path);
|
||||
res.send('You should be redirected to <a href="' + real_path + '">' + real_path + '</a>', 302);
|
||||
var real_url = sanitizedPadId;
|
||||
var query = url.parse(req.url).query;
|
||||
if ( query ) real_url += '?' + query;
|
||||
res.header('Location', real_url);
|
||||
res.send('You should be redirected to <a href="' + real_url + '">' + real_url + '</a>', 302);
|
||||
}
|
||||
//the pad id was fine, so just render it
|
||||
else
|
||||
|
|
|
@ -20,7 +20,6 @@ var log4js = require('log4js');
|
|||
|
||||
var Changeset = require("ep_etherpad-lite/static/js/Changeset");
|
||||
var contentcollector = require("ep_etherpad-lite/static/js/contentcollector");
|
||||
var map = require("ep_etherpad-lite/static/js/ace2_common").map;
|
||||
|
||||
function setPadHTML(pad, html, callback)
|
||||
{
|
||||
|
@ -50,9 +49,7 @@ function setPadHTML(pad, html, callback)
|
|||
}
|
||||
|
||||
// Get the new plain text and its attributes
|
||||
var newText = map(result.lines, function (e) {
|
||||
return e + '\n';
|
||||
}).join('');
|
||||
var newText = result.lines.join('\n');
|
||||
apiLogger.debug('newText:');
|
||||
apiLogger.debug(newText);
|
||||
var newAttribs = result.lineAttribs.join('|1+1') + '|1+1';
|
||||
|
@ -62,7 +59,7 @@ function setPadHTML(pad, html, callback)
|
|||
var attribsIter = Changeset.opIterator(attribs);
|
||||
var textIndex = 0;
|
||||
var newTextStart = 0;
|
||||
var newTextEnd = newText.length - 1;
|
||||
var newTextEnd = newText.length;
|
||||
while (attribsIter.hasNext())
|
||||
{
|
||||
var op = attribsIter.next();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue