Remove User.fields/1
This commit is contained in:
parent
9172d719cc
commit
3420dec494
|
@ -1993,21 +1993,6 @@ def roles(%{is_moderator: is_moderator, is_admin: is_admin}) do
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
# ``fields`` is an array of mastodon profile field, containing ``{"name": "…", "value": "…"}``.
|
|
||||||
# For example: [{"name": "Pronoun", "value": "she/her"}, …]
|
|
||||||
def fields(%{fields: nil, source_data: %{"attachment" => attachment}}) do
|
|
||||||
limit = Pleroma.Config.get([:instance, :max_remote_account_fields], 0)
|
|
||||||
|
|
||||||
attachment
|
|
||||||
|> Enum.filter(fn %{"type" => t} -> t == "PropertyValue" end)
|
|
||||||
|> Enum.map(fn fields -> Map.take(fields, ["name", "value"]) end)
|
|
||||||
|> Enum.take(limit)
|
|
||||||
end
|
|
||||||
|
|
||||||
def fields(%{fields: nil}), do: []
|
|
||||||
|
|
||||||
def fields(%{fields: fields}), do: fields
|
|
||||||
|
|
||||||
def validate_fields(changeset, remote? \\ false) do
|
def validate_fields(changeset, remote? \\ false) do
|
||||||
limit_name = if remote?, do: :max_remote_account_fields, else: :max_account_fields
|
limit_name = if remote?, do: :max_remote_account_fields, else: :max_account_fields
|
||||||
limit = Pleroma.Config.get([:instance, limit_name], 0)
|
limit = Pleroma.Config.get([:instance, limit_name], 0)
|
||||||
|
@ -2195,9 +2180,7 @@ def sanitize_html(%User{} = user) do
|
||||||
# - display name
|
# - display name
|
||||||
def sanitize_html(%User{} = user, filter) do
|
def sanitize_html(%User{} = user, filter) do
|
||||||
fields =
|
fields =
|
||||||
user
|
Enum.map(user.fields, fn %{"name" => name, "value" => value} ->
|
||||||
|> User.fields()
|
|
||||||
|> Enum.map(fn %{"name" => name, "value" => value} ->
|
|
||||||
%{
|
%{
|
||||||
"name" => name,
|
"name" => name,
|
||||||
"value" => HTML.filter_tags(value, Pleroma.HTML.Scrubber.LinksOnly)
|
"value" => HTML.filter_tags(value, Pleroma.HTML.Scrubber.LinksOnly)
|
||||||
|
|
|
@ -79,10 +79,7 @@ def render("user.json", %{user: user}) do
|
||||||
|
|
||||||
emoji_tags = Transmogrifier.take_emoji_tags(user)
|
emoji_tags = Transmogrifier.take_emoji_tags(user)
|
||||||
|
|
||||||
fields =
|
fields = Enum.map(user.fields, &Map.put(&1, "type", "PropertyValue"))
|
||||||
user
|
|
||||||
|> User.fields()
|
|
||||||
|> Enum.map(&Map.put(&1, "type", "PropertyValue"))
|
|
||||||
|
|
||||||
%{
|
%{
|
||||||
"id" => user.ap_id,
|
"id" => user.ap_id,
|
||||||
|
|
|
@ -746,7 +746,7 @@ test "it works with custom profile fields" do
|
||||||
|
|
||||||
user = User.get_cached_by_ap_id(activity.actor)
|
user = User.get_cached_by_ap_id(activity.actor)
|
||||||
|
|
||||||
assert User.fields(user) == [
|
assert user.fields == [
|
||||||
%{"name" => "foo", "value" => "bar"},
|
%{"name" => "foo", "value" => "bar"},
|
||||||
%{"name" => "foo1", "value" => "bar1"}
|
%{"name" => "foo1", "value" => "bar1"}
|
||||||
]
|
]
|
||||||
|
@ -767,7 +767,7 @@ test "it works with custom profile fields" do
|
||||||
|
|
||||||
user = User.get_cached_by_ap_id(user.ap_id)
|
user = User.get_cached_by_ap_id(user.ap_id)
|
||||||
|
|
||||||
assert User.fields(user) == [
|
assert user.fields == [
|
||||||
%{"name" => "foo", "value" => "updated"},
|
%{"name" => "foo", "value" => "updated"},
|
||||||
%{"name" => "foo1", "value" => "updated"}
|
%{"name" => "foo1", "value" => "updated"}
|
||||||
]
|
]
|
||||||
|
@ -785,7 +785,7 @@ test "it works with custom profile fields" do
|
||||||
|
|
||||||
user = User.get_cached_by_ap_id(user.ap_id)
|
user = User.get_cached_by_ap_id(user.ap_id)
|
||||||
|
|
||||||
assert User.fields(user) == [
|
assert user.fields == [
|
||||||
%{"name" => "foo", "value" => "updated"},
|
%{"name" => "foo", "value" => "updated"},
|
||||||
%{"name" => "foo1", "value" => "updated"}
|
%{"name" => "foo1", "value" => "updated"}
|
||||||
]
|
]
|
||||||
|
@ -796,7 +796,7 @@ test "it works with custom profile fields" do
|
||||||
|
|
||||||
user = User.get_cached_by_ap_id(user.ap_id)
|
user = User.get_cached_by_ap_id(user.ap_id)
|
||||||
|
|
||||||
assert User.fields(user) == []
|
assert user.fields == []
|
||||||
end
|
end
|
||||||
|
|
||||||
test "it works for incoming update activities which lock the account" do
|
test "it works for incoming update activities which lock the account" do
|
||||||
|
|
Loading…
Reference in New Issue