Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Regression in adonis4.x in passing properties to middleware fixes #22 #23

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 4 additions & 1 deletion src/Middlewares/Is.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down