-
Notifications
You must be signed in to change notification settings - Fork 246
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6fb20ba
commit a887d16
Showing
3 changed files
with
52 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
defmodule Changelog.Policies.Feed do | ||
use Changelog.Policies.Default | ||
|
||
def index(actor), do: is_active_member(actor) | ||
def create(actor), do: is_active_member(actor) | ||
|
||
def update(actor, feed), do: is_owner(actor, feed) | ||
def delete(actor, feed), do: is_owner(actor, feed) | ||
|
||
defp is_active_member(nil), do: false | ||
defp is_active_member(actor), do: Map.get(actor, :active_membership, false) | ||
|
||
defp is_owner(actor, feed) do | ||
feed | ||
|> Map.get(:owner, nil) | ||
|> Kernel.==(actor) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
defmodule Changelog.Policies.FeedTest do | ||
use Changelog.PolicyCase | ||
|
||
alias Changelog.Policies.Feed | ||
|
||
test "only active members can index" do | ||
refute Feed.index(@guest) | ||
assert Feed.index(@member) | ||
end | ||
|
||
test "only active members can new/create" do | ||
refute Feed.new(@user) | ||
assert Feed.new(@member) | ||
|
||
refute Feed.create(@guest) | ||
assert Feed.create(@member) | ||
end | ||
|
||
test "only active members can manage their own feeds" do | ||
refute Feed.update(@user, %{owner: @member}) | ||
assert Feed.update(@member, %{owner: @member}) | ||
|
||
refute Feed.delete(@user, %{owner: @member}) | ||
assert Feed.delete(@member, %{owner: @member}) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters