Smol optimisation for existing auth system

This commit is contained in:
Melody Becker 2025-03-28 16:16:30 +01:00
parent 57214ecde0
commit 66d6299295
Signed by: mstar
SSH key fingerprint: SHA256:9VAo09aaVNTWKzPW7Hq2LW+ox9OdwmTSHRoD4mlz1yI

View file

@ -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 {