diff options
author | Logan Hunt <loganhunt@simponic.xyz> | 2022-04-13 12:42:01 -0600 |
---|---|---|
committer | Logan Hunt <loganhunt@simponic.xyz> | 2022-04-13 12:42:01 -0600 |
commit | 9d5a369ff6aa2dc3a80f104ffdc622ddf594a725 (patch) | |
tree | 78f7a8e7728a997bb02773c4623c43dc30de6328 /lib/aggiedit/roles.ex | |
parent | 76b083a2bd7e0ab694af3e4fb2504e3869f97113 (diff) | |
download | aggiedit-9d5a369ff6aa2dc3a80f104ffdc622ddf594a725.tar.gz aggiedit-9d5a369ff6aa2dc3a80f104ffdc622ddf594a725.zip |
Add guards on post resources
Diffstat (limited to 'lib/aggiedit/roles.ex')
-rw-r--r-- | lib/aggiedit/roles.ex | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/lib/aggiedit/roles.ex b/lib/aggiedit/roles.ex new file mode 100644 index 0000000..e50b53b --- /dev/null +++ b/lib/aggiedit/roles.ex @@ -0,0 +1,10 @@ +defmodule Aggiedit.Roles do + alias Aggiedit.Accounts.User + alias Aggiedit.Rooms.Post + + def guard?(user, action, object) + def guard?(%User{role: :admin}, _, _), do: true + def guard?(%User{room_id: rid}, :show, %Post{room_id: rid}), do: true + 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 +end
\ No newline at end of file |