Skip to content

Commit

Permalink
fix: moderation log for makeNoteHome
Browse files Browse the repository at this point in the history
  • Loading branch information
Sayamame-beans committed Dec 24, 2023
1 parent 6a249bb commit 69b5b3c
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 4 deletions.
1 change: 1 addition & 0 deletions locales/ja-JP.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2371,6 +2371,7 @@ _moderationLogTypes:
deleteAvatarDecoration: "アイコンデコレーションを削除"
unsetUserAvatar: "ユーザーのアイコンを解除"
unsetUserBanner: "ユーザーのバナーを解除"
makeNoteHome: "ノートをホーム投稿に変更"

_fileViewer:
title: "ファイルの詳細"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import { Inject, Injectable } from '@nestjs/common';
import { DataSource } from 'typeorm';
import * as Redis from 'ioredis';
import type { NotesRepository } from '@/models/_.js';
import type { NotesRepository, UsersRepository } from '@/models/_.js';
import { MiNote, MiPoll } from '@/models/_.js';
import { Endpoint } from '@/server/api/endpoint-base.js';
import { DI } from '@/di-symbols.js';
Expand Down Expand Up @@ -47,6 +47,9 @@ export const paramDef = {
@Injectable()
export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-disable-line import/no-default-export
constructor(
@Inject(DI.usersRepository)
private usersRepository: UsersRepository,

@Inject(DI.notesRepository)
private notesRepository: NotesRepository,

Expand Down Expand Up @@ -74,7 +77,14 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
// Note: by design, visibility of replies and quoted renotes are not changed
// replies and quoted renotes have their own text, so it's another moderation entity

await moderationLogService.log(me, 'makeNoteHome', { targetNoteId: note.id });
const user = await this.usersRepository.findOneByOrFail({ id: note.userId });
await moderationLogService.log(me, 'makeNoteHome', {
noteId: note.id,
noteUserId: note.userId,
noteUserUsername: user.username,
noteUserHost: user.host,
note: note,
});

// update basic note info
await this.db.transaction(async transactionalEntityManager => {
Expand Down
6 changes: 5 additions & 1 deletion packages/backend/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,11 @@ export type ModerationLogPayloads = {
fileId: string;
};
makeNoteHome: {
targetNoteId: string;
noteId: string;
noteUserId: string;
noteUserUsername: string;
noteUserHost: string | null;
note: any;
};
};

Expand Down
3 changes: 2 additions & 1 deletion packages/frontend/src/pages/admin/modlog.ModLog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ SPDX-License-Identifier: AGPL-3.0-only
<b
:class="{
[$style.logGreen]: ['createRole', 'addCustomEmoji', 'createGlobalAnnouncement', 'createUserAnnouncement', 'createAd', 'createInvitation', 'createAvatarDecoration'].includes(log.type),
[$style.logYellow]: ['markSensitiveDriveFile', 'resetPassword'].includes(log.type),
[$style.logYellow]: ['markSensitiveDriveFile', 'resetPassword', 'makeNoteHome'].includes(log.type),
[$style.logRed]: ['suspend', 'deleteRole', 'suspendRemoteInstance', 'deleteGlobalAnnouncement', 'deleteUserAnnouncement', 'deleteCustomEmoji', 'deleteNote', 'deleteDriveFile', 'deleteAd', 'deleteAvatarDecoration'].includes(log.type)
}"
>{{ i18n.ts._moderationLogTypes[log.type] }}</b>
Expand Down Expand Up @@ -40,6 +40,7 @@ SPDX-License-Identifier: AGPL-3.0-only
<span v-else-if="log.type === 'createAvatarDecoration'">: {{ log.info.avatarDecoration.name }}</span>
<span v-else-if="log.type === 'updateAvatarDecoration'">: {{ log.info.before.name }}</span>
<span v-else-if="log.type === 'deleteAvatarDecoration'">: {{ log.info.avatarDecoration.name }}</span>
<span v-else-if="log.type === 'makeNoteHome'">: @{{ log.info.noteUserUsername }}{{ log.info.noteUserHost ? '@' + log.info.noteUserHost : '' }}</span>
</template>
<template #icon>
<MkAvatar :user="log.user" :class="$style.avatar"/>
Expand Down
8 changes: 8 additions & 0 deletions packages/misskey-js/src/consts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ export const moderationLogTypes = [
'deleteAvatarDecoration',
'unsetUserAvatar',
'unsetUserBanner',
'makeNoteHome',
] as const;

export type ModerationLogPayloads = {
Expand Down Expand Up @@ -271,4 +272,11 @@ export type ModerationLogPayloads = {
userHost: string | null;
fileId: string;
};
makeNoteHome: {
noteId: string;
noteUserId: string;
noteUserUsername: string;
noteUserHost: string | null;
note: any;
};
};
3 changes: 3 additions & 0 deletions packages/misskey-js/src/entities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,9 @@ export type ModerationLog = {
} | {
type: 'unsetUserBanner';
info: ModerationLogPayloads['unsetUserBanner'];
} | {
type: 'makeNoteHome';
info: ModerationLogPayloads['makeNoteHome'];
});

export type ServerStats = {
Expand Down

0 comments on commit 69b5b3c

Please sign in to comment.