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
|
2022-04-15 15:00:42 -04:00
|
|
|
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
|