become canadian

This commit is contained in:
byte[] 2019-09-30 21:12:38 -04:00
parent 9802454a48
commit c984872066
5 changed files with 37 additions and 5 deletions

View file

@ -0,0 +1,20 @@
defimpl Canada.Can, for: [Atom, Philomena.Users.User] do
alias Philomena.Users.User
alias Philomena.Images.Image
# Admins can do anything
def can?(%User{role: "admin"}, _action, _model), do: true
# Users can...
# View non-deleted images
def can?(_user, action, Image)
when action in [:new, :create, :index],
do: true
def can?(_user, :read, %Image{hidden_from_users: true}), do: false
def can?(_user, :read, %Image{hidden_from_users: false}), do: true
# Otherwise...
def can?(_user, _action, _model), do: false
end

View file

@ -50,7 +50,8 @@ defmodule Philomena.MixProject do
{:pot, "~> 0.10.1"}, {:pot, "~> 0.10.1"},
{:secure_compare, "~> 0.1.0"}, {:secure_compare, "~> 0.1.0"},
{:elastix, "~> 0.7.1"}, {:elastix, "~> 0.7.1"},
{:nimble_parsec, "~> 0.5.1"} {:nimble_parsec, "~> 0.5.1"},
{:canary, "~> 1.1.1"}
] ]
end end

View file

@ -1,5 +1,6 @@
%{ %{
"bcrypt_elixir": {:hex, :bcrypt_elixir, "2.0.3", "64e0792d5b5064391927bf3b8e436994cafd18ca2d2b76dea5c76e0adcf66b7c", [:make, :mix], [{:comeonin, "~> 5.1", [hex: :comeonin, repo: "hexpm", optional: false]}, {:elixir_make, "~> 0.4", [hex: :elixir_make, repo: "hexpm", optional: false]}], "hexpm"}, "bcrypt_elixir": {:hex, :bcrypt_elixir, "2.0.3", "64e0792d5b5064391927bf3b8e436994cafd18ca2d2b76dea5c76e0adcf66b7c", [:make, :mix], [{:comeonin, "~> 5.1", [hex: :comeonin, repo: "hexpm", optional: false]}, {:elixir_make, "~> 0.4", [hex: :elixir_make, repo: "hexpm", optional: false]}], "hexpm"},
"canada": {:hex, :canada, "2.0.0", "ce5e058f576a0625959fc5427fcde15311fb28a5ebc13775eafd13468ad16553", [:mix], [], "hexpm"},
"certifi": {:hex, :certifi, "2.5.1", "867ce347f7c7d78563450a18a6a28a8090331e77fa02380b4a21962a65d36ee5", [:rebar3], [{:parse_trans, "~>3.3", [hex: :parse_trans, repo: "hexpm", optional: false]}], "hexpm"}, "certifi": {:hex, :certifi, "2.5.1", "867ce347f7c7d78563450a18a6a28a8090331e77fa02380b4a21962a65d36ee5", [:rebar3], [{:parse_trans, "~>3.3", [hex: :parse_trans, repo: "hexpm", optional: false]}], "hexpm"},
"comeonin": {:hex, :comeonin, "5.1.2", "fbbbbbfcf0f0e9900c0336d16c8d462edf838ba1759577e29cc5fbd7c28a4540", [:mix], [], "hexpm"}, "comeonin": {:hex, :comeonin, "5.1.2", "fbbbbbfcf0f0e9900c0336d16c8d462edf838ba1759577e29cc5fbd7c28a4540", [:mix], [], "hexpm"},
"connection": {:hex, :connection, "1.0.4", "a1cae72211f0eef17705aaededacac3eb30e6625b04a6117c1b2db6ace7d5976", [:mix], [], "hexpm"}, "connection": {:hex, :connection, "1.0.4", "a1cae72211f0eef17705aaededacac3eb30e6625b04a6117c1b2db6ace7d5976", [:mix], [], "hexpm"},

View file

@ -39,12 +39,17 @@ defmodule Philomena.PollOptionsTest do
test "update_poll_option/2 with valid data updates the poll_option" do test "update_poll_option/2 with valid data updates the poll_option" do
poll_option = poll_option_fixture() poll_option = poll_option_fixture()
assert {:ok, %PollOption{} = poll_option} = PollOptions.update_poll_option(poll_option, @update_attrs)
assert {:ok, %PollOption{} = poll_option} =
PollOptions.update_poll_option(poll_option, @update_attrs)
end end
test "update_poll_option/2 with invalid data returns error changeset" do test "update_poll_option/2 with invalid data returns error changeset" do
poll_option = poll_option_fixture() poll_option = poll_option_fixture()
assert {:error, %Ecto.Changeset{}} = PollOptions.update_poll_option(poll_option, @invalid_attrs)
assert {:error, %Ecto.Changeset{}} =
PollOptions.update_poll_option(poll_option, @invalid_attrs)
assert poll_option == PollOptions.get_poll_option!(poll_option.id) assert poll_option == PollOptions.get_poll_option!(poll_option.id)
end end

View file

@ -96,12 +96,17 @@ defmodule Philomena.TopicsTest do
test "update_subscription/2 with valid data updates the subscription" do test "update_subscription/2 with valid data updates the subscription" do
subscription = subscription_fixture() subscription = subscription_fixture()
assert {:ok, %Subscription{} = subscription} = Topics.update_subscription(subscription, @update_attrs)
assert {:ok, %Subscription{} = subscription} =
Topics.update_subscription(subscription, @update_attrs)
end end
test "update_subscription/2 with invalid data returns error changeset" do test "update_subscription/2 with invalid data returns error changeset" do
subscription = subscription_fixture() subscription = subscription_fixture()
assert {:error, %Ecto.Changeset{}} = Topics.update_subscription(subscription, @invalid_attrs)
assert {:error, %Ecto.Changeset{}} =
Topics.update_subscription(subscription, @invalid_attrs)
assert subscription == Topics.get_subscription!(subscription.id) assert subscription == Topics.get_subscription!(subscription.id)
end end