Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
liamwhite committed Jul 29, 2024
2 parents d345bbc + f9e8911 commit c3fe297
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
2 changes: 1 addition & 1 deletion lib/philomena/artist_links.ex
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ defmodule Philomena.ArtistLinks do

Multi.new()
|> 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()
|> case do
{:ok, %{artist_link: artist_link}} ->
Expand Down
13 changes: 11 additions & 2 deletions lib/philomena/artist_links/badge_awarder.ex
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,22 @@ defmodule Philomena.ArtistLinks.BadgeAwarder do
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.
"""
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),
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
_ ->
{:ok, nil}
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
1 change: 1 addition & 0 deletions lib/philomena_web/controllers/dnp_entry_controller.ex
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ defmodule PhilomenaWeb.DnpEntryController do
alias PhilomenaWeb.MarkdownRenderer
alias Philomena.DnpEntries
alias Philomena.Tags.Tag
alias Philomena.ModNotes.ModNote
alias Philomena.ModNotes
alias Philomena.Repo
import Ecto.Query
Expand Down

0 comments on commit c3fe297

Please sign in to comment.