In my application i have a controller contracts_controller and i
want to apply authorization on it using a column(contract_expiry_date)
of user table.
On searching i find out only if_attribute :user_id => is {user} and
nothing else. that checks the attribute of controller on which we want
to apply authorization.
How can i check contract_expiry_date of user table to authorize
contract controller.
Thanks
Dev
if_attribute :contract_expiry_date => is {user.contract_expiry_date}
Also, remember to add :attribute_check => true when calling
filter_access_to in the users controller.
filter_access_to :index, :new, :create, :show, :update, :destroy, :attribute_check
=> true
> > How can i check contract_expiry_date of usertableto authorize
> > contract controller.
>
> > Thanks
> > Dev
It's seems more natural to have contract_expiry_date as an attribute
of the contracts, as there are many people who are not bound by
contracts. I would instead consider moving this column to the
contracts table... it seems much more at home there.
role :normal_user do
if Authorization.current_user.contract_expiry_date >
Time.now
has_permission_on [:timesheets], :to =>
[:new, :create, :edit, :update, :destroy]
end
end
Thanks for your replies Jearlu.. :)
Dev
I think you can do it, can't you? Syntax would be something like
has_permission_on :contract, :to => [:update] do
if_attribute :user => { :contract_expiry_date => ... }
end
No?
> I have to check whether it is greater than Time.now or not.
> With this how will i use greater than(>) sign.
Look in reader.rb. You have the option of using :lt, :gte, etc. I
guess Time.now will work in the block.