Simplify read-only pad ID checks
parent
f63610bb12
commit
329d037431
|
@ -28,7 +28,7 @@ const randomString = require('../utils/randomstring');
|
|||
* checks if the id pattern matches a read-only pad id
|
||||
* @param {String} the pad's id
|
||||
*/
|
||||
exports.isReadOnlyId = (id) => id.indexOf('r.') === 0;
|
||||
exports.isReadOnlyId = (id) => id.startsWith('r.');
|
||||
|
||||
/**
|
||||
* returns a read only id for a pad
|
||||
|
@ -59,7 +59,7 @@ exports.getPadId = (readOnlyId) => db.get(`readonly2pad:${readOnlyId}`);
|
|||
* @param {String} padIdOrReadonlyPadId read only id or real pad id
|
||||
*/
|
||||
exports.getIds = async (id) => {
|
||||
const readonly = (id.indexOf('r.') === 0);
|
||||
const readonly = exports.isReadOnlyId(id);
|
||||
|
||||
// Might be null, if this is an unknown read-only id
|
||||
const readOnlyPadId = readonly ? id : await exports.getReadOnlyId(id);
|
||||
|
|
|
@ -46,8 +46,7 @@ exports.expressCreateServer = (hookName, args, cb) => {
|
|||
// serve pad.html under /p
|
||||
args.app.get('/p/:pad', (req, res, next) => {
|
||||
// The below might break for pads being rewritten
|
||||
const isReadOnly =
|
||||
req.url.indexOf('/p/r.') === 0 || !webaccess.userCanModify(req.params.pad, req);
|
||||
const isReadOnly = !webaccess.userCanModify(req.params.pad, req);
|
||||
|
||||
hooks.callAll('padInitToolbar', {
|
||||
toolbar,
|
||||
|
|
Loading…
Reference in New Issue