Merge branch 'admin-report-notification-type' into fork

Signed-off-by: marcin mikołajczak <git@mkljczk.pl>
This commit is contained in:
marcin mikołajczak 2024-09-15 12:10:30 +02:00
commit f01663fe6c
10 changed files with 117 additions and 26 deletions

View file

@ -0,0 +1 @@
Use `admin.report` for report notification type

View file

@ -238,21 +238,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`

View file

@ -70,7 +70,7 @@ def unread_notifications_count(%User{id: user_id}) do
move
pleroma:chat_mention
pleroma:emoji_reaction
pleroma:report
admin.report
reblog
poll
status
@ -445,7 +445,7 @@ defp type_from_activity(%{data: %{"type" => type}} = activity) do
"pleroma:emoji_reaction"
"Flag" ->
"pleroma:report"
"admin.report"
# Compatibility with old reactions
"EmojiReaction" ->

View file

@ -208,7 +208,6 @@ defp notification_type do
"mention",
"pleroma:emoji_reaction",
"pleroma:chat_mention",
"pleroma:report",
"move",
"follow_request",
"poll",
@ -234,7 +233,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
- `pleroma:event_reminder` An event you are participating in or created is taking place soon

View file

@ -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

View file

@ -132,7 +132,7 @@ def render(
"pleroma:chat_mention" ->
put_chat_message(response, activity, reading_user, status_render_opts)
"pleroma:report" ->
"admin.report" ->
put_report(response, activity)
"pleroma:participation_accepted" ->

View file

@ -0,0 +1,101 @@
# Pleroma: A lightweight social networking server
# Copyright © 2017-2024 Pleroma Authors <https://pleroma.social/>
# 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',
'pleroma:participation_accepted'
'pleroma:participation_request'
'pleroma:event_reminder'
'pleroma:event_update'
'bite'
)
"""
|> 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',
'pleroma:participation_accepted'
'pleroma:participation_request'
'pleroma:event_reminder'
'pleroma:event_update'
'bite'
)
"""
|> execute()
"""
alter table notifications
alter column type type notification_type using (type::notification_type)
"""
|> execute()
end
end

View file

@ -49,7 +49,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
@ -65,7 +65,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

View file

@ -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)
@ -105,13 +105,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)
@ -131,7 +131,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
@ -140,7 +140,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

View file

@ -286,7 +286,7 @@ test "Report notification" 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))