Ruby on Rails Thursday, October 4, 2018

Ok, that makes sense...

Everything is working fine the way it is coded but I am fairly new to RoR and want to learn proper practices.

One of the things I do with pundit is to filter the data by a particular School District, so in the "scope" of Pundit I look to see what role the user has and filter the data presented by the districts they are allowed to see.

I'll look at moving some of that to the models instead.

For example, here is a scope section from one of my policies

  class Scope < Scope
    def resolve
      if @user.is_global_admin?
        scope.all
      elsif @user.is_facilitator?
        scope.by_districts(@user.district_ids)
      elsif @user.is_district_admin(@session[:global_district_id])
        scope.by_districts(@user.district_ids)
      elsif @user.is_district_user(@session[:global_district_id])
        scope.by_districts(@user.district_ids)
      elsif @user.is_district_viewer(@session[:global_building_id])
        scope.by_districts(@user.district_ids)
      elsif @user.is_building_admin(@session[:global_building_id])
        scope.by_buildings(@user.building_ids)
      elsif @user.is_building_user(@session[:global_building_id])
        scope.by_buildings(@user.building_ids)
      elsif @user.is_building_viewer(@session[:global_building_id])
        scope.by_buildings(@user.building_ids)
      elsif @user.is_classroom_user
        scope.where(id: @session[:global_building_id])
      elsif @user.is_classroom_viewer
        scope.where(id: @session[:global_building_id])
      else
        scope.none
      end
    end
  end


--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/093f9fea-149d-4188-920a-a2254ae0e790%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment