mirror of
https://git.pleroma.social/pleroma/pleroma.git
synced 2025-04-08 12:04:10 +00:00
Merge branch 'admin-report-notification-type' into 'develop'
Draft: Use `admin.report` for report notification type See merge request pleroma/pleroma!4261
This commit is contained in:
commit
f32a5f2066
8 changed files with 43 additions and 18 deletions
1
changelog.d/admin-report-notification-type.change
Normal file
1
changelog.d/admin-report-notification-type.change
Normal file
|
@ -0,0 +1 @@
|
|||
Use `admin.report` for report notification type
|
|
@ -184,21 +184,12 @@ The `type` value is `pleroma:chat_mention`
|
|||
- `account`: The account who sent the message
|
||||
- `chat_message`: The chat message
|
||||
|
||||
### Report Notification (not default)
|
||||
|
||||
This notification has to be requested explicitly.
|
||||
|
||||
The `type` value is `pleroma:report`
|
||||
|
||||
- `account`: The account who reported
|
||||
- `report`: The report
|
||||
|
||||
## GET `/api/v1/notifications`
|
||||
|
||||
Accepts additional parameters:
|
||||
|
||||
- `exclude_visibilities`: will exclude the notifications for activities with the given visibilities. The parameter accepts an array of visibility types (`public`, `unlisted`, `private`, `direct`). Usage example: `GET /api/v1/notifications?exclude_visibilities[]=direct&exclude_visibilities[]=private`.
|
||||
- `include_types`: will include the notifications for activities with the given types. The parameter accepts an array of types (`mention`, `follow`, `reblog`, `favourite`, `move`, `pleroma:emoji_reaction`, `pleroma:chat_mention`, `pleroma:report`). Usage example: `GET /api/v1/notifications?include_types[]=mention&include_types[]=reblog`.
|
||||
- `include_types`: will include the notifications for activities with the given types. The parameter accepts an array of types (`mention`, `follow`, `reblog`, `favourite`, `move`, `pleroma:emoji_reaction`, `pleroma:chat_mention`, `admin.report`). Usage example: `GET /api/v1/notifications?include_types[]=mention&include_types[]=reblog`.
|
||||
|
||||
## DELETE `/api/v1/notifications/destroy_multiple`
|
||||
|
||||
|
|
|
@ -74,6 +74,7 @@ defmodule Pleroma.Notification do
|
|||
reblog
|
||||
poll
|
||||
status
|
||||
update
|
||||
}
|
||||
|
||||
def changeset(%Notification{} = notification, attrs) do
|
||||
|
|
|
@ -224,7 +224,6 @@ defmodule Pleroma.Web.ApiSpec.NotificationOperation do
|
|||
- `move` - Someone moved their account
|
||||
- `pleroma:emoji_reaction` - Someone reacted with emoji to your status
|
||||
- `pleroma:chat_mention` - Someone mentioned you in a chat message
|
||||
- `pleroma:report` - Someone was reported
|
||||
- `status` - Someone you are subscribed to created a status
|
||||
- `update` - A status you boosted has been edited
|
||||
- `admin.sign_up` - Someone signed up (optionally sent to admins)
|
||||
|
|
|
@ -62,11 +62,17 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPI do
|
|||
|
||||
def get_notifications(user, params \\ %{}) do
|
||||
options =
|
||||
cast_params(params) |> Map.update(:include_types, [], fn include_types -> include_types end)
|
||||
cast_params(params)
|
||||
|> Map.update(:include_types, [], fn include_types ->
|
||||
if "admin.report" in include_types do
|
||||
include_types ++ ["pleroma:report"]
|
||||
else
|
||||
include_types
|
||||
end
|
||||
end)
|
||||
|
||||
options =
|
||||
if ("pleroma:report" not in options.include_types and
|
||||
User.privileged?(user, :reports_manage_reports)) or
|
||||
if "pleroma:report" not in options.include_types or
|
||||
User.privileged?(user, :reports_manage_reports) do
|
||||
options
|
||||
else
|
||||
|
|
|
@ -96,7 +96,7 @@ defmodule Pleroma.Web.MastodonAPI.NotificationView do
|
|||
response = %{
|
||||
id: to_string(notification.id),
|
||||
group_key: "ungrouped-" <> to_string(notification.id),
|
||||
type: notification.type,
|
||||
type: get_notification_type(notification),
|
||||
created_at: CommonAPI.Utils.to_masto_date(notification.inserted_at),
|
||||
account: account,
|
||||
pleroma: %{
|
||||
|
@ -143,6 +143,10 @@ defmodule Pleroma.Web.MastodonAPI.NotificationView do
|
|||
end
|
||||
end
|
||||
|
||||
defp get_notification_type(%Notification{type: "pleroma:report"}), do: "admin.report"
|
||||
|
||||
defp get_notification_type(%Notification{type: type}), do: type
|
||||
|
||||
defp put_report(response, activity) do
|
||||
report_render = ReportView.render("show.json", Report.extract_report_info(activity))
|
||||
|
||||
|
|
|
@ -78,7 +78,7 @@ defmodule Pleroma.Web.MastodonAPI.NotificationControllerTest do
|
|||
assert [_] = result
|
||||
end
|
||||
|
||||
test "by default, does not contain pleroma:report" do
|
||||
test "by default, does not contain admin.report" do
|
||||
clear_config([:instance, :moderator_privileges], [:reports_manage_reports])
|
||||
|
||||
user = insert(:user)
|
||||
|
@ -101,6 +101,22 @@ defmodule Pleroma.Web.MastodonAPI.NotificationControllerTest do
|
|||
|
||||
assert [] == result
|
||||
|
||||
result =
|
||||
conn
|
||||
|> get("/api/v1/notifications?include_types[]=admin.report")
|
||||
|> json_response_and_validate_schema(200)
|
||||
|
||||
assert [_] = result
|
||||
end
|
||||
|
||||
test "fallback from pleroma:report works" do
|
||||
clear_config([:instance, :moderator_privileges], [:reports_manage_reports])
|
||||
|
||||
user = insert(:user)
|
||||
{:ok, user} = user |> User.admin_api_update(%{is_moderator: true})
|
||||
%{conn: conn} = oauth_access(["read:notifications"], user: user)
|
||||
{:ok, _report} = CommonAPI.report(user, %{account_id: user.id})
|
||||
|
||||
result =
|
||||
conn
|
||||
|> get("/api/v1/notifications?include_types[]=pleroma:report")
|
||||
|
@ -109,7 +125,7 @@ defmodule Pleroma.Web.MastodonAPI.NotificationControllerTest do
|
|||
assert [_] = result
|
||||
end
|
||||
|
||||
test "Pleroma:report is hidden for non-privileged users" do
|
||||
test "Admin.report is hidden for non-privileged users" do
|
||||
clear_config([:instance, :moderator_privileges], [:reports_manage_reports])
|
||||
|
||||
user = insert(:user)
|
||||
|
@ -140,6 +156,13 @@ defmodule Pleroma.Web.MastodonAPI.NotificationControllerTest do
|
|||
|> json_response_and_validate_schema(200)
|
||||
|
||||
assert [] == result
|
||||
|
||||
result =
|
||||
conn
|
||||
|> get("/api/v1/notifications?include_types[]=admin.report")
|
||||
|> json_response_and_validate_schema(200)
|
||||
|
||||
assert [] == result
|
||||
end
|
||||
|
||||
test "excludes mentions from blockers when blockers_visible is false" do
|
||||
|
|
|
@ -285,7 +285,7 @@ defmodule Pleroma.Web.MastodonAPI.NotificationViewTest do
|
|||
id: to_string(notification.id),
|
||||
group_key: "ungrouped-#{to_string(notification.id)}",
|
||||
pleroma: %{is_seen: false, is_muted: false},
|
||||
type: "pleroma:report",
|
||||
type: "admin.report",
|
||||
account: AccountView.render("show.json", %{user: reporting_user, for: moderator_user}),
|
||||
created_at: Utils.to_masto_date(notification.inserted_at),
|
||||
report: ReportView.render("show.json", Report.extract_report_info(activity))
|
||||
|
|
Loading…
Reference in a new issue