summaryrefslogtreecommitdiff
path: root/packages/backend/src
diff options
context:
space:
mode:
authorHazelnoot <acomputerdog@gmail.com>2025-01-28 11:39:41 -0500
committerHazelnoot <acomputerdog@gmail.com>2025-02-16 19:20:41 -0500
commit568d82a9746d3d67a756b13fc007beb057dcc011 (patch)
treec1403f38bebcd931952b3fc712a2ffd66b54b62c /packages/backend/src
parentfix TypeScript errors in modlog.MogLog.vue (diff)
downloadsharkey-568d82a9746d3d67a756b13fc007beb057dcc011.tar.gz
sharkey-568d82a9746d3d67a756b13fc007beb057dcc011.tar.bz2
sharkey-568d82a9746d3d67a756b13fc007beb057dcc011.zip
record ModLog entry when setting a user's content warning
Diffstat (limited to 'packages/backend/src')
-rw-r--r--packages/backend/src/server/api/endpoints/admin/cw-user.ts26
-rw-r--r--packages/backend/src/types.ts8
2 files changed, 28 insertions, 6 deletions
diff --git a/packages/backend/src/server/api/endpoints/admin/cw-user.ts b/packages/backend/src/server/api/endpoints/admin/cw-user.ts
index d48ca565a4..bdcfa6a0d9 100644
--- a/packages/backend/src/server/api/endpoints/admin/cw-user.ts
+++ b/packages/backend/src/server/api/endpoints/admin/cw-user.ts
@@ -9,6 +9,7 @@ import type { UsersRepository } from '@/models/_.js';
import { DI } from '@/di-symbols.js';
import { CacheService } from '@/core/CacheService.js';
import { GlobalEventService } from '@/core/GlobalEventService.js';
+import { ModerationLogService } from '@/core/ModerationLogService.js';
export const meta = {
tags: ['admin'],
@@ -34,18 +35,31 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
private readonly usersRepository: UsersRepository,
private readonly globalEventService: GlobalEventService,
+ private readonly cacheService: CacheService,
+ private readonly moderationLogService: ModerationLogService,
) {
- super(meta, paramDef, async ps => {
- const result = await this.usersRepository.update(ps.userId, {
+ super(meta, paramDef, async (ps, me) => {
+ const user = await this.cacheService.findUserById(ps.userId);
+
+ // Skip if there's nothing to do
+ if (user.mandatoryCW === ps.cw) return;
+
+ // Log event first.
+ // This ensures that we don't "lose" the log if an error occurs
+ await this.moderationLogService.log(me, 'setMandatoryCW', {
+ newCW: ps.cw,
+ oldCW: user.mandatoryCW,
+ userId: user.id,
+ userUsername: user.username,
+ userHost: user.host,
+ });
+
+ await this.usersRepository.update(ps.userId, {
// Collapse empty strings to null
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
mandatoryCW: ps.cw || null,
});
- if (result.affected && result.affected < 1) {
- throw new Error('No such user');
- }
-
// Synchronize caches and other processes
this.globalEventService.publishInternalEvent('localUserUpdated', { id: ps.userId });
});
diff --git a/packages/backend/src/types.ts b/packages/backend/src/types.ts
index 067481d9da..b359fa5a39 100644
--- a/packages/backend/src/types.ts
+++ b/packages/backend/src/types.ts
@@ -100,6 +100,7 @@ export const moderationLogTypes = [
'deleteGlobalAnnouncement',
'deleteUserAnnouncement',
'resetPassword',
+ 'setMandatoryCW',
'setRemoteInstanceNSFW',
'unsetRemoteInstanceNSFW',
'suspendRemoteInstance',
@@ -261,6 +262,13 @@ export type ModerationLogPayloads = {
userUsername: string;
userHost: string | null;
};
+ setMandatoryCW: {
+ newCW: string | null;
+ oldCW: string | null;
+ userId: string;
+ userUsername: string;
+ userHost: string | null;
+ };
setRemoteInstanceNSFW: {
id: string;
host: string;