mirror of
https://github.com/philomena-dev/philomena.git
synced 2024-11-27 21:47:59 +01:00
peform alias resolution in user links (fixes philomena-dev/philomena#52)
This commit is contained in:
parent
b5bc7d2d6b
commit
a7b1ecf204
1 changed files with 13 additions and 2 deletions
|
@ -54,7 +54,7 @@ defmodule Philomena.UserLinks do
|
||||||
|
|
||||||
"""
|
"""
|
||||||
def create_user_link(user, attrs \\ %{}) do
|
def create_user_link(user, attrs \\ %{}) do
|
||||||
tag = Repo.get_by(Tag, name: attrs["tag_name"])
|
tag = fetch_tag(attrs["tag_name"])
|
||||||
|
|
||||||
%UserLink{}
|
%UserLink{}
|
||||||
|> UserLink.creation_changeset(attrs, user, tag)
|
|> UserLink.creation_changeset(attrs, user, tag)
|
||||||
|
@ -74,7 +74,7 @@ defmodule Philomena.UserLinks do
|
||||||
|
|
||||||
"""
|
"""
|
||||||
def update_user_link(%UserLink{} = user_link, attrs) do
|
def update_user_link(%UserLink{} = user_link, attrs) do
|
||||||
tag = Repo.get_by(Tag, name: attrs["tag_name"])
|
tag = fetch_tag(attrs["tag_name"])
|
||||||
|
|
||||||
user_link
|
user_link
|
||||||
|> UserLink.edit_changeset(attrs, tag)
|
|> UserLink.edit_changeset(attrs, tag)
|
||||||
|
@ -159,4 +159,15 @@ defmodule Philomena.UserLinks do
|
||||||
nil
|
nil
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
defp fetch_tag(name) do
|
||||||
|
Tag
|
||||||
|
|> preload(:aliased_tag)
|
||||||
|
|> where(name: ^name)
|
||||||
|
|> Repo.one()
|
||||||
|
|> case do
|
||||||
|
nil -> nil
|
||||||
|
tag -> tag.aliased_tag || tag
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue