Allow removing prefix from URL / remove dynamic params (middleware) #180
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Now, if we have a route like
/api/users
, we can remove theapi
prefix by passing a negative number to themiddleware
method; so, I'd domiddleware(-1)
to remove first part of the URL, or -2 to remove first 2 pieces of the URL.Also, as part of this PR, we're now able to pass an additional argument to
middleware(...)
method: this new argument named dynamicParams, will set a list of URL parameters (as defined via express router, for example) that will be excluded from the resource name when checking permissions.ATM, we didn't have a way to define a route (like a view endpoint, whose path looks like /user/89324892384) having a predefined parameter which is dynamic (:id, in this case). So, if I do:
acl.middleware(-1, getUser, 'view', ['id'])
I'm stating that the ACL module must only check for view permission over the rest of the resource's name, excluding the :id part.