-
Notifications
You must be signed in to change notification settings - Fork 23
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
Role in trestle #11
Comments
This isn't currently possible but should hopefully be very soon (I'm planning on working on it within the next couple of weeks). |
Would love to see this too! Been trying to have content editors / 'true' administrators, and some things are a little tricky to do |
looking forward to this |
Could be nice to have an idea on how to start so we can help |
This is important! |
Any word on this? |
Is this possible yet? |
Hi guys! There is any new about this issue? I will love to add some roles to my panel in order to show or hide menus in relation with user roles. |
I found a way, and it's also pretty straightforward. It's just an idea but I tested it and it works. Let's use the Pundit gem, remember that roles must be managed separately. inside an admin resource, take Customer for example: Trestle.resource(:customers) do
...
controller do
include Pundit
after_action :verify_authorized
def index
authorize Customer
super
end
def show
authorize instance
super
end
end
end Remember to create a policy for the customer, an easy one would be: class CustomerPolicy < ApplicationPolicy
class Scope < Scope
def resolve
scope.all
end
end
def index?
true
end
def show?
false
end
end Adding some config to the controller could help, instead of opening all the methods of the controller, maybe @spohlenz could give us some ideas when he sees this solution, it seems that everything is inherited from "Trestle::AdminController" and "Trestle::ResourceController" Hope this help! |
Hi, just wanted to ask if there is any news on this or is the pundit still the best way? |
I needed to have this role based support, and using @McRipper suggestion is easy enough. The only difficulty I found was how to apply Scope policies when the resolve method is more complicated than def resolve
scope.all
end It can be applied in the index, as usual, however, it is important to know that the Trestle.resource(:customers) do
...
controller do
include Pundit::Authorization
after_action :verify_authorized, except: :index
after_action :verify_policy_scoped, only: :index
def index
@collection = policy_scope @collection
end
... If we want to totally cut off some classes of users from seeing the list of resources, we could Trestle.resource(:customers) do
...
controller do
include Pundit::Authorization
after_action :verify_authorized, except: :index
def index
authorize Customer
end By using both This way of using |
How to custom trestle-auth by Role, Role Group . ..v..v..
Thks
The text was updated successfully, but these errors were encountered: