From 66d6299295e5993a156e7851dab76396663952e7 Mon Sep 17 00:00:00 2001 From: mstar Date: Fri, 28 Mar 2025 16:16:30 +0100 Subject: [PATCH] Smol optimisation for existing auth system --- auth/checks.go | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/auth/checks.go b/auth/checks.go index 05deb12..319ad08 100644 --- a/auth/checks.go +++ b/auth/checks.go @@ -2,8 +2,9 @@ package auth import ( "git.mstar.dev/mstar/goutils/sliceutils" - "git.mstar.dev/mstar/linstrom/storage" "github.com/rs/zerolog/log" + + "git.mstar.dev/mstar/linstrom/storage" ) // Can actorId read the account with targetId? @@ -33,17 +34,14 @@ func (a *Authentication) CanReadAccount(actorId *string, targetId string) bool { return false } combined := storage.CollapseRolesIntoOne(roles...) - if sliceutils.Contains(combined.BlockedUsers, *actorId) { - return false - } - return true + return !sliceutils.Contains(combined.BlockedUsers, *actorId) } // Can actorId edit the account with targetId? // If actorId is nil, it is assumed to be an anonymous user trying to edit the target account // if targetId is nil, it is assumed that the actor is editing themselves func (a *Authentication) CanEditAccount(actorId *string, targetId *string) bool { - // FIXME: This entire function feels wrong, idk + // WARN: This entire function feels wrong, idk // Only the owner of an account should be able to edit said account's data // But how do moderation actions play with this? Do they count as edit or as something separate? if actorId == nil {