improve moderation log
This commit is contained in:
parent
2ad3b1fd74
commit
ed983a5baf
|
@ -2262,6 +2262,10 @@ export interface Locale {
|
|||
"deleteNote": string;
|
||||
"createGlobalAnnouncement": string;
|
||||
"createUserAnnouncement": string;
|
||||
"updateGlobalAnnouncement": string;
|
||||
"updateUserAnnouncement": string;
|
||||
"deleteGlobalAnnouncement": string;
|
||||
"deleteUserAnnouncement": string;
|
||||
"resetPassword": string;
|
||||
"suspendRemoteInstance": string;
|
||||
"unsuspendRemoteInstance": string;
|
||||
|
|
|
@ -2175,6 +2175,10 @@ _moderationLogTypes:
|
|||
deleteNote: "ノートを削除"
|
||||
createGlobalAnnouncement: "全体のお知らせを作成"
|
||||
createUserAnnouncement: "ユーザーへお知らせを作成"
|
||||
updateGlobalAnnouncement: "全体のお知らせを更新"
|
||||
updateUserAnnouncement: "ユーザーのお知らせを更新"
|
||||
deleteGlobalAnnouncement: "全体のお知らせを削除"
|
||||
deleteUserAnnouncement: "ユーザーのお知らせを削除"
|
||||
resetPassword: "パスワードをリセット"
|
||||
suspendRemoteInstance: "リモートサーバーを停止"
|
||||
unsuspendRemoteInstance: "リモートサーバーを再開"
|
||||
|
|
|
@ -60,7 +60,7 @@ export class AnnouncementService {
|
|||
}
|
||||
|
||||
@bindThis
|
||||
public async create(values: Partial<MiAnnouncement>, moderator: MiUser): Promise<{ raw: MiAnnouncement; packed: Packed<'Announcement'> }> {
|
||||
public async create(values: Partial<MiAnnouncement>, moderator?: MiUser): Promise<{ raw: MiAnnouncement; packed: Packed<'Announcement'> }> {
|
||||
const announcement = await this.announcementsRepository.insert({
|
||||
id: this.idService.genId(),
|
||||
createdAt: new Date(),
|
||||
|
@ -82,20 +82,24 @@ export class AnnouncementService {
|
|||
announcement: packed,
|
||||
});
|
||||
|
||||
this.moderationLogService.log(moderator, 'createUserAnnouncement', {
|
||||
announcementId: announcement.id,
|
||||
announcement: announcement,
|
||||
userId: values.userId,
|
||||
});
|
||||
if (moderator) {
|
||||
this.moderationLogService.log(moderator, 'createUserAnnouncement', {
|
||||
announcementId: announcement.id,
|
||||
announcement: announcement,
|
||||
userId: values.userId,
|
||||
});
|
||||
}
|
||||
} else {
|
||||
this.globalEventService.publishBroadcastStream('announcementCreated', {
|
||||
announcement: packed,
|
||||
});
|
||||
|
||||
this.moderationLogService.log(moderator, 'createGlobalAnnouncement', {
|
||||
announcementId: announcement.id,
|
||||
announcement: announcement,
|
||||
});
|
||||
if (moderator) {
|
||||
this.moderationLogService.log(moderator, 'createGlobalAnnouncement', {
|
||||
announcementId: announcement.id,
|
||||
announcement: announcement,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
|
@ -104,6 +108,59 @@ export class AnnouncementService {
|
|||
};
|
||||
}
|
||||
|
||||
@bindThis
|
||||
public async update(announcement: MiAnnouncement, values: Partial<MiAnnouncement>, moderator?: MiUser): Promise<void> {
|
||||
await this.announcementsRepository.update(announcement.id, {
|
||||
updatedAt: new Date(),
|
||||
title: values.title,
|
||||
text: values.text,
|
||||
/* eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing -- 空の文字列の場合、nullを渡すようにするため */
|
||||
imageUrl: values.imageUrl || null,
|
||||
display: values.display,
|
||||
icon: values.icon,
|
||||
forExistingUsers: values.forExistingUsers,
|
||||
needConfirmationToRead: values.needConfirmationToRead,
|
||||
isActive: values.isActive,
|
||||
});
|
||||
|
||||
const after = await this.announcementsRepository.findOneByOrFail({ id: announcement.id });
|
||||
|
||||
if (moderator) {
|
||||
if (announcement.userId) {
|
||||
this.moderationLogService.log(moderator, 'updateUserAnnouncement', {
|
||||
announcementId: announcement.id,
|
||||
before: announcement,
|
||||
after: after,
|
||||
});
|
||||
} else {
|
||||
this.moderationLogService.log(moderator, 'updateGlobalAnnouncement', {
|
||||
announcementId: announcement.id,
|
||||
before: announcement,
|
||||
after: after,
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@bindThis
|
||||
public async delete(announcement: MiAnnouncement, moderator?: MiUser): Promise<void> {
|
||||
await this.announcementsRepository.delete(announcement.id);
|
||||
|
||||
if (moderator) {
|
||||
if (announcement.userId) {
|
||||
this.moderationLogService.log(moderator, 'deleteUserAnnouncement', {
|
||||
announcementId: announcement.id,
|
||||
announcement: announcement,
|
||||
});
|
||||
} else {
|
||||
this.moderationLogService.log(moderator, 'deleteGlobalAnnouncement', {
|
||||
announcementId: announcement.id,
|
||||
announcement: announcement,
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@bindThis
|
||||
public async read(user: MiUser, announcementId: MiAnnouncement['id']): Promise<void> {
|
||||
try {
|
||||
|
|
|
@ -7,6 +7,7 @@ import { Inject, Injectable } from '@nestjs/common';
|
|||
import { Endpoint } from '@/server/api/endpoint-base.js';
|
||||
import type { AnnouncementsRepository } from '@/models/_.js';
|
||||
import { DI } from '@/di-symbols.js';
|
||||
import { AnnouncementService } from '@/core/AnnouncementService.js';
|
||||
import { ApiError } from '../../../error.js';
|
||||
|
||||
export const meta = {
|
||||
|
@ -37,13 +38,15 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
|
|||
constructor(
|
||||
@Inject(DI.announcementsRepository)
|
||||
private announcementsRepository: AnnouncementsRepository,
|
||||
|
||||
private announcementService: AnnouncementService,
|
||||
) {
|
||||
super(meta, paramDef, async (ps, me) => {
|
||||
const announcement = await this.announcementsRepository.findOneBy({ id: ps.id });
|
||||
|
||||
if (announcement == null) throw new ApiError(meta.errors.noSuchAnnouncement);
|
||||
|
||||
await this.announcementsRepository.delete(announcement.id);
|
||||
await this.announcementService.delete(announcement, me);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,6 +7,7 @@ import { Inject, Injectable } from '@nestjs/common';
|
|||
import { Endpoint } from '@/server/api/endpoint-base.js';
|
||||
import type { AnnouncementsRepository } from '@/models/_.js';
|
||||
import { DI } from '@/di-symbols.js';
|
||||
import { AnnouncementService } from '@/core/AnnouncementService.js';
|
||||
import { ApiError } from '../../../error.js';
|
||||
|
||||
export const meta = {
|
||||
|
@ -45,13 +46,15 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
|
|||
constructor(
|
||||
@Inject(DI.announcementsRepository)
|
||||
private announcementsRepository: AnnouncementsRepository,
|
||||
|
||||
private announcementService: AnnouncementService,
|
||||
) {
|
||||
super(meta, paramDef, async (ps, me) => {
|
||||
const announcement = await this.announcementsRepository.findOneBy({ id: ps.id });
|
||||
|
||||
if (announcement == null) throw new ApiError(meta.errors.noSuchAnnouncement);
|
||||
|
||||
await this.announcementsRepository.update(announcement.id, {
|
||||
await this.announcementService.update(announcement, {
|
||||
updatedAt: new Date(),
|
||||
title: ps.title,
|
||||
text: ps.text,
|
||||
|
@ -62,7 +65,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
|
|||
forExistingUsers: ps.forExistingUsers,
|
||||
needConfirmationToRead: ps.needConfirmationToRead,
|
||||
isActive: ps.isActive,
|
||||
});
|
||||
}, me);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -43,6 +43,10 @@ export const moderationLogTypes = [
|
|||
'deleteNote',
|
||||
'createGlobalAnnouncement',
|
||||
'createUserAnnouncement',
|
||||
'updateGlobalAnnouncement',
|
||||
'updateUserAnnouncement',
|
||||
'deleteGlobalAnnouncement',
|
||||
'deleteUserAnnouncement',
|
||||
'resetPassword',
|
||||
'suspendRemoteInstance',
|
||||
'unsuspendRemoteInstance',
|
||||
|
@ -107,6 +111,24 @@ export type ModerationLogPayloads = {
|
|||
announcement: any;
|
||||
userId: string;
|
||||
};
|
||||
updateGlobalAnnouncement: {
|
||||
announcementId: string;
|
||||
before: any;
|
||||
after: any;
|
||||
};
|
||||
updateUserAnnouncement: {
|
||||
announcementId: string;
|
||||
before: any;
|
||||
after: any;
|
||||
};
|
||||
deleteGlobalAnnouncement: {
|
||||
announcementId: string;
|
||||
announcement: any;
|
||||
};
|
||||
deleteUserAnnouncement: {
|
||||
announcementId: string;
|
||||
announcement: any;
|
||||
};
|
||||
resetPassword: {
|
||||
targetId: string;
|
||||
};
|
||||
|
|
|
@ -2556,6 +2556,30 @@ type ModerationLog = {
|
|||
} | {
|
||||
type: 'promoteQueue';
|
||||
info: ModerationLogPayloads['promoteQueue'];
|
||||
} | {
|
||||
type: 'deleteDriveFile';
|
||||
info: ModerationLogPayloads['deleteDriveFile'];
|
||||
} | {
|
||||
type: 'deleteNote';
|
||||
info: ModerationLogPayloads['deleteNote'];
|
||||
} | {
|
||||
type: 'createGlobalAnnouncement';
|
||||
info: ModerationLogPayloads['createGlobalAnnouncement'];
|
||||
} | {
|
||||
type: 'createUserAnnouncement';
|
||||
info: ModerationLogPayloads['createUserAnnouncement'];
|
||||
} | {
|
||||
type: 'updateGlobalAnnouncement';
|
||||
info: ModerationLogPayloads['updateGlobalAnnouncement'];
|
||||
} | {
|
||||
type: 'updateUserAnnouncement';
|
||||
info: ModerationLogPayloads['updateUserAnnouncement'];
|
||||
} | {
|
||||
type: 'deleteGlobalAnnouncement';
|
||||
info: ModerationLogPayloads['deleteGlobalAnnouncement'];
|
||||
} | {
|
||||
type: 'deleteUserAnnouncement';
|
||||
info: ModerationLogPayloads['deleteUserAnnouncement'];
|
||||
} | {
|
||||
type: 'resetPassword';
|
||||
info: ModerationLogPayloads['resetPassword'];
|
||||
|
@ -2568,7 +2592,7 @@ type ModerationLog = {
|
|||
});
|
||||
|
||||
// @public (undocumented)
|
||||
export const moderationLogTypes: readonly ["updateServerSettings", "suspend", "unsuspend", "updateUserNote", "addCustomEmoji", "assignRole", "unassignRole", "updateRole", "deleteRole", "clearQueue", "promoteQueue", "deleteDriveFile", "deleteNote", "createGlobalAnnouncement", "createUserAnnouncement", "resetPassword", "suspendRemoteInstance", "unsuspendRemoteInstance"];
|
||||
export const moderationLogTypes: readonly ["updateServerSettings", "suspend", "unsuspend", "updateUserNote", "addCustomEmoji", "assignRole", "unassignRole", "updateRole", "deleteRole", "clearQueue", "promoteQueue", "deleteDriveFile", "deleteNote", "createGlobalAnnouncement", "createUserAnnouncement", "updateGlobalAnnouncement", "updateUserAnnouncement", "deleteGlobalAnnouncement", "deleteUserAnnouncement", "resetPassword", "suspendRemoteInstance", "unsuspendRemoteInstance"];
|
||||
|
||||
// @public (undocumented)
|
||||
export const mutedNoteReasons: readonly ["word", "manual", "spam", "other"];
|
||||
|
|
|
@ -61,6 +61,10 @@ export const moderationLogTypes = [
|
|||
'deleteNote',
|
||||
'createGlobalAnnouncement',
|
||||
'createUserAnnouncement',
|
||||
'updateGlobalAnnouncement',
|
||||
'updateUserAnnouncement',
|
||||
'deleteGlobalAnnouncement',
|
||||
'deleteUserAnnouncement',
|
||||
'resetPassword',
|
||||
'suspendRemoteInstance',
|
||||
'unsuspendRemoteInstance',
|
||||
|
@ -125,6 +129,24 @@ export type ModerationLogPayloads = {
|
|||
announcement: any;
|
||||
userId: string;
|
||||
};
|
||||
updateGlobalAnnouncement: {
|
||||
announcementId: string;
|
||||
before: any;
|
||||
after: any;
|
||||
};
|
||||
updateUserAnnouncement: {
|
||||
announcementId: string;
|
||||
before: any;
|
||||
after: any;
|
||||
};
|
||||
deleteGlobalAnnouncement: {
|
||||
announcementId: string;
|
||||
announcement: any;
|
||||
};
|
||||
deleteUserAnnouncement: {
|
||||
announcementId: string;
|
||||
announcement: any;
|
||||
};
|
||||
resetPassword: {
|
||||
targetId: string;
|
||||
};
|
||||
|
|
|
@ -607,6 +607,30 @@ export type ModerationLog = {
|
|||
} | {
|
||||
type: 'promoteQueue';
|
||||
info: ModerationLogPayloads['promoteQueue'];
|
||||
} | {
|
||||
type: 'deleteDriveFile';
|
||||
info: ModerationLogPayloads['deleteDriveFile'];
|
||||
} | {
|
||||
type: 'deleteNote';
|
||||
info: ModerationLogPayloads['deleteNote'];
|
||||
} | {
|
||||
type: 'createGlobalAnnouncement';
|
||||
info: ModerationLogPayloads['createGlobalAnnouncement'];
|
||||
} | {
|
||||
type: 'createUserAnnouncement';
|
||||
info: ModerationLogPayloads['createUserAnnouncement'];
|
||||
} | {
|
||||
type: 'updateGlobalAnnouncement';
|
||||
info: ModerationLogPayloads['updateGlobalAnnouncement'];
|
||||
} | {
|
||||
type: 'updateUserAnnouncement';
|
||||
info: ModerationLogPayloads['updateUserAnnouncement'];
|
||||
} | {
|
||||
type: 'deleteGlobalAnnouncement';
|
||||
info: ModerationLogPayloads['deleteGlobalAnnouncement'];
|
||||
} | {
|
||||
type: 'deleteUserAnnouncement';
|
||||
info: ModerationLogPayloads['deleteUserAnnouncement'];
|
||||
} | {
|
||||
type: 'resetPassword';
|
||||
info: ModerationLogPayloads['resetPassword'];
|
||||
|
|
Loading…
Reference in New Issue