mirror of
https://github.com/philomena-dev/philomena.git
synced 2024-11-23 20:18:00 +01:00
Fix wrong awarding user for automatic artist badge award
This commit is contained in:
parent
40fa0331b1
commit
0b93a1814a
2 changed files with 12 additions and 3 deletions
|
@ -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}} ->
|
||||||
|
|
|
@ -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
|
||||||
|
|
Loading…
Reference in a new issue