added User.tag_names
This commit is contained in:
parent
a4dac51568
commit
1c00933953
@ -2006,6 +2006,13 @@ defmodule Pleroma.User do
|
||||
|
||||
def parse_bio(_, _), do: ""
|
||||
|
||||
def tag_names(%__MODULE__{} = user) do
|
||||
{:ok, tags} = Repo.get_assoc(user, :tags)
|
||||
Enum.map(tags, & &1.name)
|
||||
end
|
||||
|
||||
def tag_names(_), do: []
|
||||
|
||||
def tag(user_identifiers, tags) when is_list(user_identifiers) do
|
||||
Repo.transaction(fn ->
|
||||
for user_identifier <- user_identifiers, do: tag(user_identifier, tags)
|
||||
|
@ -32,13 +32,6 @@ defmodule Pleroma.Web.ActivityPub.MRF.TagPolicy do
|
||||
]
|
||||
end
|
||||
|
||||
defp get_tags(%User{} = user) do
|
||||
{:ok, tags} = Pleroma.Repo.get_assoc(user, :tags)
|
||||
Enum.map(tags, & &1.name)
|
||||
end
|
||||
|
||||
defp get_tags(_), do: []
|
||||
|
||||
defp process_tag(
|
||||
"mrf_tag:media-force-nsfw",
|
||||
%{
|
||||
@ -151,8 +144,9 @@ defmodule Pleroma.Web.ActivityPub.MRF.TagPolicy do
|
||||
defp process_tag(_, message), do: {:ok, message}
|
||||
|
||||
def filter_message(actor, message) do
|
||||
User.get_cached_by_ap_id(actor)
|
||||
|> get_tags()
|
||||
actor
|
||||
|> User.get_cached_by_ap_id()
|
||||
|> User.tag_names()
|
||||
|> Enum.reduce({:ok, message}, fn
|
||||
tag, {:ok, message} ->
|
||||
process_tag(tag, message)
|
||||
|
@ -66,7 +66,6 @@ defmodule Pleroma.Web.AdminAPI.AccountView do
|
||||
avatar = User.avatar_url(user) |> MediaProxy.url()
|
||||
display_name = Pleroma.HTML.strip_tags(user.name || user.nickname)
|
||||
user = User.sanitize_html(user, FastSanitize.Sanitizer.StripTags)
|
||||
{:ok, user_tags} = Pleroma.Repo.get_assoc(user, :tags)
|
||||
|
||||
%{
|
||||
"id" => user.id,
|
||||
@ -77,7 +76,7 @@ defmodule Pleroma.Web.AdminAPI.AccountView do
|
||||
"is_active" => user.is_active,
|
||||
"local" => user.local,
|
||||
"roles" => roles(user),
|
||||
"tags" => Enum.map(user_tags, & &1.name),
|
||||
"tags" => User.tag_names(user),
|
||||
"is_confirmed" => user.is_confirmed,
|
||||
"is_approved" => user.is_approved,
|
||||
"url" => user.uri || user.ap_id,
|
||||
|
@ -233,8 +233,6 @@ defmodule Pleroma.Web.MastodonAPI.AccountView do
|
||||
nil
|
||||
end
|
||||
|
||||
{:ok, user_tags} = Pleroma.Repo.get_assoc(user, :tags)
|
||||
|
||||
%{
|
||||
id: to_string(user.id),
|
||||
username: username_from_nickname(user.nickname),
|
||||
@ -271,7 +269,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountView do
|
||||
ap_id: user.ap_id,
|
||||
also_known_as: user.also_known_as,
|
||||
is_confirmed: user.is_confirmed,
|
||||
tags: Enum.map(user_tags, & &1.name),
|
||||
tags: User.tag_names(user),
|
||||
hide_followers_count: user.hide_followers_count,
|
||||
hide_follows_count: user.hide_follows_count,
|
||||
hide_followers: user.hide_followers,
|
||||
|
@ -152,6 +152,20 @@ defmodule Pleroma.UserTest do
|
||||
end
|
||||
end
|
||||
|
||||
describe "tag_names/1" do
|
||||
test "returns tag names of user" do
|
||||
user =
|
||||
insert(:user, %{
|
||||
tags: [
|
||||
build(:tag, name: "verify"),
|
||||
build(:tag, name: "spam")
|
||||
]
|
||||
})
|
||||
|
||||
assert User.tag_names(user) == ["verify", "spam"]
|
||||
end
|
||||
end
|
||||
|
||||
test "ap_id returns the activity pub id for the user" do
|
||||
user = UserBuilder.build()
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user