From 992efc49340fba59d7529d68040529b36c80d2b2 Mon Sep 17 00:00:00 2001 From: nora Date: Mon, 15 Mar 2021 14:45:40 -0400 Subject: [PATCH 1/2] Adds apos as a dev dependancy for tests --- package.json | 1 + 1 file changed, 1 insertion(+) diff --git a/package.json b/package.json index bd4cb5f..38424f1 100644 --- a/package.json +++ b/package.json @@ -26,6 +26,7 @@ "apostrophe": "^2.108.1" }, "devDependencies": { + "apostrophe": "^2.116.1", "eslint": "^7.4.0", "eslint-config-apostrophe": "^3.2.0", "eslint-config-standard": "^14.1.1", From f379e15d38eb69a3e5ba33fd76815365bf5b4104 Mon Sep 17 00:00:00 2001 From: nora Date: Mon, 15 Mar 2021 14:47:28 -0400 Subject: [PATCH 2/2] Adds permission and permissionErrorMessage props and documents in readme --- README.md | 10 ++++++++++ lib/guide.js | 12 ++++++------ 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 55fc708..b44e8c8 100644 --- a/README.md +++ b/README.md @@ -123,6 +123,16 @@ As a template: ``` +### permission + +- Required: `N` +- Default: `guest` + +### permissionErrorMessage + +- Required: `N` +- Default: `You must be logged in to view this page` + ## Writing Documentation All documentation is written in Markdown with some added bonuses. Check [Markdown Guide](https://www.markdownguide.org/extended-syntax/) for a reference on how to write Markdown. In addition to the basics, you may also include [tables](https://www.markdownguide.org/extended-syntax/#tables) and [code blocks](https://www.markdownguide.org/extended-syntax/#fenced-code-blocks). diff --git a/lib/guide.js b/lib/guide.js index bc0ad7f..36e9f56 100644 --- a/lib/guide.js +++ b/lib/guide.js @@ -20,6 +20,8 @@ In your module, be sure to include a sections key.` options.path = options.path || 'guide'; options.public = options.public || false; + options.permission = options.permission || 'guest'; + options.permissionErrorMessage = options.permissionErrorMessage || 'You must be logged in to view this page'; const stylesheets = options.stylesheets; const scripts = options.scripts; @@ -36,13 +38,11 @@ In your module, be sure to include a sections key.` path: options.path }; - const permissionErrorMessage = 'You must be logged in to view this page'; - self.addRoutes = () => { self.apos.app.get(`/${options.path}`, (req, res) => { if (!canView(req)) { res.statusCode = 403; - return res.send(permissionErrorMessage); + return res.send(options.permissionErrorMessage); } const sections = setActive( @@ -90,7 +90,7 @@ In your module, be sure to include a sections key.` function canView(req) { return ( options.public === true || - (options.public === false && self.apos.permissions.can(req, 'guest')) + (options.public === false && self.apos.permissions.can(req, options.permission)) ); } @@ -99,7 +99,7 @@ In your module, be sure to include a sections key.` self.apos.app.get(demo, (req, res) => { if (!canView(req)) { res.statusCode = 403; - return res.send(permissionErrorMessage); + return res.send(options.permissionErrorMessage); } const template = path.basename(demo); return self.sendPage(req, `demos/${template}`, { ...data }); @@ -123,7 +123,7 @@ In your module, be sure to include a sections key.` self.apos.app.get(`${url}`, (req, res) => { if (!canView(req)) { res.statusCode = 403; - return res.send(permissionErrorMessage); + return res.send(options.permissionErrorMessage); } const sections = setActive(self.data.sections, page);