mirror of
https://github.com/ether/etherpad-lite.git
synced 2025-05-09 08:25:00 -04:00
removing the need for requireAuthorization setting since its now determinated automatically whether auth. plugins are registered
This commit is contained in:
parent
83648481c3
commit
ec65ded0c8
4 changed files with 37 additions and 33 deletions
|
@ -51,8 +51,6 @@
|
|||
Note: /admin always requires authentication. */
|
||||
"requireAuthentication": false,
|
||||
|
||||
/* Require authorization by a module, or a user with is_admin set, see below. */
|
||||
"requireAuthorization": false,
|
||||
|
||||
/* Users for basic authentication. is_admin = true gives access to /admin.
|
||||
If you do not uncomment this, /admin will not be available! */
|
||||
|
|
|
@ -8,9 +8,12 @@ var hooks = require('ep_etherpad-lite/static/js/pluginfw/hooks');
|
|||
|
||||
//checks for basic http auth
|
||||
exports.basicAuth = function (req, res, next) {
|
||||
|
||||
var hookResultMangle = function (cb) {
|
||||
return function (err, data) {
|
||||
return cb(!err && data.length && data[0]);
|
||||
// If data has 1 or more element, use the first one to decide if a user
|
||||
// is authenticated, if its empty or undefined, no plugin gave its 'ok'
|
||||
return cb(!err && data !== undefined && data.length < 1 && data[0]);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -18,9 +21,11 @@ exports.basicAuth = function (req, res, next) {
|
|||
// Do not require auth for static paths...this could be a bit brittle
|
||||
if (req.path.match(/^\/(static|javascripts|pluginfw)/)) return cb(true);
|
||||
|
||||
var requirePluginAuthorization = hooks.registeredCallbacks('authorize').length > 0;
|
||||
|
||||
if (req.path.indexOf('/admin') != 0) {
|
||||
if (!settings.requireAuthentication) return cb(true);
|
||||
if (!settings.requireAuthorization && req.session && req.session.user) return cb(true);
|
||||
if (!requirePluginAuthorization && req.session && req.session.user) return cb(true);
|
||||
}
|
||||
|
||||
if (req.session && req.session.user && req.session.user.is_admin) return cb(true);
|
||||
|
|
|
@ -80,11 +80,11 @@ exports.abiword = null;
|
|||
*/
|
||||
exports.loglevel = "INFO";
|
||||
|
||||
/* This setting is used if you need authentication and/or
|
||||
* authorization. Note: /admin always requires authentication, and
|
||||
* either authorization by a module, or a user with is_admin set */
|
||||
/* This setting is used if you need authentication.
|
||||
* Note: /admin always requires authentication, and
|
||||
* either authorization by a module, or a user with is_admin set.
|
||||
* Plugins may override this behavior */
|
||||
exports.requireAuthentication = false;
|
||||
exports.requireAuthorization = false;
|
||||
exports.users = {};
|
||||
|
||||
//checks if abiword is avaiable
|
||||
|
|
|
@ -62,25 +62,22 @@ exports.mapFirst = function (lst, fn, cb) {
|
|||
}
|
||||
|
||||
|
||||
/* Don't use Array.concat as it flatterns arrays within the array */
|
||||
exports.flatten = function (lst) {
|
||||
var res = [];
|
||||
if (lst != undefined && lst != null) {
|
||||
for (var i = 0; i < lst.length; i++) {
|
||||
if (lst[i] != undefined && lst[i] != null) {
|
||||
for (var j = 0; j < lst[i].length; j++) {
|
||||
res.push(lst[i][j]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return res;
|
||||
/*
|
||||
Returns all registered callbacks of a hook
|
||||
@param string hook_name the hook to retrieve the callbacks for.
|
||||
@return an array of callback functions, an empty array if no callbacks are registered
|
||||
*/
|
||||
exports.registeredCallbacks = function (hook_name){
|
||||
console.log(plugins.hooks[hook_name])
|
||||
return (plugins.hooks[hook_name] !== undefined) ? plugins.hooks[hook_name] : [];
|
||||
}
|
||||
|
||||
exports.callAll = function (hook_name, args) {
|
||||
if (!args) args = {};
|
||||
if (plugins.hooks[hook_name] === undefined) return [];
|
||||
return _.flatten(_.map(plugins.hooks[hook_name], function (hook) {
|
||||
var callbacks = exports.registeredCallbacks(hook_name);
|
||||
|
||||
return _.flatten(
|
||||
_.map(callbacks, function (hook) {
|
||||
return hookCallWrapper(hook, hook_name, args);
|
||||
}), true);
|
||||
}
|
||||
|
@ -88,9 +85,10 @@ exports.callAll = function (hook_name, args) {
|
|||
exports.aCallAll = function (hook_name, args, cb) {
|
||||
if (!args) args = {};
|
||||
if (!cb) cb = function () {};
|
||||
if (plugins.hooks[hook_name] === undefined) return cb(null, []);
|
||||
var callbacks = exports.registeredCallbacks(hook_name);
|
||||
|
||||
async.map(
|
||||
plugins.hooks[hook_name],
|
||||
callbacks,
|
||||
function (hook, cb) {
|
||||
hookCallWrapper(hook, hook_name, args, function (res) { cb(null, res); });
|
||||
},
|
||||
|
@ -102,18 +100,21 @@ exports.aCallAll = function (hook_name, args, cb) {
|
|||
|
||||
exports.callFirst = function (hook_name, args) {
|
||||
if (!args) args = {};
|
||||
if (plugins.hooks[hook_name][0] === undefined) return [];
|
||||
return exports.syncMapFirst(plugins.hooks[hook_name], function (hook) {
|
||||
return hookCallWrapper(hook, hook_name, args);
|
||||
var callbacks = exports.registeredCallbacks(hook_name);
|
||||
|
||||
return exports.syncMapFirst(callbacks, function (hook) {
|
||||
var res = hookCallWrapper(hook, hook_name, args);
|
||||
return res !== undefined ? res : [];
|
||||
});
|
||||
}
|
||||
|
||||
exports.aCallFirst = function (hook_name, args, cb) {
|
||||
if (!args) args = {};
|
||||
if (!cb) cb = function () {};
|
||||
if (plugins.hooks[hook_name] === undefined) return cb(null, []);
|
||||
var callbacks = exports.registeredCallbacks(hook_name);
|
||||
|
||||
exports.mapFirst(
|
||||
plugins.hooks[hook_name],
|
||||
callbacks,
|
||||
function (hook, cb) {
|
||||
hookCallWrapper(hook, hook_name, args, function (res) { cb(null, res); });
|
||||
},
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue