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:
21
models/tenanted.go
Normal file
21
models/tenanted.go
Normal 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
|
||||
}
|
||||
Reference in New Issue
Block a user