schrockwell/bodyguard

Elaborate documentation concerning roles checks inside authorize function

acrolink opened this issue · 2 comments

In documentation, an example is given to make role checks inside authorize function. Kindly, provide more information how to implement the role field itself, datatype, schema properties etc.

  # Admin users can do anything
  def authorize(_, %Blog.User{role: :admin}, _), do: :ok

Update:

I have managed to do this:

 def authorize(:list_posts, %User{role: "admin"}, _), do: :ok

I have created a Roles table with a string field named name as primary key. But still I need to specify it as "admin" not :admin in def authorize(...)

Yes, the role field is an implementation detail left to the user. It could be an atom in some cases.