Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

モデレータのブロックを禁止 #84

Open
wants to merge 3 commits into
base: voskey-main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 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,11 @@ export class UserBlockingService implements OnModuleInit {
}

@bindThis
public async block(blocker: MiUser, blockee: MiUser, silent = false) {
public async block(blocker: MiUser, blockee: MiUser, silent = false): Promise<
| 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 +95,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: throw new Error(error satisfies never);
}
});
}
}
Loading