mirror of
https://github.com/hanzoai/base.git
synced 2026-10-21 03:41:50 +00:00
A new Base's users collection has a null createRule. On upgrade, a users collection whose five rules are still the ones the init migration wrote gets the same; any other rule set stays as the operator left it. People come from IAM and are mirrored for one request without being saved, so nothing that signs in creates these rows. Co-authored-by: Hanzo Dev <[email protected]>
39 lines
945 B
Go
39 lines
945 B
Go
package migrations
|
|
|
|
import (
|
|
"database/sql"
|
|
"errors"
|
|
|
|
"github.com/hanzoai/base/core"
|
|
)
|
|
|
|
// People come from IAM and are never rows here, so only superusers add a users
|
|
// row. A users collection whose five rules are still the ones the init migration
|
|
// wrote, createRule "" among them, gets a null createRule. Any other rule set was
|
|
// chosen by an operator and stays as it is.
|
|
func init() {
|
|
core.SystemMigrations.Register(func(txApp core.App) error {
|
|
users, err := txApp.FindCollectionByNameOrId("users")
|
|
if errors.Is(err, sql.ErrNoRows) {
|
|
return nil
|
|
}
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
owner := "id = @request.auth.id"
|
|
for _, rule := range []*string{users.ListRule, users.ViewRule, users.UpdateRule, users.DeleteRule} {
|
|
if rule == nil || *rule != owner {
|
|
return nil
|
|
}
|
|
}
|
|
if users.CreateRule == nil || *users.CreateRule != "" {
|
|
return nil
|
|
}
|
|
|
|
users.CreateRule = nil
|
|
|
|
return txApp.Save(users)
|
|
}, nil)
|
|
}
|