##Problems with role-based authorizations
e.g. gem 'access-granted'
https://github.com/chaps-io/access-granted
role :admin, { is_admin: true } do
can :destroy, Post
end
role :member do
can :read, Post
can :create, Post
end
####Authorizing controller actions
class PostsController
def show
@post = Post.find(params[:id])
authorize! :read, @post
end
def create
authorize! :create, Post
# (...)
end
end
we have to define authorize!
for each controller action; in case of many controllers, it could be overwhelming, e.g. 42 controllers -> 312 methods to define authorize!
alternative approach needed!
like this:
- group controllers in directories (folders), like: admin/, super_admin/ ...
- define authorization rules based on User role methods: e.g. super_admin? admin? auditor? tech? (role methods returns boolean value)
- check for user authorization in controllers or in the ApplicationController