[backend/federation] Respect UserSettings.AlwaysMarkSensitive

This commit is contained in:
Laura Hausmann 2024-07-11 23:24:48 +02:00
parent 8f508d0c72
commit 3ac63e1510
No known key found for this signature in database
GPG key ID: D044E84C5BE01605
2 changed files with 13 additions and 4 deletions

View file

@ -589,6 +589,9 @@ public class User : IEntity
HasRenoted(note) ||
HasVoted(note);
[Projectable]
public bool ProhibitInteractionWith(User user) => IsBlocking(user) || IsBlockedBy(user);
public User WithPrecomputedBlockStatus(bool blocking, bool blockedBy)
{
PrecomputedIsBlocking = blocking;

View file

@ -112,18 +112,16 @@ public class NoteService(
var (mentionedUserIds, mentionedLocalUserIds, mentions, remoteMentions, splitDomainMapping) =
resolvedMentions ?? await ResolveNoteMentionsAsync(text);
// ReSharper disable EntityFramework.UnsupportedServerSideFunctionCall
// ReSharper disable once EntityFramework.UnsupportedServerSideFunctionCall
if (mentionedUserIds.Count > 0)
{
var blockAcct = await db.Users
.Where(p => mentionedUserIds.Contains(p.Id) &&
(p.IsBlocking(user) || p.IsBlockedBy(user)))
.Where(p => mentionedUserIds.Contains(p.Id) && p.ProhibitInteractionWith(user))
.Select(p => p.Acct)
.FirstOrDefaultAsync();
if (blockAcct != null)
throw GracefulException.Forbidden($"You're not allowed to interact with @{blockAcct}");
}
// ReSharper restore EntityFramework.UnsupportedServerSideFunctionCall
List<MfmNode>? nodes = null;
if (text != null && string.IsNullOrWhiteSpace(text))
@ -146,6 +144,14 @@ public class NoteService(
if ((user.UserSettings?.PrivateMode ?? false) && visibility < Note.NoteVisibility.Followers)
visibility = Note.NoteVisibility.Followers;
// Enforce UserSettings.AlwaysMarkSensitive, if configured
if ((user.UserSettings?.AlwaysMarkSensitive ?? false) && (attachments?.Any(p => !p.IsSensitive) ?? false))
{
foreach (var driveFile in attachments.Where(p => !p.IsSensitive)) driveFile.IsSensitive = true;
await db.DriveFiles.Where(p => attachments.Select(a => a.Id).Contains(p.Id) && !p.IsSensitive)
.ExecuteUpdateAsync(p => p.SetProperty(i => i.IsSensitive, _ => true));
}
var tags = ResolveHashtags(text, asNote);
var mastoReplyUserId = reply?.UserId != user.Id