Add username validation function for non-scripted actors

This commit is contained in:
Melody Becker 2025-04-16 16:43:37 +02:00
parent 087728cfe5
commit b00f5e9777
Signed by: mstar
SSH key fingerprint: SHA256:9VAo09aaVNTWKzPW7Hq2LW+ox9OdwmTSHRoD4mlz1yI
2 changed files with 27 additions and 1 deletions

View file

@ -8,5 +8,6 @@ const (
// where multiple releases in a day are required // where multiple releases in a day are required
Version = "0.0.1 pre-alpha" Version = "0.0.1 pre-alpha"
// Username for the server actor // Username for the server actor
ServerActorName = "server.actor" ServerActorName = "server.actor"
FeedUsernameSuffix = "-feed"
) )

25
shared/validation.go Normal file
View file

@ -0,0 +1,25 @@
package shared
import (
"strings"
"git.mstar.dev/mstar/goutils/sliceutils"
)
var forbiddenUsernames = []string{
"server.actor",
"feed",
}
// Reports whether a given user name is valid (for non-internal systems)
//
// TODO: Include compat check for Mastodon?
func ValidateUsername(username string) bool {
if strings.HasSuffix(username, FeedUsernameSuffix) {
return false
}
if sliceutils.Contains(forbiddenUsernames, username) {
return false
}
return true
}