some reformatting and adjusting so logged in users get moved directly to their feed
This commit is contained in:
@@ -38,6 +38,24 @@ defmodule Mixer.Posts.Media do
|
||||
end
|
||||
end
|
||||
|
||||
policies do
|
||||
policy action_type(:read) do
|
||||
authorize_if always()
|
||||
end
|
||||
|
||||
policy action(:upload) do
|
||||
authorize_if actor_present()
|
||||
end
|
||||
|
||||
policy action(:link_to_tweet) do
|
||||
authorize_if relates_to_actor_via(:user)
|
||||
end
|
||||
|
||||
policy action_type(:destroy) do
|
||||
authorize_if relates_to_actor_via(:user)
|
||||
end
|
||||
end
|
||||
|
||||
attributes do
|
||||
uuid_primary_key :id
|
||||
|
||||
@@ -64,22 +82,4 @@ defmodule Mixer.Posts.Media do
|
||||
public? true
|
||||
end
|
||||
end
|
||||
|
||||
policies do
|
||||
policy action_type(:read) do
|
||||
authorize_if always()
|
||||
end
|
||||
|
||||
policy action(:upload) do
|
||||
authorize_if actor_present()
|
||||
end
|
||||
|
||||
policy action(:link_to_tweet) do
|
||||
authorize_if relates_to_actor_via(:user)
|
||||
end
|
||||
|
||||
policy action_type(:destroy) do
|
||||
authorize_if relates_to_actor_via(:user)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -10,7 +10,8 @@ defmodule Mixer.Posts.MediaUploader do
|
||||
if ext in @extensions, do: :ok, else: {:error, "unsupported file type #{ext}"}
|
||||
end
|
||||
|
||||
def storage_dir(_version, {_file, scope}), do: "uploads/media/#{scope.user_id}/#{scope.media_id}"
|
||||
def storage_dir(_version, {_file, scope}),
|
||||
do: "uploads/media/#{scope.user_id}/#{scope.media_id}"
|
||||
|
||||
def filename(_version, {file, _scope}) do
|
||||
Path.basename(file.file_name, Path.extname(file.file_name))
|
||||
|
||||
@@ -14,10 +14,6 @@ defmodule Mixer.Posts.Tweet do
|
||||
repo Mixer.Repo
|
||||
end
|
||||
|
||||
typescript do
|
||||
type_name "tweets"
|
||||
end
|
||||
|
||||
state_machine do
|
||||
initial_states [:drafted, :posted]
|
||||
default_initial_state :drafted
|
||||
@@ -27,6 +23,10 @@ defmodule Mixer.Posts.Tweet do
|
||||
end
|
||||
end
|
||||
|
||||
typescript do
|
||||
type_name "tweets"
|
||||
end
|
||||
|
||||
actions do
|
||||
defaults [:read, :destroy]
|
||||
|
||||
@@ -36,6 +36,7 @@ defmodule Mixer.Posts.Tweet do
|
||||
argument :media_id, :uuid, allow_nil?: true
|
||||
change relate_actor(:user)
|
||||
change transition_state(:posted)
|
||||
|
||||
change fn changeset, context ->
|
||||
case Ash.Changeset.get_argument(changeset, :media_id) do
|
||||
nil ->
|
||||
@@ -45,7 +46,9 @@ defmodule Mixer.Posts.Tweet do
|
||||
Ash.Changeset.after_action(changeset, fn _changeset, tweet ->
|
||||
Mixer.Posts.Media
|
||||
|> Ash.get!(media_id, authorize?: false)
|
||||
|> Ash.Changeset.for_update(:link_to_tweet, %{tweet_id: tweet.id}, actor: context.actor)
|
||||
|> Ash.Changeset.for_update(:link_to_tweet, %{tweet_id: tweet.id},
|
||||
actor: context.actor
|
||||
)
|
||||
|> Ash.update!()
|
||||
|
||||
{:ok, tweet}
|
||||
@@ -111,6 +114,32 @@ defmodule Mixer.Posts.Tweet do
|
||||
end
|
||||
end
|
||||
|
||||
policies do
|
||||
policy action_type(:read) do
|
||||
authorize_if always()
|
||||
end
|
||||
|
||||
policy action_type(:create) do
|
||||
authorize_if actor_present()
|
||||
end
|
||||
|
||||
policy action(:update) do
|
||||
authorize_if relates_to_actor_via(:user)
|
||||
end
|
||||
|
||||
policy action(:destroy) do
|
||||
authorize_if relates_to_actor_via(:user)
|
||||
end
|
||||
|
||||
policy action(:like) do
|
||||
authorize_if actor_present()
|
||||
end
|
||||
|
||||
policy action(:unlike) do
|
||||
authorize_if actor_present()
|
||||
end
|
||||
end
|
||||
|
||||
attributes do
|
||||
uuid_primary_key :id
|
||||
|
||||
@@ -165,32 +194,6 @@ defmodule Mixer.Posts.Tweet do
|
||||
end
|
||||
end
|
||||
|
||||
policies do
|
||||
policy action_type(:read) do
|
||||
authorize_if always()
|
||||
end
|
||||
|
||||
policy action_type(:create) do
|
||||
authorize_if actor_present()
|
||||
end
|
||||
|
||||
policy action(:update) do
|
||||
authorize_if relates_to_actor_via(:user)
|
||||
end
|
||||
|
||||
policy action(:destroy) do
|
||||
authorize_if relates_to_actor_via(:user)
|
||||
end
|
||||
|
||||
policy action(:like) do
|
||||
authorize_if actor_present()
|
||||
end
|
||||
|
||||
policy action(:unlike) do
|
||||
authorize_if actor_present()
|
||||
end
|
||||
end
|
||||
|
||||
defp ensure_like(_tweet, nil), do: {:error, Ash.Error.Forbidden.exception([])}
|
||||
|
||||
defp ensure_like(tweet, actor) do
|
||||
|
||||
@@ -23,6 +23,20 @@ defmodule Mixer.Posts.TweetLike do
|
||||
end
|
||||
end
|
||||
|
||||
policies do
|
||||
policy action_type(:read) do
|
||||
authorize_if always()
|
||||
end
|
||||
|
||||
policy action(:create) do
|
||||
authorize_if actor_present()
|
||||
end
|
||||
|
||||
policy action_type(:destroy) do
|
||||
authorize_if relates_to_actor_via(:user)
|
||||
end
|
||||
end
|
||||
|
||||
attributes do
|
||||
uuid_primary_key :id
|
||||
|
||||
@@ -52,18 +66,4 @@ defmodule Mixer.Posts.TweetLike do
|
||||
identities do
|
||||
identity :unique_user_tweet, [:tweet_id, :user_id]
|
||||
end
|
||||
|
||||
policies do
|
||||
policy action_type(:read) do
|
||||
authorize_if always()
|
||||
end
|
||||
|
||||
policy action(:create) do
|
||||
authorize_if actor_present()
|
||||
end
|
||||
|
||||
policy action_type(:destroy) do
|
||||
authorize_if relates_to_actor_via(:user)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user