Simplify read-only pad ID checks

pull/5002/head
Richard Hansen 2021-04-12 17:57:44 -04:00
parent f63610bb12
commit 329d037431
2 changed files with 3 additions and 4 deletions

View File

@ -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);

View File

@ -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,