0

I'm working on a project where I'm trying to use lit https://github.com/prograils/lit to organise my translation file. So I've installed the gem and done the it's working. The problem is that the dashboard is now available to any user.

We use devise for authentication and pundit for authorization, but I can't find any mechanism to restrict access to the dashboard depending on the users role.

Any help would be greatly appreciated.

user2320239
  • 1,021
  • 2
  • 18
  • 43

1 Answers1

0

dashboard depending on the users role. is something you need to achieve using(in your case) Pundit. As you mentioned you are already using it then you should be able to do something like below:

class DashboardPolicy
  :
  :
  :

  def show?
    user.admin?
  end
end

In you user.rb model you will need a method which would return a boolean value something like:

def admin?
  self.role == "admin"
end

Update (in case of no access to controller method)

As you mentioned you dont have access to the controller method then in this case you may want to check for constraints at the routes level.

I wont be adding code snippets here since it has been documented really well on another question you can check out the answer here: https://stackoverflow.com/a/29136866/2545197 and also read more about the same here: http://guides.rubyonrails.org/routing.html#advanced-constraints

Abhinay
  • 1,796
  • 4
  • 28
  • 52