More API stuff. Lots of bleh. Really boring

Also need to figure out a somewhat generic way for "requires ownership"
permission and then a combinator for permissions
This commit is contained in:
Melody Becker 2024-11-04 16:25:39 +01:00
parent ffe3cf32ae
commit 1bb6cd8a70
8 changed files with 438 additions and 300 deletions

View file

@ -4,6 +4,7 @@ import (
"crypto/ed25519"
"crypto/rand"
"errors"
"fmt"
"strings"
"time"
@ -57,7 +58,7 @@ type Account struct {
// An unordered list since the owner can freely set it
// Examples: [she her], [it they its them] or, if you want to go fancy, [this is super serious]
Gender []string `gorm:"serializer:json"`
// The roles assocciated with an account
// The roles assocciated with an account. Values are the names of the roles
Roles []string `gorm:"serializer:json"`
// --- And internal account stuff ---
@ -320,6 +321,12 @@ func (s *Storage) NewEmptyAccount() (*Account, error) {
}
log.Debug().Msg("Random webauthn id for new account created")
acc.ID = uuid.NewString()
accountRole, err := s.NewEmptyRole(acc.ID)
if err != nil {
return nil, fmt.Errorf("failed to generate account role for new account: %w", err)
}
acc.WebAuthnId = data
acc.Followers = []string{}
acc.Tags = []string{}
@ -328,6 +335,7 @@ func (s *Storage) NewEmptyAccount() (*Account, error) {
acc.CustomFields = []uint{}
acc.IdentifiesAs = []Being{}
acc.PasskeyCredentials = []webauthn.Credential{}
acc.Roles = []string{DefaultUserRole.Name, accountRole.Name}
log.Debug().Any("account", &acc).Msg("Saving new account in db")
res := s.db.Save(&acc)
if res.Error != nil {