Aggiedit/lib/aggiedit/roles.ex

13 lines
535 B
Elixir
Raw Normal View History

2022-04-13 14:42:01 -04:00
defmodule Aggiedit.Roles do
alias Aggiedit.Accounts.User
alias Aggiedit.Rooms.Post
2022-04-13 15:13:41 -04:00
alias Aggiedit.Rooms.Room
2022-04-13 14:42:01 -04:00
def guard?(user, action, object)
def guard?(%User{role: :admin}, _, _), do: true
2022-04-13 15:13:41 -04:00
def guard?(%User{room_id: rid}, :index, %Room{id: rid}), do: true
def guard?(%User{room_id: rid}, action, %Post{room_id: rid}) when action in [:show, :vote], do: true
2022-04-13 14:42:01 -04:00
def guard?(%User{id: id, room_id: rid}, action, %Post{user_id: id, room_id: rid}) when action in [:delete, :edit], do: true
def guard?(_, _, _), do: false
2022-04-13 15:13:41 -04:00
2022-04-13 14:42:01 -04:00
end