Rails CanCan Simple_form association issue -
why doesen't cancan stop dept_tech role creating users in detpartments dept_tech role has no access?
i using cancan autorization , simple_form views. have user model , department model.
class user < activerecord::base belongs_to :department ... end class department < activerecord::base has_many :departments ... end i have abilities model
class ability include cancan::ability def initialize(user) rails.logger.debug {" >>>>>>> user id: #{user.id} ...... if user.role? :admin ... elseif user.role? :dept_tech rails.logger.debug {" >>>>>>> role 6 ...... can :manage, user, :department_id => user.department_id can :read, department, :id => user.department_id rails.logger.debug {" >>>>>>> user.department: #{user.department_id}} end end end and user controller:
load_and_authorize_resource ... def new respond_to |format| rails.logger.debug {" >>>> here"} format.html # new.html.erb end rails.logger.debug {" >>>> there"} end ... there a
load_and_authorize_resource in department controller.
and _form view helper using simple_form
<% simple_form_for @user, :html => {class => 'form-horizontal' } |f| %> <%= f.input :email %> rails.logger.debug {" >>>> view"} <%= f.association :department %> .... <% end %> this works well, dept_tech can index , show actions department. works index, show action users. when new action on users performed collection_select department shows departments, not department of dept_tech.
the thinking dept_tech can create (manage) users of own department.
this log, shows select used without on department select, , done in view.
started "/users/new" 127.0.0.1 @ 2012-06-05 13:57:58 +0200 [2012-06-05 13:57:58 +0200] processing userscontroller#new html [2012-06-05 13:57:58 +0200] user load (0.9ms) select "users".* "users" "users"."id" = $1 limit 1 [["id", 2]] [2012-06-05 13:57:58 +0200] >>>> user id: 2, user role: ["dept_tech"], roles_mask: 64 [2012-06-05 13:57:58 +0200] >>>> role 6 [2012-06-05 13:57:58 +0200] >>>> user.department: 2 [2012-06-05 13:57:58 +0200] >>>> here [2012-06-05 13:57:58 +0200] >>>> view [2012-06-05 13:57:58 +0200] department load (0.9ms) select "departments".* "departments" [2012-06-05 13:57:58 +0200] rendered users/_form.html.erb (45.7ms) [2012-06-05 13:57:58 +0200] rendered users/new.html.erb within layouts/application (46.5ms) [2012-06-05 13:57:58 +0200] >>>> there [2012-06-05 13:57:58 +0200] completed 200 ok in 63ms (views: 56.4ms | activerecord: 1.8ms) the log shows not surprisingly sql gets called in view. simple_form issue? how solve?
Comments
Post a Comment