[backend/core] Disallow quoting of notes with specified visibility

This commit is contained in:
Laura Hausmann 2024-04-29 16:03:28 +02:00
parent f1a1716f16
commit fd0d6b4fea
No known key found for this signature in database
GPG key ID: D044E84C5BE01605

View file

@ -82,18 +82,27 @@ public class NoteService(
if (user.IsSuspended)
throw GracefulException.Forbidden("User is suspended");
var pureRenote = renote != null && text == null && poll == null && attachments is not { Count: > 0 };
if (renote != null && renote.User != user)
if (renote != null)
{
if (pureRenote && renote.Visibility > Note.NoteVisibility.Home)
throw GracefulException.UnprocessableEntity("You're not allowed to renote this note");
if (await db.Blockings.AnyAsync(p => p.Blockee == user && p.Blocker == renote.User))
throw GracefulException.Forbidden($"You are not allowed to interact with @{renote.User.Acct}");
}
var pureRenote = text == null && poll == null && attachments is not { Count: > 0 };
if (pureRenote && renote!.Visibility > visibility)
visibility = renote.Visibility;
if (renote.Visibility > Note.NoteVisibility.Followers)
{
var target = pureRenote ? "renote" : "quote";
throw GracefulException.UnprocessableEntity($"You're not allowed to {target} this note");
}
if (renote.User != user)
{
if (pureRenote && renote.Visibility > Note.NoteVisibility.Home)
throw GracefulException.UnprocessableEntity("You're not allowed to renote this note");
if (await db.Blockings.AnyAsync(p => p.Blockee == user && p.Blocker == renote.User))
throw GracefulException.Forbidden($"You are not allowed to interact with @{renote.User.Acct}");
}
if (pureRenote && renote.Visibility > visibility)
visibility = renote.Visibility;
}
var (mentionedUserIds, mentionedLocalUserIds, mentions, remoteMentions, splitDomainMapping) =
resolvedMentions ?? await ResolveNoteMentionsAsync(text);