forked from kokonect-link/cherrypick
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: admin側でuser.isSensitiveをセットできるように (#133)
* feat: admin側でuser.isSensitiveをセットできるように * drop: 設定からuser.isSensitiveを設定できないように * add locale * feat: i/updateからisSensitiveを切り替えられないように --------- Co-authored-by: Esurio <esurio@esurio1673.net>
- Loading branch information
Showing
17 changed files
with
372 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
packages/backend/src/server/api/endpoints/admin/set-user-sensitive.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}); | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
packages/backend/src/server/api/endpoints/admin/unset-user-sensitive.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}); | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.