administrate
administrate copied to clipboard
filter specific action on a per-record basis
- What would you like to be able to do? Can you provide some examples?
At the moment if you want to filter out a specific action in the dashboards you can override valid_action?
def valid_action?(name, resource = resource_class)
%w[].exclude?(name.to_s) && super
end
Is there a way to fine tune that on a per resource basis, say I only want record of a certain type to be editable.
- How could we go about implementing that? Would be lovely to be able to write something like :
def valid_action?(name, resource = resource_class)
%w[ edit ].exclude?(name.to_s) if resource.kind = 'non_editable'
super
end
- Can you think of other approaches to the problem?
Would show_action? work for you? It's different from valid_action?. See http://administrate-demo.herokuapp.com/authorization
To clarify:
-
valid_action?: tells if a route exists for the action. It probably should be a private method... -
show_action?: controls authorization. For example, it's the one overriden by Punditize.
The names are a bit confusing. I'm currently working on a branch that should make this clearer.
Should be fixed by https://github.com/thoughtbot/administrate/pull/1941