Merge branch 'develop' into pleroma-database-config-whitelist
This commit is contained in:
commit
c3b779036d
57 changed files with 1378 additions and 611 deletions
|
|
@ -226,7 +226,12 @@ defmodule Mix.Tasks.Pleroma.Database do
|
|||
DELETE FROM hashtags AS ht
|
||||
WHERE NOT EXISTS (
|
||||
SELECT 1 FROM hashtags_objects hto
|
||||
WHERE ht.id = hto.hashtag_id)
|
||||
WHERE ht.id = hto.hashtag_id
|
||||
)
|
||||
AND NOT EXISTS (
|
||||
SELECT 1 FROM user_follows_hashtag ufh
|
||||
WHERE ht.id = ufh.hashtag_id
|
||||
)
|
||||
"""
|
||||
|> Repo.query()
|
||||
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ defmodule Mix.Tasks.Pleroma.OpenapiSpec do
|
|||
else
|
||||
{_, errors} ->
|
||||
IO.puts(IO.ANSI.format([:red, :bright, "Spec check failed, errors:"]))
|
||||
Enum.map(errors, &IO.puts/1)
|
||||
Enum.each(errors, &IO.puts/1)
|
||||
|
||||
raise "Spec check failed"
|
||||
end
|
||||
|
|
|
|||
|
|
@ -38,7 +38,7 @@ defmodule Pleroma.Activity.HTML do
|
|||
|
||||
def invalidate_cache_for(activity_id) do
|
||||
keys = get_cache_keys_for(activity_id)
|
||||
Enum.map(keys, &@cachex.del(:scrubber_cache, &1))
|
||||
Enum.each(keys, &@cachex.del(:scrubber_cache, &1))
|
||||
@cachex.del(:scrubber_management_cache, activity_id)
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -22,7 +22,8 @@ defmodule Pleroma.Constants do
|
|||
"generator",
|
||||
"rules",
|
||||
"language",
|
||||
"voters"
|
||||
"voters",
|
||||
"assigned_account"
|
||||
]
|
||||
)
|
||||
|
||||
|
|
|
|||
|
|
@ -6,8 +6,9 @@ defmodule Pleroma.HTTP.AdapterHelper.Hackney do
|
|||
@behaviour Pleroma.HTTP.AdapterHelper
|
||||
|
||||
@defaults [
|
||||
follow_redirect: true,
|
||||
force_redirect: true
|
||||
follow_redirect: false,
|
||||
force_redirect: false,
|
||||
with_body: true
|
||||
]
|
||||
|
||||
@spec options(keyword(), URI.t()) :: keyword()
|
||||
|
|
|
|||
|
|
@ -132,11 +132,18 @@ defmodule Pleroma.ModerationLog do
|
|||
end
|
||||
|
||||
def insert_log(%{actor: %User{}, action: action, subject: %Activity{} = subject} = attrs)
|
||||
when action in ["report_note_delete", "report_update", "report_note"] do
|
||||
when action in [
|
||||
"report_note_delete",
|
||||
"report_update",
|
||||
"report_note",
|
||||
"report_unassigned",
|
||||
"report_assigned"
|
||||
] do
|
||||
data =
|
||||
attrs
|
||||
|> prepare_log_data
|
||||
|> Pleroma.Maps.put_if_present("text", attrs[:text])
|
||||
|> Pleroma.Maps.put_if_present("assigned_account", attrs[:assigned_account])
|
||||
|> Map.merge(%{"subject" => report_to_map(subject)})
|
||||
|
||||
insert_log_entry_with_message(%ModerationLog{data: data})
|
||||
|
|
@ -441,6 +448,35 @@ defmodule Pleroma.ModerationLog do
|
|||
" with '#{state}' state"
|
||||
end
|
||||
|
||||
def get_log_entry_message(
|
||||
%ModerationLog{
|
||||
data: %{
|
||||
"actor" => %{"nickname" => actor_nickname},
|
||||
"action" => "report_assigned",
|
||||
"subject" => %{"id" => subject_id, "type" => "report"},
|
||||
"assigned_account" => assigned_account
|
||||
}
|
||||
} = log
|
||||
) do
|
||||
"@#{actor_nickname} assigned report ##{subject_id}" <>
|
||||
subject_actor_nickname(log, " (on user ", ")") <>
|
||||
" to user #{assigned_account}"
|
||||
end
|
||||
|
||||
def get_log_entry_message(
|
||||
%ModerationLog{
|
||||
data: %{
|
||||
"actor" => %{"nickname" => actor_nickname},
|
||||
"action" => "report_unassigned",
|
||||
"subject" => %{"id" => subject_id, "type" => "report"}
|
||||
}
|
||||
} = log
|
||||
) do
|
||||
"@#{actor_nickname} unassigned report ##{subject_id}" <>
|
||||
subject_actor_nickname(log, " (on user ", ")") <>
|
||||
" from a user"
|
||||
end
|
||||
|
||||
def get_log_entry_message(
|
||||
%ModerationLog{
|
||||
data: %{
|
||||
|
|
|
|||
|
|
@ -5,6 +5,23 @@
|
|||
defmodule Pleroma.ReverseProxy.Client.Hackney do
|
||||
@behaviour Pleroma.ReverseProxy.Client
|
||||
|
||||
# In-app redirect handler to avoid Hackney redirect bugs:
|
||||
# - https://github.com/benoitc/hackney/issues/527 (relative/protocol-less redirects can crash Hackney)
|
||||
# - https://github.com/benoitc/hackney/issues/273 (redirects not followed when using HTTP proxy)
|
||||
#
|
||||
# Based on a redirect handler from Pleb, slightly modified to work with Hackney:
|
||||
# https://declin.eu/objects/d4f38e62-5429-4614-86d1-e8fc16e6bf33
|
||||
@redirect_statuses [301, 302, 303, 307, 308]
|
||||
defp absolute_redirect_url(original_url, resp_headers) do
|
||||
location =
|
||||
Enum.find(resp_headers, fn {header, _location} ->
|
||||
String.downcase(header) == "location"
|
||||
end)
|
||||
|
||||
URI.merge(original_url, elem(location, 1))
|
||||
|> URI.to_string()
|
||||
end
|
||||
|
||||
@impl true
|
||||
def request(method, url, headers, body, opts \\ []) do
|
||||
opts =
|
||||
|
|
@ -12,7 +29,35 @@ defmodule Pleroma.ReverseProxy.Client.Hackney do
|
|||
path
|
||||
end)
|
||||
|
||||
:hackney.request(method, url, headers, body, opts)
|
||||
if opts[:follow_redirect] != false do
|
||||
{_state, req_opts} = Access.get_and_update(opts, :follow_redirect, fn a -> {a, false} end)
|
||||
res = :hackney.request(method, url, headers, body, req_opts)
|
||||
|
||||
case res do
|
||||
{:ok, code, resp_headers, _client} when code in @redirect_statuses ->
|
||||
:hackney.request(
|
||||
method,
|
||||
absolute_redirect_url(url, resp_headers),
|
||||
headers,
|
||||
body,
|
||||
req_opts
|
||||
)
|
||||
|
||||
{:ok, code, resp_headers} when code in @redirect_statuses ->
|
||||
:hackney.request(
|
||||
method,
|
||||
absolute_redirect_url(url, resp_headers),
|
||||
headers,
|
||||
body,
|
||||
req_opts
|
||||
)
|
||||
|
||||
_ ->
|
||||
res
|
||||
end
|
||||
else
|
||||
:hackney.request(method, url, headers, body, opts)
|
||||
end
|
||||
end
|
||||
|
||||
@impl true
|
||||
|
|
|
|||
|
|
@ -45,7 +45,7 @@ defmodule Pleroma.UserRelationship do
|
|||
do: exists?(unquote(relationship_type), source, target)
|
||||
|
||||
# `def get_block_expire_date/2`, `def get_mute_expire_date/2`,
|
||||
# `def get_reblog_mute_expire_date/2`, `def get_notification_mute_exists?/2`,
|
||||
# `def get_reblog_mute_expire_date/2`, `def get_notification_mute_expire_date/2`,
|
||||
# `def get_inverse_subscription_expire_date/2`, `def get_inverse_endorsement_expire_date/2`
|
||||
def unquote(:"get_#{relationship_type}_expire_date")(source, target),
|
||||
do: get_expire_date(unquote(relationship_type), source, target)
|
||||
|
|
|
|||
|
|
@ -1003,6 +1003,14 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do
|
|||
|
||||
defp restrict_state(query, _), do: query
|
||||
|
||||
defp restrict_assigned_account(query, %{assigned_account: assigned_account}) do
|
||||
from(activity in query,
|
||||
where: fragment("?->>'assigned_account' = ?", activity.data, ^assigned_account)
|
||||
)
|
||||
end
|
||||
|
||||
defp restrict_assigned_account(query, _), do: query
|
||||
|
||||
defp restrict_favorited_by(query, %{favorited_by: ap_id}) do
|
||||
from(
|
||||
[_activity, object] in query,
|
||||
|
|
@ -1471,6 +1479,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do
|
|||
|> restrict_actor(opts)
|
||||
|> restrict_type(opts)
|
||||
|> restrict_state(opts)
|
||||
|> restrict_assigned_account(opts)
|
||||
|> restrict_favorited_by(opts)
|
||||
|> restrict_blocked(restrict_blocked_opts)
|
||||
|> restrict_blockers_visibility(opts)
|
||||
|
|
|
|||
|
|
@ -27,7 +27,14 @@ defmodule Pleroma.Web.ActivityPub.MRF.MediaProxyWarmingPolicy do
|
|||
end
|
||||
|
||||
defp fetch(url) do
|
||||
http_client_opts = Pleroma.Config.get([:media_proxy, :proxy_opts, :http], pool: :media)
|
||||
# This module uses Tesla (Pleroma.HTTP) to fetch the MediaProxy URL.
|
||||
# Redirect following is handled by Tesla middleware, so we must not enable
|
||||
# adapter-level redirect logic (Hackney can crash on relative redirects when proxied).
|
||||
http_client_opts =
|
||||
[:media_proxy, :proxy_opts, :http]
|
||||
|> Pleroma.Config.get(pool: :media)
|
||||
|> Keyword.drop([:follow_redirect, :force_redirect])
|
||||
|
||||
HTTP.get(url, [], http_client_opts)
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -863,6 +863,34 @@ defmodule Pleroma.Web.ActivityPub.Utils do
|
|||
|
||||
def update_report_state(_, _), do: {:error, "Unsupported state"}
|
||||
|
||||
def assign_report_to_account(%Activity{} = activity, nil = _account) do
|
||||
new_data = Map.delete(activity.data, "assigned_account")
|
||||
|
||||
activity
|
||||
|> Changeset.change(data: new_data)
|
||||
|> Repo.update()
|
||||
end
|
||||
|
||||
def assign_report_to_account(%Activity{} = activity, account) do
|
||||
new_data = Map.put(activity.data, "assigned_account", account)
|
||||
|
||||
activity
|
||||
|> Changeset.change(data: new_data)
|
||||
|> Repo.update()
|
||||
end
|
||||
|
||||
def assign_report_to_account(activity_ids, account) do
|
||||
activities_num = length(activity_ids)
|
||||
|
||||
from(a in Activity, where: a.id in ^activity_ids)
|
||||
|> update(set: [data: fragment("jsonb_set(data, '{assigned_account}', ?)", ^account)])
|
||||
|> Repo.update_all([])
|
||||
|> case do
|
||||
{^activities_num, _} -> :ok
|
||||
_ -> {:error, activity_ids}
|
||||
end
|
||||
end
|
||||
|
||||
def strip_report_status_data(%Activity{} = activity) do
|
||||
with {:ok, new_data} <- strip_report_status_data(activity.data) do
|
||||
{:ok, %{activity | data: new_data}}
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ defmodule Pleroma.Web.AdminAPI.ReportController do
|
|||
alias Pleroma.Activity
|
||||
alias Pleroma.ModerationLog
|
||||
alias Pleroma.ReportNote
|
||||
alias Pleroma.User
|
||||
alias Pleroma.Web.ActivityPub.Utils
|
||||
alias Pleroma.Web.AdminAPI
|
||||
alias Pleroma.Web.AdminAPI.Report
|
||||
|
|
@ -24,7 +25,7 @@ defmodule Pleroma.Web.AdminAPI.ReportController do
|
|||
plug(
|
||||
OAuthScopesPlug,
|
||||
%{scopes: ["admin:write:reports"]}
|
||||
when action in [:update, :notes_create, :notes_delete]
|
||||
when action in [:update, :assign_account, :notes_create, :notes_delete]
|
||||
)
|
||||
|
||||
action_fallback(AdminAPI.FallbackController)
|
||||
|
|
@ -79,6 +80,22 @@ defmodule Pleroma.Web.AdminAPI.ReportController do
|
|||
end
|
||||
end
|
||||
|
||||
def assign_account(
|
||||
%{
|
||||
assigns: %{user: admin},
|
||||
private: %{open_api_spex: %{body_params: %{reports: reports}}}
|
||||
} = conn,
|
||||
_
|
||||
) do
|
||||
result = Enum.map(reports, &do_assign_account(&1, admin))
|
||||
|
||||
if Enum.any?(result, &Map.has_key?(&1, :error)) do
|
||||
json_response(conn, :bad_request, result)
|
||||
else
|
||||
json_response(conn, :no_content, "")
|
||||
end
|
||||
end
|
||||
|
||||
def notes_create(
|
||||
%{
|
||||
assigns: %{user: user},
|
||||
|
|
@ -131,4 +148,40 @@ defmodule Pleroma.Web.AdminAPI.ReportController do
|
|||
_ -> json_response(conn, :bad_request, "")
|
||||
end
|
||||
end
|
||||
|
||||
defp do_assign_account(%{assigned_account: nil, id: id}, admin) do
|
||||
with {:ok, activity} <- CommonAPI.assign_report_to_account(id, nil),
|
||||
report <- Activity.get_by_id_with_user_actor(activity.id) do
|
||||
ModerationLog.insert_log(%{
|
||||
action: "report_unassigned",
|
||||
actor: admin,
|
||||
subject: activity,
|
||||
subject_actor: report.user_actor
|
||||
})
|
||||
|
||||
activity
|
||||
else
|
||||
{:error, message} ->
|
||||
%{id: id, error: message}
|
||||
end
|
||||
end
|
||||
|
||||
defp do_assign_account(%{assigned_account: assigned_account, id: id}, admin) do
|
||||
with %User{id: account} = user <- User.get_cached_by_nickname(assigned_account),
|
||||
{:ok, activity} <- CommonAPI.assign_report_to_account(id, account),
|
||||
report <- Activity.get_by_id_with_user_actor(activity.id) do
|
||||
ModerationLog.insert_log(%{
|
||||
action: "report_assigned",
|
||||
actor: admin,
|
||||
subject: activity,
|
||||
subject_actor: report.user_actor,
|
||||
assigned_account: user.nickname
|
||||
})
|
||||
|
||||
activity
|
||||
else
|
||||
{:error, message} ->
|
||||
%{id: id, error: message}
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -13,6 +13,11 @@ defmodule Pleroma.Web.AdminAPI.Report do
|
|||
user = User.get_cached_by_ap_id(actor)
|
||||
account = User.get_cached_by_ap_id(account_ap_id)
|
||||
|
||||
assigned_account =
|
||||
if Map.has_key?(report.data, "assigned_account") do
|
||||
User.get_cached_by_id(report.data["assigned_account"])
|
||||
end
|
||||
|
||||
statuses =
|
||||
status_ap_ids
|
||||
|> Enum.reject(&is_nil(&1))
|
||||
|
|
@ -26,7 +31,13 @@ defmodule Pleroma.Web.AdminAPI.Report do
|
|||
Activity.get_by_ap_id_with_object(act)
|
||||
end)
|
||||
|
||||
%{report: report, user: user, account: account, statuses: statuses}
|
||||
%{
|
||||
report: report,
|
||||
user: user,
|
||||
account: account,
|
||||
statuses: statuses,
|
||||
assigned_account: assigned_account
|
||||
}
|
||||
end
|
||||
|
||||
defp make_fake_activity(act, user) do
|
||||
|
|
|
|||
|
|
@ -26,7 +26,13 @@ defmodule Pleroma.Web.AdminAPI.ReportView do
|
|||
}
|
||||
end
|
||||
|
||||
def render("show.json", %{report: report, user: user, account: account, statuses: statuses}) do
|
||||
def render("show.json", %{
|
||||
report: report,
|
||||
user: user,
|
||||
account: account,
|
||||
statuses: statuses,
|
||||
assigned_account: assigned_account
|
||||
}) do
|
||||
created_at = Utils.to_masto_date(report.data["published"])
|
||||
|
||||
content =
|
||||
|
|
@ -36,6 +42,11 @@ defmodule Pleroma.Web.AdminAPI.ReportView do
|
|||
nil
|
||||
end
|
||||
|
||||
assigned_account =
|
||||
if assigned_account do
|
||||
merge_account_views(assigned_account)
|
||||
end
|
||||
|
||||
%{
|
||||
id: report.id,
|
||||
account: merge_account_views(account),
|
||||
|
|
@ -49,7 +60,8 @@ defmodule Pleroma.Web.AdminAPI.ReportView do
|
|||
}),
|
||||
state: report.data["state"],
|
||||
notes: render(__MODULE__, "index_notes.json", %{notes: report.report_notes}),
|
||||
rules: rules(Map.get(report.data, "rules", nil))
|
||||
rules: rules(Map.get(report.data, "rules", nil)),
|
||||
assigned_account: assigned_account
|
||||
}
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -53,6 +53,12 @@ defmodule Pleroma.Web.ApiSpec.Admin.ReportOperation do
|
|||
:query,
|
||||
%Schema{type: :integer, default: 50},
|
||||
"Number number of log entries per page"
|
||||
),
|
||||
Operation.parameter(
|
||||
:assigned_account,
|
||||
:query,
|
||||
%Schema{type: :string},
|
||||
"Filter by assigned account ID"
|
||||
)
|
||||
| admin_api_params()
|
||||
],
|
||||
|
|
@ -103,6 +109,22 @@ defmodule Pleroma.Web.ApiSpec.Admin.ReportOperation do
|
|||
}
|
||||
end
|
||||
|
||||
def assign_account_operation do
|
||||
%Operation{
|
||||
tags: ["Report management"],
|
||||
summary: "Assign account to specified reports",
|
||||
operationId: "AdminAPI.ReportController.assign_account",
|
||||
security: [%{"oAuth" => ["admin:write:reports"]}],
|
||||
parameters: admin_api_params(),
|
||||
requestBody: request_body("Parameters", assign_account_request(), required: true),
|
||||
responses: %{
|
||||
204 => no_content_response(),
|
||||
400 => Operation.response("Bad Request", "application/json", update_400_response()),
|
||||
403 => Operation.response("Forbidden", "application/json", ApiError)
|
||||
}
|
||||
}
|
||||
end
|
||||
|
||||
def notes_create_operation do
|
||||
%Operation{
|
||||
tags: ["Report management"],
|
||||
|
|
@ -186,7 +208,10 @@ defmodule Pleroma.Web.ApiSpec.Admin.ReportOperation do
|
|||
hint: %Schema{type: :string, nullable: true}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
assigned_account:
|
||||
account_admin()
|
||||
|> Map.put(:nullable, true)
|
||||
}
|
||||
}
|
||||
end
|
||||
|
|
@ -242,6 +267,34 @@ defmodule Pleroma.Web.ApiSpec.Admin.ReportOperation do
|
|||
}
|
||||
end
|
||||
|
||||
defp assign_account_request do
|
||||
%Schema{
|
||||
type: :object,
|
||||
required: [:reports],
|
||||
properties: %{
|
||||
reports: %Schema{
|
||||
type: :array,
|
||||
items: %Schema{
|
||||
type: :object,
|
||||
properties: %{
|
||||
id: %Schema{allOf: [FlakeID], description: "Required, report ID"},
|
||||
assigned_account: %Schema{
|
||||
type: :string,
|
||||
description: "User nickname",
|
||||
nullable: true
|
||||
}
|
||||
}
|
||||
},
|
||||
example: %{
|
||||
"reports" => [
|
||||
%{"id" => "123", "assigned_account" => "pleroma"}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
end
|
||||
|
||||
defp update_400_response do
|
||||
%Schema{
|
||||
type: :array,
|
||||
|
|
|
|||
|
|
@ -342,6 +342,18 @@ defmodule Pleroma.Web.ApiSpec.InstanceOperation do
|
|||
max_pinned_statuses: %Schema{
|
||||
type: :integer,
|
||||
description: "The maximum number of pinned statuses for each account."
|
||||
},
|
||||
max_profile_fields: %Schema{
|
||||
type: :integer,
|
||||
description: "The maximum number of custom profile fields allowed to be set."
|
||||
},
|
||||
profile_field_name_limit: %Schema{
|
||||
type: :integer,
|
||||
description: "The maximum size of a profile field name, in characters."
|
||||
},
|
||||
profile_field_value_limit: %Schema{
|
||||
type: :integer,
|
||||
description: "The maximum size of a profile field value, in characters."
|
||||
}
|
||||
}
|
||||
},
|
||||
|
|
|
|||
|
|
@ -21,6 +21,7 @@ defmodule Pleroma.Web.ApiSpec.Schemas.Account do
|
|||
acct: %Schema{type: :string},
|
||||
avatar_static: %Schema{type: :string, format: :uri},
|
||||
avatar: %Schema{type: :string, format: :uri},
|
||||
avatar_description: %Schema{type: :string},
|
||||
bot: %Schema{type: :boolean},
|
||||
created_at: %Schema{type: :string, format: "date-time"},
|
||||
display_name: %Schema{type: :string},
|
||||
|
|
@ -31,6 +32,7 @@ defmodule Pleroma.Web.ApiSpec.Schemas.Account do
|
|||
following_count: %Schema{type: :integer},
|
||||
header_static: %Schema{type: :string, format: :uri},
|
||||
header: %Schema{type: :string, format: :uri},
|
||||
header_description: %Schema{type: :string},
|
||||
id: FlakeID,
|
||||
locked: %Schema{type: :boolean},
|
||||
note: %Schema{type: :string, format: :html},
|
||||
|
|
@ -111,8 +113,8 @@ defmodule Pleroma.Web.ApiSpec.Schemas.Account do
|
|||
nullable: true,
|
||||
description: "Favicon image of the user's instance"
|
||||
},
|
||||
avatar_description: %Schema{type: :string},
|
||||
header_description: %Schema{type: :string}
|
||||
avatar_description: %Schema{type: :string, deprecated: true},
|
||||
header_description: %Schema{type: :string, deprecated: true}
|
||||
}
|
||||
},
|
||||
source: %Schema{
|
||||
|
|
|
|||
|
|
@ -26,7 +26,9 @@ defmodule Pleroma.Web.ApiSpec.Schemas.AccountRelationship do
|
|||
requested: %Schema{type: :boolean},
|
||||
showing_reblogs: %Schema{type: :boolean},
|
||||
subscribing: %Schema{type: :boolean},
|
||||
notifying: %Schema{type: :boolean}
|
||||
notifying: %Schema{type: :boolean},
|
||||
mute_expires_at: %Schema{type: :string, format: "date-time", nullable: true},
|
||||
block_expires_at: %Schema{type: :string, format: "date-time", nullable: true}
|
||||
},
|
||||
example: %{
|
||||
"blocked_by" => false,
|
||||
|
|
|
|||
|
|
@ -709,6 +709,22 @@ defmodule Pleroma.Web.CommonAPI do
|
|||
end
|
||||
end
|
||||
|
||||
def assign_report_to_account(activity_ids, user) when is_list(activity_ids) do
|
||||
case Utils.assign_report_to_account(activity_ids, user) do
|
||||
:ok -> {:ok, activity_ids}
|
||||
_ -> {:error, dgettext("errors", "Could not assign account")}
|
||||
end
|
||||
end
|
||||
|
||||
def assign_report_to_account(activity_id, user) do
|
||||
with %Activity{} = activity <- Activity.get_by_id(activity_id) do
|
||||
Utils.assign_report_to_account(activity, user)
|
||||
else
|
||||
nil -> {:error, :not_found}
|
||||
_ -> {:error, dgettext("errors", "Could not assign account")}
|
||||
end
|
||||
end
|
||||
|
||||
@spec update_activity_scope(String.t(), map()) :: {:ok, any()} | {:error, any()}
|
||||
def update_activity_scope(activity_id, opts \\ %{}) do
|
||||
with %Activity{} = activity <- Activity.get_by_id_with_object(activity_id),
|
||||
|
|
|
|||
|
|
@ -96,6 +96,24 @@ defmodule Pleroma.Web.MastodonAPI.AccountView do
|
|||
followed_by = FollowingRelationship.following?(target, reading_user)
|
||||
following = FollowingRelationship.following?(reading_user, target)
|
||||
|
||||
blocking =
|
||||
UserRelationship.exists?(
|
||||
user_relationships,
|
||||
:block,
|
||||
reading_user,
|
||||
target,
|
||||
&User.blocks_user?(&1, &2)
|
||||
)
|
||||
|
||||
muting =
|
||||
UserRelationship.exists?(
|
||||
user_relationships,
|
||||
:mute,
|
||||
reading_user,
|
||||
target,
|
||||
&User.mutes?(&1, &2)
|
||||
)
|
||||
|
||||
requested =
|
||||
cond do
|
||||
following -> false
|
||||
|
|
@ -116,14 +134,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountView do
|
|||
id: to_string(target.id),
|
||||
following: following,
|
||||
followed_by: followed_by,
|
||||
blocking:
|
||||
UserRelationship.exists?(
|
||||
user_relationships,
|
||||
:block,
|
||||
reading_user,
|
||||
target,
|
||||
&User.blocks_user?(&1, &2)
|
||||
),
|
||||
blocking: blocking,
|
||||
blocked_by:
|
||||
UserRelationship.exists?(
|
||||
user_relationships,
|
||||
|
|
@ -132,14 +143,8 @@ defmodule Pleroma.Web.MastodonAPI.AccountView do
|
|||
reading_user,
|
||||
&User.blocks_user?(&1, &2)
|
||||
),
|
||||
muting:
|
||||
UserRelationship.exists?(
|
||||
user_relationships,
|
||||
:mute,
|
||||
reading_user,
|
||||
target,
|
||||
&User.mutes?(&1, &2)
|
||||
),
|
||||
block_expires_at: nil,
|
||||
muting: muting,
|
||||
muting_notifications:
|
||||
UserRelationship.exists?(
|
||||
user_relationships,
|
||||
|
|
@ -148,6 +153,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountView do
|
|||
target,
|
||||
&User.muted_notifications?(&1, &2)
|
||||
),
|
||||
mute_expires_at: nil,
|
||||
subscribing: subscribing,
|
||||
notifying: subscribing,
|
||||
requested: requested,
|
||||
|
|
@ -174,6 +180,8 @@ defmodule Pleroma.Web.MastodonAPI.AccountView do
|
|||
&User.endorses?(&1, &2)
|
||||
)
|
||||
}
|
||||
|> maybe_put_mute_expires_at(target, reading_user, %{mutes: muting})
|
||||
|> maybe_put_block_expires_at(target, reading_user, %{blocks: blocking})
|
||||
end
|
||||
|
||||
def render("relationships.json", %{user: user, targets: targets} = opts) do
|
||||
|
|
@ -292,8 +300,10 @@ defmodule Pleroma.Web.MastodonAPI.AccountView do
|
|||
note: user.bio,
|
||||
url: user.uri || user.ap_id,
|
||||
avatar: avatar,
|
||||
avatar_description: avatar_description,
|
||||
avatar_static: avatar_static,
|
||||
header: header,
|
||||
header_description: header_description,
|
||||
header_static: header_static,
|
||||
emojis: emojis,
|
||||
fields: user.fields,
|
||||
|
|
@ -343,8 +353,8 @@ defmodule Pleroma.Web.MastodonAPI.AccountView do
|
|||
|> maybe_put_unread_conversation_count(user, opts[:for])
|
||||
|> maybe_put_unread_notification_count(user, opts[:for])
|
||||
|> maybe_put_email_address(user, opts[:for])
|
||||
|> maybe_put_mute_expires_at(user, opts[:for], opts)
|
||||
|> maybe_put_block_expires_at(user, opts[:for], opts)
|
||||
|> maybe_put_mute_expires_at(user, opts[:for], opts, relationship)
|
||||
|> maybe_put_block_expires_at(user, opts[:for], opts, relationship)
|
||||
|> maybe_show_birthday(user, opts[:for])
|
||||
end
|
||||
|
||||
|
|
@ -472,25 +482,47 @@ defmodule Pleroma.Web.MastodonAPI.AccountView do
|
|||
|
||||
defp maybe_put_email_address(data, _, _), do: data
|
||||
|
||||
defp maybe_put_mute_expires_at(data, %User{} = user, target, %{mutes: true}) do
|
||||
defp maybe_put_mute_expires_at(data, target, user, opts, relationship \\ nil)
|
||||
|
||||
defp maybe_put_mute_expires_at(data, _target, _user, %{mutes: true}, %{
|
||||
mute_expires_at: mute_expires_at
|
||||
}) do
|
||||
Map.put(data, :mute_expires_at, mute_expires_at)
|
||||
end
|
||||
|
||||
defp maybe_put_mute_expires_at(data, %User{} = target, user, %{mutes: true}, _relationship) do
|
||||
Map.put(
|
||||
data,
|
||||
:mute_expires_at,
|
||||
UserRelationship.get_mute_expire_date(target, user)
|
||||
UserRelationship.get_mute_expire_date(user, target)
|
||||
)
|
||||
end
|
||||
|
||||
defp maybe_put_mute_expires_at(data, _, _, _), do: data
|
||||
defp maybe_put_mute_expires_at(data, _, _, _, _), do: data
|
||||
|
||||
defp maybe_put_block_expires_at(data, %User{} = user, target, %{blocks: true}) do
|
||||
defp maybe_put_block_expires_at(data, target, user, opts, relationship \\ nil)
|
||||
|
||||
defp maybe_put_block_expires_at(data, _target, _user, %{blocks: true}, %{
|
||||
block_expires_at: block_expires_at
|
||||
}) do
|
||||
Map.put(data, :block_expires_at, block_expires_at)
|
||||
end
|
||||
|
||||
defp maybe_put_block_expires_at(
|
||||
data,
|
||||
%User{} = target,
|
||||
%User{} = user,
|
||||
%{blocks: true},
|
||||
_relationship
|
||||
) do
|
||||
Map.put(
|
||||
data,
|
||||
:block_expires_at,
|
||||
UserRelationship.get_block_expire_date(target, user)
|
||||
UserRelationship.get_block_expire_date(user, target)
|
||||
)
|
||||
end
|
||||
|
||||
defp maybe_put_block_expires_at(data, _, _, _), do: data
|
||||
defp maybe_put_block_expires_at(data, _, _, _, _), do: data
|
||||
|
||||
defp maybe_show_birthday(data, %User{id: user_id} = user, %User{id: user_id}) do
|
||||
data
|
||||
|
|
|
|||
|
|
@ -303,6 +303,15 @@ defmodule Pleroma.Web.MastodonAPI.InstanceView do
|
|||
defp configuration2 do
|
||||
configuration()
|
||||
|> put_in([:accounts, :max_pinned_statuses], Config.get([:instance, :max_pinned_statuses], 0))
|
||||
|> put_in([:accounts, :max_profile_fields], Config.get([:instance, :max_account_fields]))
|
||||
|> put_in(
|
||||
[:accounts, :profile_field_name_limit],
|
||||
Config.get([:instance, :account_field_name_length])
|
||||
)
|
||||
|> put_in(
|
||||
[:accounts, :profile_field_value_limit],
|
||||
Config.get([:instance, :account_field_value_length])
|
||||
)
|
||||
|> put_in([:statuses, :characters_reserved_per_url], 0)
|
||||
|> Map.merge(%{
|
||||
urls: %{
|
||||
|
|
|
|||
|
|
@ -395,6 +395,7 @@ defmodule Pleroma.Web.Router do
|
|||
get("/reports", ReportController, :index)
|
||||
get("/reports/:id", ReportController, :show)
|
||||
patch("/reports", ReportController, :update)
|
||||
post("/reports/assign_account", ReportController, :assign_account)
|
||||
post("/reports/:id/notes", ReportController, :notes_create)
|
||||
delete("/reports/:report_id/notes/:id", ReportController, :notes_delete)
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue