Fix wrong awarding user for automatic artist badge award

This commit is contained in:
Liam 2024-07-29 11:26:11 -04:00
parent 40fa0331b1
commit 0b93a1814a
2 changed files with 12 additions and 3 deletions

View file

@ -93,7 +93,7 @@ defmodule Philomena.ArtistLinks do
Multi.new() Multi.new()
|> Multi.update(:artist_link, artist_link_changeset) |> Multi.update(:artist_link, artist_link_changeset)
|> Multi.run(:add_award, fn _repo, _changes -> BadgeAwarder.award_badge(artist_link) end) |> Multi.run(:add_award, BadgeAwarder.award_callback(artist_link, verifying_user))
|> Repo.transaction() |> Repo.transaction()
|> case do |> case do
{:ok, %{artist_link: artist_link}} -> {:ok, %{artist_link: artist_link}} ->

View file

@ -16,13 +16,22 @@ defmodule Philomena.ArtistLinks.BadgeAwarder do
Returns `{:ok, award}`, `{:ok, nil}`, or `{:error, changeset}`. The return value is Returns `{:ok, award}`, `{:ok, nil}`, or `{:error, changeset}`. The return value is
suitable for use as the return value to an `Ecto.Multi.run/3` callback. suitable for use as the return value to an `Ecto.Multi.run/3` callback.
""" """
def award_badge(artist_link) do def award_badge(artist_link, verifying_user) do
with badge when not is_nil(badge) <- Badges.get_badge_by_title(@badge_title), with badge when not is_nil(badge) <- Badges.get_badge_by_title(@badge_title),
award when is_nil(award) <- Badges.get_badge_award_for(badge, artist_link.user) do award when is_nil(award) <- Badges.get_badge_award_for(badge, artist_link.user) do
Badges.create_badge_award(artist_link.user, artist_link.user, %{badge_id: badge.id}) Badges.create_badge_award(verifying_user, artist_link.user, %{badge_id: badge.id})
else else
_ -> _ ->
{:ok, nil} {:ok, nil}
end end
end end
@doc """
Get a callback for issuing a badge award from within an `m:Ecto.Multi`.
"""
def award_callback(artist_link, verifying_user) do
fn _repo, _changes ->
award_badge(artist_link, verifying_user)
end
end
end end