Skip to content
This repository has been archived by the owner on Feb 24, 2024. It is now read-only.

Best way to get the current resource name #1762

Closed
seguidor777 opened this issue Aug 13, 2019 · 5 comments
Closed

Best way to get the current resource name #1762

seguidor777 opened this issue Aug 13, 2019 · 5 comments
Labels
enhancement New feature or request help wanted Feel free to contribute!

Comments

@seguidor777
Copy link

seguidor777 commented Aug 13, 2019

Hello,

I am working on a feature that uses policies to authorize requests basing on a user role, an action and a resource.

I have no problem to get the first two, but I am facing issues with getting the resource name, since I only have the full path. Is there any efficient way to get that with any function similar to controller_name from Rails?

@seguidor777
Copy link
Author

seguidor777 commented Aug 13, 2019

I could extract the resource name from the name of the handler, for example:
handlerName: = c.Data()["current_route"].(buffalo.RouteInfo).HandlerName

Lets suppose that handlerName is something like "github.com/company/project/actions.UsersResource.Edit"
And with some regexp stuff I capture the UsersResource string, but this does not convince me at all

@markbates markbates added enhancement New feature or request good first issue help wanted Feel free to contribute! labels Aug 15, 2019
@alexisvisco
Copy link
Contributor

With the RouteInfo you have the Handler, maybe using reflect you could get the resource name ?

(I am doing a pr with the resource name in the RouteInfo and I rely on the name of the handler with reflect as they do to have the HandlerName (with suffix List, Delete, Show ...)

@seguidor777
Copy link
Author

Hello! Thanks for replying. I agree with the proposal, it would be great to have the resource and the action names on separate fields, for example ResourceName and ActionName

@paganotoni
Copy link
Member

@seguidor777 the RouteInfo has both: ResourceName and Handler name.

@paganotoni
Copy link
Member

Closing this one as it seems to be solved. please reopen if still relevant.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request help wanted Feel free to contribute!
Projects
None yet
Development

No branches or pull requests

4 participants