Skip to content

Commit

Permalink
Merge pull request ether#2 from mconf/export-read-only
Browse files Browse the repository at this point in the history
Fix readOnly pad export
  • Loading branch information
pedrobmarin committed Sep 16, 2020
2 parents 3bc93aa + ca0547e commit 5e1526b
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 9 deletions.
9 changes: 9 additions & 0 deletions src/node/db/ReadOnlyManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,15 @@
var db = require("./DB");
var randomString = require("../utils/randomstring");

/**
* checks if the id pattern matches a read-only pad id
* @param {String} the pad's id
*/
exports.isReadOnlyId = function(id)
{
return id.indexOf("r.") === 0;
}

/**
* returns a read only id for a pad
* @param {String} padId the id of the pad
Expand Down
8 changes: 4 additions & 4 deletions src/node/handler/ExportHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ const tempDirectory = os.tmpdir();
/**
* do a requested export
*/
async function doExport(req, res, padId, type)
async function doExport(req, res, padId, readOnlyId, type)
{
var fileName = padId;
var fileName = readOnlyId ? readOnlyId : padId;

// allow fileName to be overwritten by a hook, the type type is kept static for security reasons
let hookFileName = await hooks.aCallFirst("exportFileName", padId);
Expand Down Expand Up @@ -130,9 +130,9 @@ async function doExport(req, res, padId, type)
}
}

exports.doExport = function(req, res, padId, type)
exports.doExport = function(req, res, padId, readOnlyId, type)
{
doExport(req, res, padId, type).catch(err => {
doExport(req, res, padId, readOnlyId, type).catch(err => {
if (err !== "stop") {
throw err;
}
Expand Down
13 changes: 11 additions & 2 deletions src/node/hooks/express/importexport.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ var settings = require('../../utils/Settings');
var exportHandler = require('../../handler/ExportHandler');
var importHandler = require('../../handler/ImportHandler');
var padManager = require("../../db/PadManager");
var readOnlyManager = require("../../db/ReadOnlyManager");

exports.expressCreateServer = function (hook_name, args, cb) {
args.app.get('/p/:pad/:rev?/export/:type', async function(req, res, next) {
Expand All @@ -23,12 +24,20 @@ exports.expressCreateServer = function (hook_name, args, cb) {

if (await hasPadAccess(req, res)) {
console.log('req.params.pad', req.params.pad);
let exists = await padManager.doesPadExists(req.params.pad);
let padId = req.params.pad;

let readOnlyId = null;
if (readOnlyManager.isReadOnlyId(padId)) {
readOnlyId = padId;
padId = await readOnlyManager.getPadId(readOnlyId);
}

let exists = await padManager.doesPadExists(padId);
if (!exists) {
return next();
}

exportHandler.doExport(req, res, req.params.pad, req.params.type);
exportHandler.doExport(req, res, padId, readOnlyId, req.params.type);
}
});

Expand Down
3 changes: 0 additions & 3 deletions src/static/css/pad.css
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,6 @@ textarea {
iframe {
position: absolute
}
.readonly .acl-write {
display: none;
}

#users {
background: #f7f7f7;
Expand Down

0 comments on commit 5e1526b

Please sign in to comment.