forgejo/models/user/moderation_test.go
floss4good d87e2e7e40 feat: Admin interface for abuse reports (#7905)
- Implementation of milestone 5. from **Task F. Moderation features: Reporting** (part of [amendment of the workplan](https://codeberg.org/forgejo/sustainability/src/branch/main/2022-12-01-nlnet/2025-02-07-extended-workplan.md#task-f-moderation-features-reporting) for NLnet 2022-12-035):
  `5. Forgejo admins can see a list of reports`
  There is a lot of room for improvements, but it was decided to start with a basic version so that feedback can be collected from real-life usages (based on which the UI might change a lot).
- Also covers milestone 2. from same **Task F. Moderation features: Reporting**:
  `2. Reports from multiple users are combined in the database and don't create additional reports.`
  But instead of combining the reports when stored, they are grouped when retrieved (it was concluded _that it might be preferable to take care of the deduplication while implementing the admin interface_; see https://codeberg.org/forgejo/forgejo/pulls/7939#issuecomment-4841754 for more details).

---

Follow-up of !6977

### See also:
- forgejo/design#30

---

This adds a new _Moderation reports_ section (/admin/moderation/reports) within the _Site administration_ page, where administrators can see an overview with the submitted abuse reports that are still open (not yet handled in any way). When multiple reports exist for the same content (submitted by distinct users) only the first one will be shown in the list and a counter can be seen on the right side (indicating the number of open reports for the same content type and ID). Clicking on the counter or the icon from the right side will open the details page where a list with all the reports (when multiple) linked to the reported content is available, as well as any shadow copy saved for the current report(s).
The new section is available only when moderation in enabled ([moderation] ENABLED config is set as true within app.ini).

Discussions regarding the UI/UX started with https://codeberg.org/forgejo/design/issues/30#issuecomment-2908849

Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/7905
Reviewed-by: Otto <otto@codeberg.org>
Reviewed-by: jerger <jerger@noreply.codeberg.org>
Co-authored-by: floss4good <floss4good@disroot.org>
Co-committed-by: floss4good <floss4good@disroot.org>
2025-07-23 00:20:15 +02:00

60 lines
2.3 KiB
Go

// Copyright 2025 The Forgejo Authors. All rights reserved.
// SPDX-License-Identifier: GPL-3.0-or-later
package user_test
import (
"testing"
"forgejo.org/models/moderation"
"forgejo.org/models/user"
"forgejo.org/modules/timeutil"
"github.com/stretchr/testify/assert"
)
const (
tsCreated timeutil.TimeStamp = timeutil.TimeStamp(1753093200) // 2025-07-21 10:20:00 UTC
tsUpdated timeutil.TimeStamp = timeutil.TimeStamp(1753093320) // 2025-07-21 10:22:00 UTC
tsLastLogin timeutil.TimeStamp = timeutil.TimeStamp(1753093800) // 2025-07-21 10:30:00 UTC
)
func testShadowCopyField(t *testing.T, scField moderation.ShadowCopyField, key, value string) {
assert.Equal(t, key, scField.Key)
assert.Equal(t, value, scField.Value)
}
func TestUserDataGetFieldsMap(t *testing.T) {
ud := user.UserData{
Name: "alexsmith",
FullName: "Alex Smith",
Email: "alexsmith@example.org",
LoginName: "",
Location: "@master@seo.net",
Website: "http://promote-your-business.biz",
Pronouns: "SEO",
Description: "I can help you promote your business online using SEO.",
CreatedUnix: tsCreated,
UpdatedUnix: tsUpdated,
LastLogin: tsLastLogin,
Avatar: "avatar-hash-user-1002",
AvatarEmail: "alexsmith@example.org",
}
scFields := ud.GetFieldsMap()
if assert.Len(t, scFields, 13) {
testShadowCopyField(t, scFields[0], "Name", "alexsmith")
testShadowCopyField(t, scFields[1], "FullName", "Alex Smith")
testShadowCopyField(t, scFields[2], "Email", "alexsmith@example.org")
testShadowCopyField(t, scFields[3], "LoginName", "")
testShadowCopyField(t, scFields[4], "Location", "@master@seo.net")
testShadowCopyField(t, scFields[5], "Website", "http://promote-your-business.biz")
testShadowCopyField(t, scFields[6], "Pronouns", "SEO")
testShadowCopyField(t, scFields[7], "Description", "I can help you promote your business online using SEO.")
testShadowCopyField(t, scFields[8], "CreatedUnix", tsCreated.AsLocalTime().String())
testShadowCopyField(t, scFields[9], "UpdatedUnix", tsUpdated.AsLocalTime().String())
testShadowCopyField(t, scFields[10], "LastLogin", tsLastLogin.AsLocalTime().String())
testShadowCopyField(t, scFields[11], "Avatar", "avatar-hash-user-1002")
testShadowCopyField(t, scFields[12], "AvatarEmail", "alexsmith@example.org")
}
}