Skip to content

Commit

Permalink
モデレータのブロックを禁止
Browse files Browse the repository at this point in the history
  • Loading branch information
FineArchs committed Nov 27, 2024
1 parent d237651 commit fc8ad3d
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 10 deletions.
7 changes: 6 additions & 1 deletion packages/backend/src/core/UserBlockingService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { UserWebhookService } from '@/core/UserWebhookService.js';
import { bindThis } from '@/decorators.js';
import { CacheService } from '@/core/CacheService.js';
import { UserFollowingService } from '@/core/UserFollowingService.js';
import { RoleService } from '@/core/RoleService.js';

@Injectable()
export class UserBlockingService implements OnModuleInit {
Expand Down Expand Up @@ -49,6 +50,7 @@ export class UserBlockingService implements OnModuleInit {
private webhookService: UserWebhookService,
private apRendererService: ApRendererService,
private loggerService: LoggerService,
private roleService: RoleService,
) {
this.logger = this.loggerService.getLogger('user-block');
}
Expand All @@ -58,7 +60,8 @@ export class UserBlockingService implements OnModuleInit {
}

@bindThis
public async block(blocker: MiUser, blockee: MiUser, silent = false) {
public async block(blocker: MiUser, blockee: MiUser, silent = false): null | 'BLOCKEE_IS_MODERATOR' {
if (await this.roleService.isModerator(blockee)) return 'BLOCKEE_IS_MODERATOR';
await Promise.all([
this.cancelRequest(blocker, blockee, silent),
this.cancelRequest(blockee, blocker, silent),
Expand Down Expand Up @@ -89,6 +92,8 @@ export class UserBlockingService implements OnModuleInit {
const content = this.apRendererService.addContext(this.apRendererService.renderBlock(blocking));
this.queueService.deliver(blocker, content, blockee.inbox, false);
}

return null;
}

@bindThis
Expand Down
7 changes: 5 additions & 2 deletions packages/backend/src/core/activitypub/ApInboxService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -357,8 +357,11 @@ export class ApInboxService {
return 'skip: ブロックしようとしているユーザーはローカルユーザーではありません';
}

await this.userBlockingService.block(await this.usersRepository.findOneByOrFail({ id: actor.id }), await this.usersRepository.findOneByOrFail({ id: blockee.id }));
return 'ok';
const error = await this.userBlockingService.block(await this.usersRepository.findOneByOrFail({ id: actor.id }), await this.usersRepository.findOneByOrFail({ id: blockee.id }));
switch (error) {
case null: return 'ok';
case 'BLOCKEE_IS_MODERATOR': return 'skip: Blocking Moderator is not allowed.';
}
}

@bindThis
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,11 @@ export class RelationshipProcessorService {
this.usersRepository.findOneByOrFail({ id: job.data.from.id }),
this.usersRepository.findOneByOrFail({ id: job.data.to.id }),
]);
await this.userBlockingService.block(blockee, blocker, job.data.silent);
return 'ok';
const error = await this.userBlockingService.block(blockee, blocker, job.data.silent);
switch (error) {
case null: return 'ok';
case 'BLOCKEE_IS_MODERATOR': return 'skip: Blocking Moderator is not allowed.';
}
}

@bindThis
Expand Down
23 changes: 18 additions & 5 deletions packages/backend/src/server/api/endpoints/blocking/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@ export const meta = {
code: 'ALREADY_BLOCKING',
id: '787fed64-acb9-464a-82eb-afbd745b9614',
},

blockeeIsModerator: {
message: 'Blocking Moderator is not allowed.',
code: 'BLOCKEE_IS_MODERATOR',
id: '3dca06d1-5ee8-4f14-aff1-917e9ba35e05',
},
},

res: {
Expand Down Expand Up @@ -99,11 +105,18 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
throw new ApiError(meta.errors.alreadyBlocking);
}

await this.userBlockingService.block(blocker, blockee);

return await this.userEntityService.pack(blockee.id, blocker, {
schema: 'UserDetailedNotMe',
});
const error = await this.userBlockingService.block(blocker, blockee);

switch (error) {
case null: {
return await this.userEntityService.pack(blockee.id, blocker, {
schema: 'UserDetailedNotMe',
});
}
case 'BLOCKEE_IS_MODERATOR': throw new ApiError(meta.errors.blockeeIsModerator);
// 網羅性チェック
default: error satisfies never;
}
});
}
}

0 comments on commit fc8ad3d

Please sign in to comment.