Use admin.report
for report notification type
Signed-off-by: marcin mikołajczak <git@mkljczk.pl>
This commit is contained in:
parent
360dd34f19
commit
455e3dea2e
10 changed files with 108 additions and 26 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
|
|
@ -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`
|
||||
|
||||
|
|
|
@ -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" ->
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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"] ->
|
||||
|
|
|
@ -0,0 +1,91 @@
|
|||
# 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'
|
||||
)
|
||||
"""
|
||||
|> 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
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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))
|
||||
|
|
Loading…
Reference in a new issue