suspend周りの改修 (#14409)
* enhance(backend): 凍結されたアカウントのフォローリクエストを表示しないように * Update CHANGELOG.md * wip * Update gen-spec.ts * Update packages/backend/src/server/api/endpoints/admin/suspend-user.ts Co-authored-by: Kisaragi <48310258+KisaragiEffective@users.noreply.github.com> * owa- * revert misskey-js related changes (#14414) --------- Co-authored-by: Kisaragi <48310258+KisaragiEffective@users.noreply.github.com> Co-authored-by: anatawa12 <anatawa12@icloud.com>
This commit is contained in:
		| @@ -7,9 +7,9 @@ import { Inject, Injectable } from '@nestjs/common'; | ||||
| import { Endpoint } from '@/server/api/endpoint-base.js'; | ||||
| import type { UsersRepository } from '@/models/_.js'; | ||||
| import { QueueService } from '@/core/QueueService.js'; | ||||
| import { UserSuspendService } from '@/core/UserSuspendService.js'; | ||||
| import { DI } from '@/di-symbols.js'; | ||||
| import { UserEntityService } from '@/core/entities/UserEntityService.js'; | ||||
| import { DeleteAccountService } from '@/core/DeleteAccountService.js'; | ||||
|  | ||||
| export const meta = { | ||||
| 	tags: ['admin'], | ||||
| @@ -33,9 +33,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint- | ||||
| 		@Inject(DI.usersRepository) | ||||
| 		private usersRepository: UsersRepository, | ||||
|  | ||||
| 		private userEntityService: UserEntityService, | ||||
| 		private queueService: QueueService, | ||||
| 		private userSuspendService: UserSuspendService, | ||||
| 		private deleteAccoountService: DeleteAccountService, | ||||
| 	) { | ||||
| 		super(meta, paramDef, async (ps, me) => { | ||||
| 			const user = await this.usersRepository.findOneBy({ id: ps.userId }); | ||||
| @@ -48,22 +46,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint- | ||||
| 				throw new Error('cannot delete a root account'); | ||||
| 			} | ||||
|  | ||||
| 			if (this.userEntityService.isLocalUser(user)) { | ||||
| 				// 物理削除する前にDelete activityを送信する | ||||
| 				await this.userSuspendService.doPostSuspend(user).catch(err => {}); | ||||
|  | ||||
| 				this.queueService.createDeleteAccountJob(user, { | ||||
| 					soft: false, | ||||
| 				}); | ||||
| 			} else { | ||||
| 				this.queueService.createDeleteAccountJob(user, { | ||||
| 					soft: true, // リモートユーザーの削除は、完全にDBから物理削除してしまうと再度連合してきてアカウントが復活する可能性があるため、soft指定する | ||||
| 				}); | ||||
| 			} | ||||
|  | ||||
| 			await this.usersRepository.update(user.id, { | ||||
| 				isDeleted: true, | ||||
| 			}); | ||||
| 			await this.deleteAccoountService.deleteAccount(user); | ||||
| 		}); | ||||
| 	} | ||||
| } | ||||
|   | ||||
| @@ -3,18 +3,12 @@ | ||||
|  * SPDX-License-Identifier: AGPL-3.0-only | ||||
|  */ | ||||
|  | ||||
| import { IsNull, Not } from 'typeorm'; | ||||
| import { Inject, Injectable } from '@nestjs/common'; | ||||
| import { Endpoint } from '@/server/api/endpoint-base.js'; | ||||
| import type { UsersRepository, FollowingsRepository } from '@/models/_.js'; | ||||
| import type { MiUser } from '@/models/User.js'; | ||||
| import type { RelationshipJobData } from '@/queue/types.js'; | ||||
| import { ModerationLogService } from '@/core/ModerationLogService.js'; | ||||
| import type { UsersRepository } from '@/models/_.js'; | ||||
| import { UserSuspendService } from '@/core/UserSuspendService.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'], | ||||
| @@ -38,13 +32,8 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint- | ||||
| 		@Inject(DI.usersRepository) | ||||
| 		private usersRepository: UsersRepository, | ||||
|  | ||||
| 		@Inject(DI.followingsRepository) | ||||
| 		private followingsRepository: FollowingsRepository, | ||||
|  | ||||
| 		private userSuspendService: UserSuspendService, | ||||
| 		private roleService: RoleService, | ||||
| 		private moderationLogService: ModerationLogService, | ||||
| 		private queueService: QueueService, | ||||
| 	) { | ||||
| 		super(meta, paramDef, async (ps, me) => { | ||||
| 			const user = await this.usersRepository.findOneBy({ id: ps.userId }); | ||||
| @@ -57,42 +46,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint- | ||||
| 				throw new Error('cannot suspend moderator account'); | ||||
| 			} | ||||
|  | ||||
| 			await this.usersRepository.update(user.id, { | ||||
| 				isSuspended: true, | ||||
| 			}); | ||||
|  | ||||
| 			this.moderationLogService.log(me, 'suspend', { | ||||
| 				userId: user.id, | ||||
| 				userUsername: user.username, | ||||
| 				userHost: user.host, | ||||
| 			}); | ||||
|  | ||||
| 			(async () => { | ||||
| 				await this.userSuspendService.doPostSuspend(user).catch(e => {}); | ||||
| 				await this.unFollowAll(user).catch(e => {}); | ||||
| 			})(); | ||||
| 			await this.userSuspendService.suspend(user, me); | ||||
| 		}); | ||||
| 	} | ||||
|  | ||||
| 	@bindThis | ||||
| 	private async unFollowAll(follower: MiUser) { | ||||
| 		const followings = await this.followingsRepository.find({ | ||||
| 			where: { | ||||
| 				followerId: follower.id, | ||||
| 				followeeId: Not(IsNull()), | ||||
| 			}, | ||||
| 		}); | ||||
|  | ||||
| 		const jobs: RelationshipJobData[] = []; | ||||
| 		for (const following of followings) { | ||||
| 			if (following.followeeId && following.followerId) { | ||||
| 				jobs.push({ | ||||
| 					from: { id: following.followerId }, | ||||
| 					to: { id: following.followeeId }, | ||||
| 					silent: true, | ||||
| 				}); | ||||
| 			} | ||||
| 		} | ||||
| 		this.queueService.createUnfollowJob(jobs); | ||||
| 	} | ||||
| } | ||||
|   | ||||
| @@ -6,7 +6,6 @@ | ||||
| import { Inject, Injectable } from '@nestjs/common'; | ||||
| import { Endpoint } from '@/server/api/endpoint-base.js'; | ||||
| import type { UsersRepository } from '@/models/_.js'; | ||||
| import { ModerationLogService } from '@/core/ModerationLogService.js'; | ||||
| import { UserSuspendService } from '@/core/UserSuspendService.js'; | ||||
| import { DI } from '@/di-symbols.js'; | ||||
|  | ||||
| @@ -33,7 +32,6 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint- | ||||
| 		private usersRepository: UsersRepository, | ||||
|  | ||||
| 		private userSuspendService: UserSuspendService, | ||||
| 		private moderationLogService: ModerationLogService, | ||||
| 	) { | ||||
| 		super(meta, paramDef, async (ps, me) => { | ||||
| 			const user = await this.usersRepository.findOneBy({ id: ps.userId }); | ||||
| @@ -42,17 +40,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint- | ||||
| 				throw new Error('user not found'); | ||||
| 			} | ||||
|  | ||||
| 			await this.usersRepository.update(user.id, { | ||||
| 				isSuspended: false, | ||||
| 			}); | ||||
|  | ||||
| 			this.moderationLogService.log(me, 'unsuspend', { | ||||
| 				userId: user.id, | ||||
| 				userUsername: user.username, | ||||
| 				userHost: user.host, | ||||
| 			}); | ||||
|  | ||||
| 			this.userSuspendService.doPostUnsuspend(user); | ||||
| 			await this.userSuspendService.unsuspend(user, me); | ||||
| 		}); | ||||
| 	} | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 syuilo
					syuilo