From 455e3dea2e57ef0b28ac685ff6600b3d0c89c064 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?marcin=20miko=C5=82ajczak?= Date: Thu, 12 Sep 2024 14:24:13 +0200 Subject: [PATCH] Use `admin.report` for report notification type MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: marcin mikołajczak --- .../admin-report-notification-type.change | 1 + .../API/differences_in_mastoapi_responses.md | 11 +-- lib/pleroma/notification.ex | 5 +- .../operations/notification_operation.ex | 2 - lib/pleroma/web/mastodon_api/mastodon_api.ex | 6 +- .../mastodon_api/views/notification_view.ex | 2 +- ...port_notification_type_to_admin_report.exs | 91 +++++++++++++++++++ test/pleroma/notification_test.exs | 4 +- .../notification_controller_test.exs | 10 +- .../views/notification_view_test.exs | 2 +- 10 files changed, 108 insertions(+), 26 deletions(-) create mode 100644 changelog.d/admin-report-notification-type.change create mode 100644 priv/repo/migrations/20240912000000_rename_pleroma_report_notification_type_to_admin_report.exs diff --git a/changelog.d/admin-report-notification-type.change b/changelog.d/admin-report-notification-type.change new file mode 100644 index 0000000000..6899a131fd --- /dev/null +++ b/changelog.d/admin-report-notification-type.change @@ -0,0 +1 @@ +Use `admin.report` for report notification type \ No newline at end of file diff --git a/docs/development/API/differences_in_mastoapi_responses.md b/docs/development/API/differences_in_mastoapi_responses.md index 41464e8021..dfe7b5bf63 100644 --- a/docs/development/API/differences_in_mastoapi_responses.md +++ b/docs/development/API/differences_in_mastoapi_responses.md @@ -181,21 +181,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` diff --git a/lib/pleroma/notification.ex b/lib/pleroma/notification.ex index 75f4ba5033..3b5b6fb947 100644 --- a/lib/pleroma/notification.ex +++ b/lib/pleroma/notification.ex @@ -70,10 +70,11 @@ def unread_notifications_count(%User{id: user_id}) do move pleroma:chat_mention pleroma:emoji_reaction - pleroma:report + admin.report reblog poll status + update } def changeset(%Notification{} = notification, attrs) do @@ -412,7 +413,7 @@ defp type_from_activity(%{data: %{"type" => type}} = activity) do "pleroma:emoji_reaction" "Flag" -> - "pleroma:report" + "admin.report" # Compatibility with old reactions "EmojiReaction" -> diff --git a/lib/pleroma/web/api_spec/operations/notification_operation.ex b/lib/pleroma/web/api_spec/operations/notification_operation.ex index 2dc0f66df5..f5fc85e9ca 100644 --- a/lib/pleroma/web/api_spec/operations/notification_operation.ex +++ b/lib/pleroma/web/api_spec/operations/notification_operation.ex @@ -199,7 +199,6 @@ defp notification_type do "mention", "pleroma:emoji_reaction", "pleroma:chat_mention", - "pleroma:report", "move", "follow_request", "poll", @@ -219,7 +218,6 @@ defp notification_type 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) diff --git a/lib/pleroma/web/mastodon_api/mastodon_api.ex b/lib/pleroma/web/mastodon_api/mastodon_api.ex index c9e045d238..9e049fcdcd 100644 --- a/lib/pleroma/web/mastodon_api/mastodon_api.ex +++ b/lib/pleroma/web/mastodon_api/mastodon_api.ex @@ -65,14 +65,14 @@ def get_notifications(user, params \\ %{}) do cast_params(params) |> Map.update(:include_types, [], fn include_types -> include_types end) options = - if ("pleroma:report" not in options.include_types and + if ("admin.report" not in options.include_types and User.privileged?(user, :reports_manage_reports)) or User.privileged?(user, :reports_manage_reports) do options else options - |> Map.update(:exclude_types, ["pleroma:report"], fn current_exclude_types -> - current_exclude_types ++ ["pleroma:report"] + |> Map.update(:exclude_types, ["admin.report"], fn current_exclude_types -> + current_exclude_types ++ ["admin.report"] end) end diff --git a/lib/pleroma/web/mastodon_api/views/notification_view.ex b/lib/pleroma/web/mastodon_api/views/notification_view.ex index 3f24787192..bfb8020282 100644 --- a/lib/pleroma/web/mastodon_api/views/notification_view.ex +++ b/lib/pleroma/web/mastodon_api/views/notification_view.ex @@ -134,7 +134,7 @@ def render( "pleroma:chat_mention" -> put_chat_message(response, activity, reading_user, status_render_opts) - "pleroma:report" -> + "admin.report" -> put_report(response, activity) type when type in ["follow", "follow_request"] -> diff --git a/priv/repo/migrations/20240912000000_rename_pleroma_report_notification_type_to_admin_report.exs b/priv/repo/migrations/20240912000000_rename_pleroma_report_notification_type_to_admin_report.exs new file mode 100644 index 0000000000..df9f6343a5 --- /dev/null +++ b/priv/repo/migrations/20240912000000_rename_pleroma_report_notification_type_to_admin_report.exs @@ -0,0 +1,91 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2024 Pleroma Authors +# SPDX-License-Identifier: AGPL-3.0-only + +defmodule Pleroma.Repo.Migrations.RenamePleromaReportNotificationTypeToAdminReport do + use Ecto.Migration + + def up do + alter table(:notifications) do + modify(:type, :string) + end + + """ + update notifications + set type = 'admin.report' + where type = 'pleroma:report' + """ + |> execute() + + """ + drop type if exists notification_type + """ + |> execute() + + """ + create type notification_type as enum ( + 'follow', + 'follow_request', + 'mention', + 'move', + 'pleroma:emoji_reaction', + 'pleroma:chat_mention', + 'reblog', + 'favourite', + 'admin.report', + 'poll', + 'status', + 'update' + ) + """ + |> execute() + + """ + alter table notifications + alter column type type notification_type using (type::notification_type) + """ + |> execute() + end + + def down do + alter table(:notifications) do + modify(:type, :string) + end + + """ + update notifications + set type = 'pleroma:report' + where type = 'admin.report' + """ + |> execute() + + """ + drop type if exists notification_type + """ + |> execute() + + """ + create type notification_type as enum ( + 'follow', + 'follow_request', + 'mention', + 'move', + 'pleroma:emoji_reaction', + 'pleroma:chat_mention', + 'reblog', + 'favourite', + 'pleroma:report', + 'poll', + 'status', + 'update' + ) + """ + |> execute() + + """ + alter table notifications + alter column type type notification_type using (type::notification_type) + """ + |> execute() + end +end diff --git a/test/pleroma/notification_test.exs b/test/pleroma/notification_test.exs index e595c5c532..c2cfd3dc0f 100644 --- a/test/pleroma/notification_test.exs +++ b/test/pleroma/notification_test.exs @@ -48,7 +48,7 @@ test "creates a report notification only for privileged users" do {:ok, [notification]} = Notification.create_notifications(activity2) assert notification.user_id == moderator_user.id - assert notification.type == "pleroma:report" + assert notification.type == "admin.report" end test "suppresses notifications for own reports" do @@ -64,7 +64,7 @@ test "suppresses notifications for own reports" do refute notification.user_id == reporting_admin.id assert notification.user_id == other_admin.id - assert notification.type == "pleroma:report" + assert notification.type == "admin.report" end test "creates a notification for an emoji reaction" do diff --git a/test/pleroma/web/mastodon_api/controllers/notification_controller_test.exs b/test/pleroma/web/mastodon_api/controllers/notification_controller_test.exs index 8fc22dde14..29eddddb1d 100644 --- a/test/pleroma/web/mastodon_api/controllers/notification_controller_test.exs +++ b/test/pleroma/web/mastodon_api/controllers/notification_controller_test.exs @@ -78,7 +78,7 @@ test "by default, does not contain pleroma:chat_mention" 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) @@ -103,13 +103,13 @@ test "by default, does not contain pleroma:report" do result = conn - |> get("/api/v1/notifications?include_types[]=pleroma:report") + |> get("/api/v1/notifications?include_types[]=admin.report") |> json_response_and_validate_schema(200) 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) @@ -127,7 +127,7 @@ test "Pleroma:report is hidden for non-privileged users" do result = conn - |> get("/api/v1/notifications?include_types[]=pleroma:report") + |> get("/api/v1/notifications?include_types[]=admin.report") |> json_response_and_validate_schema(200) assert [_] = result @@ -136,7 +136,7 @@ test "Pleroma:report is hidden for non-privileged users" do result = conn - |> get("/api/v1/notifications?include_types[]=pleroma:report") + |> get("/api/v1/notifications?include_types[]=admin.report") |> json_response_and_validate_schema(200) assert [] == result diff --git a/test/pleroma/web/mastodon_api/views/notification_view_test.exs b/test/pleroma/web/mastodon_api/views/notification_view_test.exs index 75ab375aae..1439f1c350 100644 --- a/test/pleroma/web/mastodon_api/views/notification_view_test.exs +++ b/test/pleroma/web/mastodon_api/views/notification_view_test.exs @@ -275,7 +275,7 @@ test "Report notification" do expected = %{ id: 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))