From 359b66ce93054d2c840ea3d9fe90b97cceb28bdd Mon Sep 17 00:00:00 2001 From: Erik Kallen Date: Wed, 29 Aug 2018 15:10:37 +0200 Subject: [PATCH 1/2] Regression in adonis4.x in passing properties to middleware fixes #22 --- README.md | 8 ++++---- src/Middlewares/Is.js | 5 ++++- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 400f630..b895a0d 100644 --- a/README.md +++ b/README.md @@ -321,17 +321,17 @@ await user.permissions().fetch() Syntax: -`and (&&)` - administrator && moderator +`and` - administrator,and,moderator -`or (||)` - administrator || moderator +`or` - administrator,or,moderator -`not (!)` - administrator && !moderator +`not` - administrator,and,not,moderator ```js // check roles Route .get('/users') - .middleware(['auth:jwt', 'is:(administrator || moderator) && !customer']) + .middleware(['auth:jwt', 'is:(administrator,or,moderator),and,not,customer']) // check permissions Route diff --git a/src/Middlewares/Is.js b/src/Middlewares/Is.js index e2a3671..8a659d1 100644 --- a/src/Middlewares/Is.js +++ b/src/Middlewares/Is.js @@ -12,8 +12,11 @@ class Is { async handle ({ auth }, next, ...args) { let expression = args[0] if (Array.isArray(expression)) { - expression = expression[0] + expression = expression.join(' ') } + expression = expression.replace(' or ', ' || ') + expression = expression.replace(' and ', ' && ') + expression = expression.replace(' not ', ' !') const is = await auth.user.is(expression) if (!is) { throw new ForbiddenException() From 3a3ebc76a6481344664855dd648e0fab51eb87ed Mon Sep 17 00:00:00 2001 From: Erik Kallen Date: Wed, 5 Sep 2018 08:41:49 +0200 Subject: [PATCH 2/2] Updated readme to remove unneeded commas in the is rule as suggested by cmelgarejo --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index b895a0d..500418a 100644 --- a/README.md +++ b/README.md @@ -331,7 +331,7 @@ Syntax: // check roles Route .get('/users') - .middleware(['auth:jwt', 'is:(administrator,or,moderator),and,not,customer']) + .middleware(['auth:jwt', 'is:(administrator or moderator) and not customer']) // check permissions Route