Skip to content
This repository has been archived by the owner on Jan 12, 2023. It is now read-only.

Commit

Permalink
fixes delete calls breaking for non-authorize calls
Browse files Browse the repository at this point in the history
  • Loading branch information
JaneJeon committed Jan 4, 2020
1 parent d109d93 commit 23f9868
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 13 deletions.
2 changes: 2 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ module.exports = (acl, library = 'role-acl', opts) => {

// wrappers around acl, querybuilder, and model
_checkAccess (action, body) {
if (!this._shouldCheckAccess) return body

const {
_user: user,
_resource: resource,
Expand Down
2 changes: 1 addition & 1 deletion lib/role-acl@3.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
// and M: the number of rules to match.
exports.getAccess = (acl, user, resource, action, body, opts) =>
acl
.can(opts.roleFromUser(user)) // role
.can(opts.roleFromUser(user))
.execute(action)
.context(
Object.assign(
Expand Down
18 changes: 6 additions & 12 deletions lib/role-acl@4.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
// With role-acl v4.3.2, they brought back synchronous acl checks.
// This is basically the same as role-acl@3 except we now have to append .sync()
exports.getAccess = (acl, user, resource, action, body, opts) =>
// to get the same behaviour of v<4.
const roleAcl3 = require('./role-acl@3')

roleAcl3.getAccess = (acl, user, resource, action, body, opts) =>
acl
.can(opts.roleFromUser(user)) // role
.can(opts.roleFromUser(user))
.execute(action)
.context(
Object.assign(
Expand All @@ -15,13 +18,4 @@ exports.getAccess = (acl, user, resource, action, body, opts) =>
.sync()
.on(resource.constructor.name)

exports.isAuthorized = access => access.granted

exports.pickFields = access =>
access.attributes.filter(field => field !== '*' && !field.startsWith('!')) ||
[]

exports.omitFields = access =>
access.attributes
.filter(field => field.startsWith('!'))
.map(field => field.substr(1)) || []
module.exports = roleAcl3
4 changes: 4 additions & 0 deletions test/utils/plugin-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,10 @@ module.exports = (acl, library) => {
.authorize(testUser)
.delete()
})

test("doesn't break non-authorize calls", async () => {
await User.query().deleteById(5)
})
})
})
})
Expand Down

0 comments on commit 23f9868

Please sign in to comment.