Skip to content

Commit

Permalink
feat: admin側でuser.isSensitiveをセットできるように (#133)
Browse files Browse the repository at this point in the history
* feat: admin側でuser.isSensitiveをセットできるように

* drop: 設定からuser.isSensitiveを設定できないように

* add locale

* feat: i/updateからisSensitiveを切り替えられないように

---------

Co-authored-by: Esurio <esurio@esurio1673.net>
  • Loading branch information
1673beta and Esurio authored Aug 11, 2024
1 parent 4b1bdf6 commit 46d7f64
Show file tree
Hide file tree
Showing 17 changed files with 372 additions and 9 deletions.
4 changes: 4 additions & 0 deletions locales/en-US.yml
Original file line number Diff line number Diff line change
Expand Up @@ -226,10 +226,14 @@ block: "Block"
unblock: "Unblock"
suspend: "Suspend"
unsuspend: "Unsuspend"
setAsSensitive: "Set as sensitive user"
unsetAsSensitive: "Unset as sensitive user"
blockConfirm: "Are you sure that you want to block this account?"
unblockConfirm: "Are you sure that you want to unblock this account?"
suspendConfirm: "Are you sure that you want to suspend this account?"
unsuspendConfirm: "Are you sure that you want to unsuspend this account?"
setSensitiveConfirm: "Are you sure that you want to set this account as sensitive?"
unsetSensitiveConfirm: "Are you sure that you want to unset this account as sensitive?"
selectList: "Select a list"
editList: "Edit list"
selectChannel: "Select a channel"
Expand Down
16 changes: 16 additions & 0 deletions locales/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -930,6 +930,14 @@ export interface Locale extends ILocale {
* 解凍
*/
"unsuspend": string;
/**
* センシティブとして設定
*/
"setAsSensitive": string;
/**
* センシティブを解除
*/
"unsetAsSensitive": string;
/**
* ブロックしますか?
*/
Expand All @@ -946,6 +954,14 @@ export interface Locale extends ILocale {
* 解凍しますか?
*/
"unsuspendConfirm": string;
/**
* センシティブとして設定しますか?
*/
"setSensitiveConfirm": string;
/**
* センシティブを解除しますか?
*/
"unsetSensitiveConfirm": string;
/**
* リストを選択
*/
Expand Down
4 changes: 4 additions & 0 deletions locales/ja-JP.yml
Original file line number Diff line number Diff line change
Expand Up @@ -227,10 +227,14 @@ block: "ブロック"
unblock: "ブロック解除"
suspend: "凍結"
unsuspend: "解凍"
setAsSensitive: "センシティブとして設定"
unsetAsSensitive: "センシティブを解除"
blockConfirm: "ブロックしますか?"
unblockConfirm: "ブロック解除しますか?"
suspendConfirm: "凍結しますか?"
unsuspendConfirm: "解凍しますか?"
setSensitiveConfirm: "センシティブとして設定しますか?"
unsetSensitiveConfirm: "センシティブを解除しますか?"
selectList: "リストを選択"
editList: "リストを編集"
selectChannel: "チャンネルを選択"
Expand Down
8 changes: 8 additions & 0 deletions packages/backend/src/server/api/EndpointsModule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ import * as ep___admin_showUser from './endpoints/admin/show-user.js';
import * as ep___admin_showUsers from './endpoints/admin/show-users.js';
import * as ep___admin_suspendUser from './endpoints/admin/suspend-user.js';
import * as ep___admin_unsuspendUser from './endpoints/admin/unsuspend-user.js';
import * as ep___admin_setUserSensitive from './endpoints/admin/set-user-sensitive.js';
import * as ep___admin_unsetUserSensitive from './endpoints/admin/unset-user-sensitive.js';
import * as ep___admin_updateMeta from './endpoints/admin/update-meta.js';
import * as ep___admin_deleteAccount from './endpoints/admin/delete-account.js';
import * as ep___admin_updateUserNote from './endpoints/admin/update-user-note.js';
Expand Down Expand Up @@ -491,6 +493,8 @@ const $admin_showUser: Provider = { provide: 'ep:admin/show-user', useClass: ep_
const $admin_showUsers: Provider = { provide: 'ep:admin/show-users', useClass: ep___admin_showUsers.default };
const $admin_suspendUser: Provider = { provide: 'ep:admin/suspend-user', useClass: ep___admin_suspendUser.default };
const $admin_unsuspendUser: Provider = { provide: 'ep:admin/unsuspend-user', useClass: ep___admin_unsuspendUser.default };
const $admin_setUserSensitive: Provider = { provide: 'ep:admin/set-user-sensitive', useClass: ep___admin_setUserSensitive.default };
const $admin_unsetUserSensitive: Provider = { provide: 'ep:admin/unset-user-sensitive', useClass: ep___admin_unsetUserSensitive.default };
const $admin_updateMeta: Provider = { provide: 'ep:admin/update-meta', useClass: ep___admin_updateMeta.default };
const $admin_deleteAccount: Provider = { provide: 'ep:admin/delete-account', useClass: ep___admin_deleteAccount.default };
const $admin_updateUserNote: Provider = { provide: 'ep:admin/update-user-note', useClass: ep___admin_updateUserNote.default };
Expand Down Expand Up @@ -904,6 +908,8 @@ const $bubbleGame_ranking: Provider = { provide: 'ep:bubble-game/ranking', useCl
$admin_showUsers,
$admin_suspendUser,
$admin_unsuspendUser,
$admin_setUserSensitive,
$admin_unsetUserSensitive,
$admin_updateMeta,
$admin_deleteAccount,
$admin_updateUserNote,
Expand Down Expand Up @@ -1310,6 +1316,8 @@ const $bubbleGame_ranking: Provider = { provide: 'ep:bubble-game/ranking', useCl
$admin_showUsers,
$admin_suspendUser,
$admin_unsuspendUser,
$admin_setUserSensitive,
$admin_unsetUserSensitive,
$admin_updateMeta,
$admin_deleteAccount,
$admin_updateUserNote,
Expand Down
4 changes: 4 additions & 0 deletions packages/backend/src/server/api/endpoints.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ import * as ep___admin_showUser from './endpoints/admin/show-user.js';
import * as ep___admin_showUsers from './endpoints/admin/show-users.js';
import * as ep___admin_suspendUser from './endpoints/admin/suspend-user.js';
import * as ep___admin_unsuspendUser from './endpoints/admin/unsuspend-user.js';
import * as ep___admin_setUserSensitive from './endpoints/admin/set-user-sensitive.js';
import * as ep___admin_unsetUserSensitive from './endpoints/admin/unset-user-sensitive.js';
import * as ep___admin_updateMeta from './endpoints/admin/update-meta.js';
import * as ep___admin_deleteAccount from './endpoints/admin/delete-account.js';
import * as ep___admin_updateUserNote from './endpoints/admin/update-user-note.js';
Expand Down Expand Up @@ -494,6 +496,8 @@ const eps = [
['admin/show-users', ep___admin_showUsers],
['admin/suspend-user', ep___admin_suspendUser],
['admin/unsuspend-user', ep___admin_unsuspendUser],
['admin/set-user-sensitive', ep___admin_setUserSensitive],
['admin/unset-user-sensitive', ep___admin_unsetUserSensitive],
['admin/update-meta', ep___admin_updateMeta],
['admin/delete-account', ep___admin_deleteAccount],
['admin/update-user-note', ep___admin_updateUserNote],
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/*
* SPDX-FileCopyrightText: syuilo and misskey-project
* SPDX-License-Identifier: AGPL-3.0-only
*/

import { Inject, Injectable } from '@nestjs/common';
import { Endpoint } from '@/server/api/endpoint-base.js';
import type { UsersRepository, UserProfilesRepository } from '@/models/_.js';
import type { MiUser } from '@/models/User.js';
import { ModerationLogService } from '@/core/ModerationLogService.js';
import { DI } from '@/di-symbols.js';
import { bindThis } from '@/decorators.js';
import { RoleService } from '@/core/RoleService.js';
import { QueueService } from '@/core/QueueService.js';

export const meta = {
tags: ['admin'],

requireCredential: true,
requireModerator: true,
kind: 'write:admin:suspend-user',
} as const;

export const paramDef = {
type: 'object',
properties: {
userId: { type: 'string', format: 'misskey:id' },
},
required: ['userId'],
} as const;

@Injectable()
export default class extends Endpoint<typeof meta, typeof paramDef> {
constructor(
@Inject(DI.usersRepository)
private usersRepository: UsersRepository,

@Inject(DI.userProfilesRepository)
private userProfilesRepository: UserProfilesRepository,

private roleService: RoleService,
private moderationLogService: ModerationLogService,
private queueService: QueueService,
) {
super(meta, paramDef, async (ps, me) => {
const user = await this.usersRepository.findOneBy({ id: ps.userId });

if (user == null) {
throw new Error('user not found');
}

if (await this.roleService.isAdministrator(user)) {
throw new Error('cannot set admin as sensitive');
}

await this.userProfilesRepository.update(user.id, {
isSensitive: true,
});

await this.usersRepository.update(user.id, {
isSensitive: true,
});

this.moderationLogService.log(me, 'setSensitive', {
userId: user.id,
userUsername: user.username,
userHost: user.host,
});
})
}
}
5 changes: 5 additions & 0 deletions packages/backend/src/server/api/endpoints/admin/show-user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,10 @@ export const meta = {
type: 'boolean',
optional: false, nullable: false,
},
isSensitive: {
type: 'boolean',
optional: false, nullable: false,
},
isHibernated: {
type: 'boolean',
optional: false, nullable: false,
Expand Down Expand Up @@ -241,6 +245,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
isModerator: isModerator,
isSilenced: isSilenced,
isSuspended: user.isSuspended,
isSensitive: profile.isSensitive,
isHibernated: user.isHibernated,
lastActiveDate: user.lastActiveDate ? user.lastActiveDate.toISOString() : null,
moderationNote: profile.moderationNote ?? '',
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/*
* SPDX-FileCopyrightText: syuilo and misskey-project
* SPDX-License-Identifier: AGPL-3.0-only
*/

import { Inject, Injectable } from '@nestjs/common';
import { Endpoint } from '@/server/api/endpoint-base.js';
import type { UsersRepository, UserProfilesRepository } from '@/models/_.js';
import type { MiUser } from '@/models/User.js';
import { ModerationLogService } from '@/core/ModerationLogService.js';
import { DI } from '@/di-symbols.js';
import { bindThis } from '@/decorators.js';
import { RoleService } from '@/core/RoleService.js';
import { QueueService } from '@/core/QueueService.js';

export const meta = {
tags: ['admin'],

requireCredential: true,
requireModerator: true,
kind: 'write:admin:suspend-user',
} as const;

export const paramDef = {
type: 'object',
properties: {
userId: { type: 'string', format: 'misskey:id' },
},
required: ['userId'],
} as const;

@Injectable()
export default class extends Endpoint<typeof meta, typeof paramDef> {
constructor(
@Inject(DI.usersRepository)
private usersRepository: UsersRepository,

@Inject(DI.userProfilesRepository)
private userProfilesRepository: UserProfilesRepository,

private roleService: RoleService,
private moderationLogService: ModerationLogService,
private queueService: QueueService,
) {
super(meta, paramDef, async (ps, me) => {
const user = await this.usersRepository.findOneBy({ id: ps.userId });

if (user == null) {
throw new Error('user not found');
}

if (await this.roleService.isAdministrator(user)) {
throw new Error('cannot set admin as sensitive');
}

await this.userProfilesRepository.update(user.id, {
isSensitive: false,
});

await this.usersRepository.update(user.id, {
isSensitive: false,
});

this.moderationLogService.log(me, 'setSensitive', {
userId: user.id,
userUsername: user.username,
userHost: user.host,
});
})
}
}
5 changes: 0 additions & 5 deletions packages/backend/src/server/api/endpoints/i/update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,6 @@ export const paramDef = {
noCrawle: { type: 'boolean' },
preventAiLearning: { type: 'boolean' },
isIndexable: { type: 'boolean' },
isSensitive: { type: 'boolean' },
isBot: { type: 'boolean' },
isCat: { type: 'boolean' },
injectFeaturedNote: { type: 'boolean' },
Expand Down Expand Up @@ -330,10 +329,6 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
updates.isIndexable = ps.isIndexable;
profileUpdates.isIndexable = ps.isIndexable;
};
if (typeof ps.isSensitive === 'boolean') {
updates.isSensitive = ps.isSensitive;
profileUpdates.isSensitive = ps.isSensitive;
};
if (typeof ps.isCat === 'boolean') updates.isCat = ps.isCat;
if (typeof ps.injectFeaturedNote === 'boolean') profileUpdates.injectFeaturedNote = ps.injectFeaturedNote;
if (typeof ps.receiveAnnouncementEmail === 'boolean') profileUpdates.receiveAnnouncementEmail = ps.receiveAnnouncementEmail;
Expand Down
12 changes: 12 additions & 0 deletions packages/backend/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ export const moderationLogTypes = [
'updateServerSettings',
'suspend',
'unsuspend',
'setSensitive',
'unsetSensitive',
'updateUserNote',
'addCustomEmoji',
'updateCustomEmoji',
Expand Down Expand Up @@ -115,6 +117,16 @@ export type ModerationLogPayloads = {
userUsername: string;
userHost: string | null;
};
setSensitive: {
userId: string;
userUsername: string;
userHost: string | null;
};
unsetSensitive: {
userId: string;
userUsername: string;
userHost: string | null;
};
updateUserNote: {
userId: string;
userUsername: string;
Expand Down
8 changes: 8 additions & 0 deletions packages/cherrypick-js/etc/cherrypick-js.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,9 @@ type AdminSendEmailRequest = operations['admin___send-email']['requestBody']['co
// @public (undocumented)
type AdminServerInfoResponse = operations['admin___server-info']['responses']['200']['content']['application/json'];

// @public (undocumented)
type AdminSetUserSensitiveRequest = operations['admin___set-user-sensitive']['requestBody']['content']['application/json'];

// @public (undocumented)
type AdminShowModerationLogsRequest = operations['admin___show-moderation-logs']['requestBody']['content']['application/json'];

Expand Down Expand Up @@ -400,6 +403,9 @@ type AdminUnsetUserAvatarRequest = operations['admin___unset-user-avatar']['requ
// @public (undocumented)
type AdminUnsetUserBannerRequest = operations['admin___unset-user-banner']['requestBody']['content']['application/json'];

// @public (undocumented)
type AdminUnsetUserSensitiveRequest = operations['admin___unset-user-sensitive']['requestBody']['content']['application/json'];

// @public (undocumented)
type AdminUnsuspendUserRequest = operations['admin___unsuspend-user']['requestBody']['content']['application/json'];

Expand Down Expand Up @@ -1316,6 +1322,8 @@ declare namespace entities {
AdminShowUsersResponse,
AdminSuspendUserRequest,
AdminUnsuspendUserRequest,
AdminSetUserSensitiveRequest,
AdminUnsetUserSensitiveRequest,
AdminUpdateMetaRequest,
AdminDeleteAccountRequest,
AdminUpdateUserNoteRequest,
Expand Down
22 changes: 22 additions & 0 deletions packages/cherrypick-js/src/autogen/apiClientJSDoc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -849,6 +849,28 @@ declare module '../api.js' {
credential?: string | null,
): Promise<SwitchCaseResponseType<E, P>>;

/**
* No description provided.
*
* **Credential required**: *Yes* / **Permission**: *write:admin:suspend-user*
*/
request<E extends 'admin/set-user-sensitive', P extends Endpoints[E]['req']>(
endpoint: E,
params: P,
credential?: string | null,
): Promise<SwitchCaseResponseType<E, P>>;

/**
* No description provided.
*
* **Credential required**: *Yes* / **Permission**: *write:admin:suspend-user*
*/
request<E extends 'admin/unset-user-sensitive', P extends Endpoints[E]['req']>(
endpoint: E,
params: P,
credential?: string | null,
): Promise<SwitchCaseResponseType<E, P>>;

/**
* No description provided.
*
Expand Down
Loading

0 comments on commit 46d7f64

Please sign in to comment.