Merge branch 'admin-report-notification-type' into fork
Signed-off-by: marcin mikołajczak <git@mkljczk.pl>
This commit is contained in:
commit
f01663fe6c
10 changed files with 117 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
|
|
@ -238,21 +238,12 @@ The `type` value is `pleroma:chat_mention`
|
||||||
- `account`: The account who sent the message
|
- `account`: The account who sent the message
|
||||||
- `chat_message`: The chat 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`
|
## GET `/api/v1/notifications`
|
||||||
|
|
||||||
Accepts additional parameters:
|
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`.
|
- `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`
|
## DELETE `/api/v1/notifications/destroy_multiple`
|
||||||
|
|
||||||
|
|
|
@ -70,7 +70,7 @@ def unread_notifications_count(%User{id: user_id}) do
|
||||||
move
|
move
|
||||||
pleroma:chat_mention
|
pleroma:chat_mention
|
||||||
pleroma:emoji_reaction
|
pleroma:emoji_reaction
|
||||||
pleroma:report
|
admin.report
|
||||||
reblog
|
reblog
|
||||||
poll
|
poll
|
||||||
status
|
status
|
||||||
|
@ -445,7 +445,7 @@ defp type_from_activity(%{data: %{"type" => type}} = activity) do
|
||||||
"pleroma:emoji_reaction"
|
"pleroma:emoji_reaction"
|
||||||
|
|
||||||
"Flag" ->
|
"Flag" ->
|
||||||
"pleroma:report"
|
"admin.report"
|
||||||
|
|
||||||
# Compatibility with old reactions
|
# Compatibility with old reactions
|
||||||
"EmojiReaction" ->
|
"EmojiReaction" ->
|
||||||
|
|
|
@ -208,7 +208,6 @@ defp notification_type do
|
||||||
"mention",
|
"mention",
|
||||||
"pleroma:emoji_reaction",
|
"pleroma:emoji_reaction",
|
||||||
"pleroma:chat_mention",
|
"pleroma:chat_mention",
|
||||||
"pleroma:report",
|
|
||||||
"move",
|
"move",
|
||||||
"follow_request",
|
"follow_request",
|
||||||
"poll",
|
"poll",
|
||||||
|
@ -234,7 +233,6 @@ defp notification_type do
|
||||||
- `move` - Someone moved their account
|
- `move` - Someone moved their account
|
||||||
- `pleroma:emoji_reaction` - Someone reacted with emoji to your status
|
- `pleroma:emoji_reaction` - Someone reacted with emoji to your status
|
||||||
- `pleroma:chat_mention` - Someone mentioned you in a chat message
|
- `pleroma:chat_mention` - Someone mentioned you in a chat message
|
||||||
- `pleroma:report` - Someone was reported
|
|
||||||
- `status` - Someone you are subscribed to created a status
|
- `status` - Someone you are subscribed to created a status
|
||||||
- `update` - A status you boosted has been edited
|
- `update` - A status you boosted has been edited
|
||||||
- `pleroma:event_reminder` – An event you are participating in or created is taking place soon
|
- `pleroma:event_reminder` – An event you are participating in or created is taking place soon
|
||||||
|
|
|
@ -65,14 +65,14 @@ def get_notifications(user, params \\ %{}) do
|
||||||
cast_params(params) |> Map.update(:include_types, [], fn include_types -> include_types end)
|
cast_params(params) |> Map.update(:include_types, [], fn include_types -> include_types end)
|
||||||
|
|
||||||
options =
|
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)) or
|
||||||
User.privileged?(user, :reports_manage_reports) do
|
User.privileged?(user, :reports_manage_reports) do
|
||||||
options
|
options
|
||||||
else
|
else
|
||||||
options
|
options
|
||||||
|> Map.update(:exclude_types, ["pleroma:report"], fn current_exclude_types ->
|
|> Map.update(:exclude_types, ["admin.report"], fn current_exclude_types ->
|
||||||
current_exclude_types ++ ["pleroma:report"]
|
current_exclude_types ++ ["admin.report"]
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -132,7 +132,7 @@ def render(
|
||||||
"pleroma:chat_mention" ->
|
"pleroma:chat_mention" ->
|
||||||
put_chat_message(response, activity, reading_user, status_render_opts)
|
put_chat_message(response, activity, reading_user, status_render_opts)
|
||||||
|
|
||||||
"pleroma:report" ->
|
"admin.report" ->
|
||||||
put_report(response, activity)
|
put_report(response, activity)
|
||||||
|
|
||||||
"pleroma:participation_accepted" ->
|
"pleroma:participation_accepted" ->
|
||||||
|
|
|
@ -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
|
|
@ -49,7 +49,7 @@ test "creates a report notification only for privileged users" do
|
||||||
{:ok, [notification]} = Notification.create_notifications(activity2)
|
{:ok, [notification]} = Notification.create_notifications(activity2)
|
||||||
|
|
||||||
assert notification.user_id == moderator_user.id
|
assert notification.user_id == moderator_user.id
|
||||||
assert notification.type == "pleroma:report"
|
assert notification.type == "admin.report"
|
||||||
end
|
end
|
||||||
|
|
||||||
test "suppresses notifications for own reports" do
|
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
|
refute notification.user_id == reporting_admin.id
|
||||||
assert notification.user_id == other_admin.id
|
assert notification.user_id == other_admin.id
|
||||||
assert notification.type == "pleroma:report"
|
assert notification.type == "admin.report"
|
||||||
end
|
end
|
||||||
|
|
||||||
test "creates a notification for an emoji reaction" do
|
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
|
assert [_] = result
|
||||||
end
|
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])
|
clear_config([:instance, :moderator_privileges], [:reports_manage_reports])
|
||||||
|
|
||||||
user = insert(:user)
|
user = insert(:user)
|
||||||
|
@ -105,13 +105,13 @@ test "by default, does not contain pleroma:report" do
|
||||||
|
|
||||||
result =
|
result =
|
||||||
conn
|
conn
|
||||||
|> get("/api/v1/notifications?include_types[]=pleroma:report")
|
|> get("/api/v1/notifications?include_types[]=admin.report")
|
||||||
|> json_response_and_validate_schema(200)
|
|> json_response_and_validate_schema(200)
|
||||||
|
|
||||||
assert [_] = result
|
assert [_] = result
|
||||||
end
|
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])
|
clear_config([:instance, :moderator_privileges], [:reports_manage_reports])
|
||||||
|
|
||||||
user = insert(:user)
|
user = insert(:user)
|
||||||
|
@ -131,7 +131,7 @@ test "Pleroma:report is hidden for non-privileged users" do
|
||||||
|
|
||||||
result =
|
result =
|
||||||
conn
|
conn
|
||||||
|> get("/api/v1/notifications?include_types[]=pleroma:report")
|
|> get("/api/v1/notifications?include_types[]=admin.report")
|
||||||
|> json_response_and_validate_schema(200)
|
|> json_response_and_validate_schema(200)
|
||||||
|
|
||||||
assert [_] = result
|
assert [_] = result
|
||||||
|
@ -140,7 +140,7 @@ test "Pleroma:report is hidden for non-privileged users" do
|
||||||
|
|
||||||
result =
|
result =
|
||||||
conn
|
conn
|
||||||
|> get("/api/v1/notifications?include_types[]=pleroma:report")
|
|> get("/api/v1/notifications?include_types[]=admin.report")
|
||||||
|> json_response_and_validate_schema(200)
|
|> json_response_and_validate_schema(200)
|
||||||
|
|
||||||
assert [] == result
|
assert [] == result
|
||||||
|
|
|
@ -286,7 +286,7 @@ test "Report notification" do
|
||||||
id: to_string(notification.id),
|
id: to_string(notification.id),
|
||||||
group_key: "ungrouped-#{to_string(notification.id)}",
|
group_key: "ungrouped-#{to_string(notification.id)}",
|
||||||
pleroma: %{is_seen: false, is_muted: false},
|
pleroma: %{is_seen: false, is_muted: false},
|
||||||
type: "pleroma:report",
|
type: "admin.report",
|
||||||
account: AccountView.render("show.json", %{user: reporting_user, for: moderator_user}),
|
account: AccountView.render("show.json", %{user: reporting_user, for: moderator_user}),
|
||||||
created_at: Utils.to_masto_date(notification.inserted_at),
|
created_at: Utils.to_masto_date(notification.inserted_at),
|
||||||
report: ReportView.render("show.json", Report.extract_report_info(activity))
|
report: ReportView.render("show.json", Report.extract_report_info(activity))
|
||||||
|
|
Loading…
Reference in a new issue