feat(safety): report, block and hide, MODULE_API 1.21.0
USER_SAFETY.md step 2 (core), with S11-S14 decided while building it. - Reports: POST /player/reports takes any target type, core's forum types or a module's registered ones. One resolver (model/safety/targets.js) answers "what is this item, for this reader" and 404s an item the reader cannot see. Every report stores content_reports.snapshot; the queue shows a module item from it. - Hide for everyone: POST /admin/moderation/reports/:id/hide hides the item through its own moderation (forum hide as staff, or the module's hide) and actions the report with actioned_with = 'hide'. - Blocks (user_blocks) name an item, never a person, and land on the author's account first (S12); an unlinked game identity is blocked as itself and becomes an account block once linked (S14). Staff cannot be blocked; a block on someone later promoted stops applying (S8). - Hide for me (user_hidden_items), /auth/me/blocks and /auth/me/hidden. - Forum reads filter blocked authors and hidden items on the server and carry canBlock per thread and post. - MODULE_API 1.21.0: api.registerReportTargets, api.registerGameIdentities, ctx.safety.forViewer and ctx.safety.staffAmong, so a module filters its own per-viewer feeds on the server (S11) and marks lines canBlock (S13). - Web: Hide for me / Block author in the forum menus, a Blocked section on both account pages, Hide for everyone in the Reports queue. - Tests, OpenAPI, route/guard/engagement manifests regenerated. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01E14m6SuuY6i1vASFeGDBeY
This commit is contained in:
@@ -17,6 +17,7 @@ const grants = require('../src/model/teams/teamGrants.model')
|
||||
const access = require('../src/model/teams/teamAccess.model')
|
||||
const forum = require('../src/model/teams/teamForum.model')
|
||||
const forumDb = require('../src/model/teams/teamForum.db')
|
||||
const safetyDb = require('../src/model/safety/userSafety.db')
|
||||
const uploads = require('../src/model/teams/teamForumUploads.model')
|
||||
const { cleanForumBody, renderForumBody } = require('../src/utils/forumHtml')
|
||||
|
||||
@@ -599,6 +600,7 @@ test('every post comes back knowing whether THIS reader may edit it', async () =
|
||||
post({ id: 80, author_user_id: 11, created_at: new Date() }),
|
||||
post({ id: 81, author_user_id: 99, author_username: 'someone', created_at: new Date() }),
|
||||
])
|
||||
patch(safetyDb, 'staffAmong', async () => [])
|
||||
|
||||
const mine = await forum.getThread(1, 5, { viewer: { userId: 11, windowMinutes: 15 } })
|
||||
assert.deepEqual(mine.posts.map((p) => p.canEdit), [true, false])
|
||||
@@ -609,3 +611,40 @@ test('every post comes back knowing whether THIS reader may edit it', async () =
|
||||
const anonymous = await forum.getThread(1, 5, {})
|
||||
assert.deepEqual(anonymous.posts.map((p) => p.canEdit), [false, false])
|
||||
})
|
||||
|
||||
// USER_SAFETY.md S8: the menu does not offer what the server would refuse.
|
||||
test('every post says whether this reader may block its author: not yourself, not staff, not a deleted account', async () => {
|
||||
patch(forumDb, 'threadById', async () => discussion())
|
||||
patch(forumDb, 'postsByThread', async () => [
|
||||
post({ id: 80, author_user_id: 11, created_at: new Date() }),
|
||||
post({ id: 81, author_user_id: 99, created_at: new Date() }),
|
||||
post({ id: 82, author_user_id: 2, created_at: new Date() }),
|
||||
post({ id: 83, author_user_id: null, author_username: 'gone', created_at: new Date() }),
|
||||
])
|
||||
patch(safetyDb, 'staffAmong', async (ids) => ids.filter((id) => id === 2))
|
||||
|
||||
const thread = await forum.getThread(1, 5, { viewer: { userId: 11, windowMinutes: 15 } })
|
||||
assert.deepEqual(thread.posts.map((p) => p.canBlock), [false, true, false, false])
|
||||
|
||||
patch(safetyDb, 'staffAmong', async () => { throw new Error('a signed-out read asks nothing') })
|
||||
const anonymous = await forum.getThread(1, 5, {})
|
||||
assert.deepEqual(anonymous.posts.map((p) => p.canBlock), [false, false, false, false])
|
||||
})
|
||||
|
||||
test('a reader’s filter leaves out their hidden posts and their blocked authors’ posts', async () => {
|
||||
patch(forumDb, 'threadById', async () => discussion())
|
||||
patch(forumDb, 'postsByThread', async () => [
|
||||
post({ id: 80, author_user_id: 3, created_at: new Date() }),
|
||||
post({ id: 81, author_user_id: 99, created_at: new Date() }),
|
||||
post({ id: 82, author_user_id: 4, created_at: new Date() }),
|
||||
])
|
||||
patch(safetyDb, 'staffAmong', async () => [])
|
||||
const filter = { blockedUserIds: new Set([99]), hidden: { team_forum_thread: new Set(), team_forum_post: new Set([82]) } }
|
||||
|
||||
const thread = await forum.getThread(1, 5, { viewer: { userId: 11 }, filter })
|
||||
assert.deepEqual(thread.posts.map((p) => p.id), [80])
|
||||
|
||||
// A thread its reader hid is gone from their view, a link to it included.
|
||||
filter.hidden.team_forum_thread.add(5)
|
||||
assert.equal(await forum.getThread(1, 5, { viewer: { userId: 11 }, filter }), null)
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user