* 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
22 lines
313 B
Go
22 lines
313 B
Go
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
|
|
}
|