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

Routes with paramters #66

Closed
arliber opened this issue Sep 14, 2014 · 4 comments
Closed

Routes with paramters #66

arliber opened this issue Sep 14, 2014 · 4 comments

Comments

@arliber
Copy link

arliber commented Sep 14, 2014

Hi,

I can't seem to understand how to work with express routes with parameters..
Basically what I'm trying to do is to make the following code to grant access to the resource while now it blocks it:

acl.allow('guestRole', 'blogs/:blogId', 'view')
acl.addUserRoles('guest', 'guestRole')

acl.isAllowed('guest', 'blogs/123', 'view', function(err, res){
    if(res){
        console.log("Granted")
    } else {
        console.log("Denied")
    }
});

I would expect the resource 'blogs/123' to be mapped to 'blogs/:blogId' but it looks like it does string comparison only, ignoring the fact that ':blogId' could be any number.

I hope I clearly explained my self :)

Thanks

@manast
Copy link
Member

manast commented Sep 15, 2014

You should take a look at this issue: #38
I think it may answer this question and many others.

@manast manast closed this as completed Sep 15, 2014
@arliber
Copy link
Author

arliber commented Sep 15, 2014

Thank you, but I've already read this and implemented my own method to replace ids with param1, param2 etc. but it does not solve my problem since in my case the following route: "/resource/:id/subResource/:otherId" could map down to "/resource/aStringID/subResource/123-456-789".
In such case replacing "aStringID" with "param1" and "123-456-789" with "param2" is not possible (there is no such pattern).

I think what I need is a way to get the original route and compare it my self the req.url while omitting any ":x".

What do you think?

@arliber
Copy link
Author

arliber commented Sep 16, 2014

Some kind of a solution:
I ended up using req.route.path and treating it as the actual resource instead of the req.url.
That way I don't need to do funny regex replacement becuase the req.route.path already contains the the route parameters as specified in the ACL.

What do you think? Am I missing something?

@futurechan
Copy link

@LeonLiber if you are using memory-backend, you might consider https://github.com/futurechan/node_acl-mem-regexp

It does use regexes, but it's not much different than what you'd already be writing. An example is provided.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants