import: setting for allowing import without author existing

pull/4068/head
John McLear 2020-06-01 18:19:06 +01:00 committed by GitHub
parent 9fdb9e224c
commit bfca481b0b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 32 additions and 4 deletions

View File

@ -467,6 +467,19 @@
*/ */
"importMaxFileSize": 52428800, // 50 * 1024 * 1024 "importMaxFileSize": 52428800, // 50 * 1024 * 1024
/*
* From Etherpad 1.8.3 onwards import was restricted to authors who had
* content within the pad.
*
* This setting will override that restriction and allow any user to import
* without the requirement to add content to a pad.
*
* This setting is useful for when you use a plugin for authentication so you
* can already trust each user.
*/
"allowAnyoneToImport": false,
/* /*
* Toolbar buttons configuration. * Toolbar buttons configuration.
* *

View File

@ -1131,6 +1131,7 @@ async function handleClientReady(client, message)
}, },
"initialChangesets": [], // FIXME: REMOVE THIS SHIT "initialChangesets": [], // FIXME: REMOVE THIS SHIT
"thisUserHasEditedThisPad": thisUserHasEditedThisPad, "thisUserHasEditedThisPad": thisUserHasEditedThisPad,
"allowAnyoneToImport": settings.allowAnyoneToImport
} }
// Add a username to the clientVars if one avaiable // Add a username to the clientVars if one avaiable

View File

@ -83,20 +83,20 @@ exports.expressCreateServer = function (hook_name, args, cb) {
let author = await authorManager.getAuthor4Token(req.cookies.token); let author = await authorManager.getAuthor4Token(req.cookies.token);
// author is of the form: "a.g2droBYw1prY7HW9" // author is of the form: "a.g2droBYw1prY7HW9"
if (!author) { if (!author && !settings.allowAnyoneToImport) {
console.warn(`Unable to import file into "${req.params.pad}". No Author found for token ${req.cookies.token}`); console.warn(`Unable to import file into "${req.params.pad}". No Author found for token ${req.cookies.token}`);
return next(); return next();
} }
let authorsPads = await authorManager.listPadsOfAuthor(author); let authorsPads = await authorManager.listPadsOfAuthor(author);
if (!authorsPads) { if (!authorsPads && !settings.allowAnyoneToImport) {
console.warn(`Unable to import file into "${req.params.pad}". Author "${author}" exists but he never contributed to any pad`); console.warn(`Unable to import file into "${req.params.pad}". Author "${author}" exists but he never contributed to any pad`);
return next(); return next();
} }
let authorsPadIDs = authorsPads.padIDs; let authorsPadIDs = authorsPads.padIDs;
if (authorsPadIDs.indexOf(req.params.pad) === -1) { if ( (authorsPadIDs.indexOf(req.params.pad) === -1) && !settings.allowAnyoneToImport) {
console.warn(`Unable to import file into "${req.params.pad}". Author "${author}" exists but he never contributed to this pad`); console.warn(`Unable to import file into "${req.params.pad}". Author "${author}" exists but he never contributed to this pad`);
return next(); return next();
} }

View File

@ -351,6 +351,20 @@ exports.importExportRateLimiting = {
*/ */
exports.importMaxFileSize = 50 * 1024 * 1024; exports.importMaxFileSize = 50 * 1024 * 1024;
/*
* From Etherpad 1.8.3 onwards import was restricted to authors who had
* content within the pad.
*
* This setting will override that restriction and allow any user to import
* without the requirement to add content to a pad.
*
* This setting is useful for when you use a plugin for authentication so you
* can already trust each user.
*/
exports.allowAnyoneToImport = false,
// checks if abiword is avaiable // checks if abiword is avaiable
exports.abiwordAvailable = function() exports.abiwordAvailable = function()
{ {

View File

@ -408,7 +408,7 @@ var padeditbar = (function()
toolbar.registerCommand("import_export", function () { toolbar.registerCommand("import_export", function () {
toolbar.toggleDropDown("import_export", function(){ toolbar.toggleDropDown("import_export", function(){
if (clientVars.thisUserHasEditedThisPad) { if (clientVars.thisUserHasEditedThisPad || clientVars.allowAnyoneToImport) {
// the user has edited this pad historically or in this session // the user has edited this pad historically or in this session
$('#importform').show(); $('#importform').show();
$('#importmessagepermission').hide(); $('#importmessagepermission').hide();