On Feb 1, 12:49 am, Steffen Bartsch <
sbart...@tzi.de> wrote:
>
> Three things to check: Are all requests denied? Then: What does the log say?
> ApplicationController#current_user also should rather be protected than
> private to be accessible from child controllers.
>
> Second, is the context inferred correctly (is it really :dashboard_locations,
> else it may e.g. be set with the :context parameter)?
>
> Third, have you tried passing the load_method:
> filter_access_to :edit, attribute_check: true, load_method: :find_location
> or setting the model:
> filter_access_to :edit, attribute_check: true, model: Location
>
>
http://www.tzi.org/~sbartsch/declarative_authorization/master/classes...
>
> Steffen
Thanks Steffen! I am really impressed by your support of this gem.
Thanks for the quick response!
Are all requests denied? - No requests were being denied. But I found
my problem, thanks to your prodding! As usual it was out of scope of
my example context. I missed a higher up rule that allowed the request
to pass. Now I just need to figure out all of my conditions!
To make this useful for others... I did make my current_user method
public and I did not have to specify the :load_method or the :model.
And my context was being inferred correctly.
I do have one question. The docs say this for filter_access_to:
----
Without the :attribute_check option, no constraints from the
authorization rules are enforced because for some actions
(collections, new, create), there is no object to evaluate conditions
against. To allow attribute checks on all actions, it is a common
pattern to provide custom objects through before_filters:
class BranchesController < ApplicationController
before_filter :load_company
before_filter :new_branch_from_company_and_params,
:only => [:index, :new, :create]
filter_access_to :all, :attribute_check => true
protected
def new_branch_from_company_and_params
@branch = @
company.branches.new(params[:branch])
end
end
----
While I get some of the ramifications, I am left with a few questions:
- In my example, I took away the attribute_check: true and it still
filtered on my if_attribute statements. Why? The statement "Without
the :attribute_check option, no constraints from the authorization
rules are enforced..." seems to infer that it will not check.
- Is attribute_check: true only needed on index, new, create? If so,
does declarative_authorization make assumptions about the instance
variable name? i.e. lower-case, underscored, singular of the
controller name?
Your library has proven itself to me yet again! Much thanks!