feat: ロールによるメンション、リプライ、引用の制限 (MisskeyIO#478)

This commit is contained in:
kabo2468 2024-02-27 02:51:17 +09:00 committed by GitHub
parent ce98a86c89
commit a9912534fe
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
10 changed files with 55 additions and 4 deletions

View file

@ -259,13 +259,14 @@ export class NoteCreateService implements OnApplicationShutdown {
if (data.channel != null) data.localOnly = true;
const meta = await this.metaService.fetch();
const policies = await this.roleService.getUserPolicies(user.id);
if (data.visibility === 'public' && data.channel == null) {
const sensitiveWords = meta.sensitiveWords;
if (this.utilityService.isKeyWordIncluded(data.cw ?? data.text ?? '', sensitiveWords)) {
data.visibility = 'home';
this.logger.warn('Visibility changed to home because sensitive words are included', { user: user.id, note: data });
} else if ((await this.roleService.getUserPolicies(user.id)).canPublicNote === false) {
} else if (policies.canPublicNote === false) {
data.visibility = 'home';
}
}
@ -379,6 +380,18 @@ export class NoteCreateService implements OnApplicationShutdown {
}
}
if (policies.canInitiateConversation === false) {
if (
mentionedUsers.some(u => u.id !== user.id)
|| (data.reply && data.reply.replyUserId !== user.id)
|| (data.visibility === 'specified' && data.visibleUsers?.some(u => u.id !== user.id))
|| (this.isQuote(data) && data.renote.userId !== user.id)
) {
this.logger.error('Request rejected because user has no permission to initiate conversation', { user: user.id, note: data });
throw new IdentifiableError('332dd91b-6a00-430a-ac39-620cf60ad34b', 'Notes including mentions, replies, or renotes are not allowed.');
}
}
tags = tags.filter(tag => Array.from(tag).length <= 128).splice(0, 32);
if (data.reply && (user.id !== data.reply.userId) && !mentionedUsers.some(u => u.id === data.reply!.userId)) {

View file

@ -36,6 +36,7 @@ export type RolePolicies = {
gtlAvailable: boolean;
ltlAvailable: boolean;
canPublicNote: boolean;
canInitiateConversation: boolean;
canCreateContent: boolean;
canUpdateContent: boolean;
canDeleteContent: boolean;
@ -69,6 +70,7 @@ export const DEFAULT_POLICIES: RolePolicies = {
gtlAvailable: true,
ltlAvailable: true,
canPublicNote: true,
canInitiateConversation: true,
canCreateContent: true,
canUpdateContent: true,
canDeleteContent: true,
@ -338,6 +340,7 @@ export class RoleService implements OnApplicationShutdown, OnModuleInit {
gtlAvailable: calc('gtlAvailable', vs => vs.some(v => v === true)),
ltlAvailable: calc('ltlAvailable', vs => vs.some(v => v === true)),
canPublicNote: calc('canPublicNote', vs => vs.some(v => v === true)),
canInitiateConversation: calc('canInitiateConversation', vs => vs.some(v => v === true)),
canCreateContent: calc('canCreateContent', vs => vs.some(v => v === true)),
canUpdateContent: calc('canUpdateContent', vs => vs.some(v => v === true)),
canDeleteContent: calc('canDeleteContent', vs => vs.some(v => v === true)),

View file

@ -393,7 +393,7 @@ export class UserEntityService implements OnModuleInit {
bannerBlurhash: user.bannerBlurhash,
isLocked: user.isLocked,
isSilenced: !policies?.canPublicNote,
isLimited: !(policies?.canCreateContent && policies.canUpdateContent && policies.canDeleteContent),
isLimited: !(policies?.canCreateContent && policies.canUpdateContent && policies.canDeleteContent && policies.canInitiateConversation),
isSuspended: user.isSuspended,
description: profile!.description,
location: profile!.location,