Added better Tenanting

* Removed Tenanting from base objects as some models may be tenantless
* Admins are naturally not restricted by tenants
* Users *ARE* the tenants (for now) so they don't require a tenant ID
either
* User-owned models should all include the Tenanted model as their base
* Created .Create and .Save methods attached to base model
This commit is contained in:
🐙PiperYxzzy
2022-05-01 12:48:40 +02:00
parent 8ab45e2401
commit dd8d2a677d
3 changed files with 25 additions and 11 deletions

21
models/tenanted.go Normal file
View File

@@ -0,0 +1,21 @@
package models
import (
"errors"
"github.com/google/uuid"
"gorm.io/gorm"
)
type Tenanted struct {
Base
Tenant uuid.UUID `gorm:"index;<-:create"`
}
func (t *Tenanted) BeforeCreate(scope *gorm.DB) error {
if t.Tenant == uuid.Nil {
return errors.New("cannot save an untenanted object")
}
return nil
}