Capture accumulated application, UI, CLI, regression tests and design documentation changes, including task project mapping and default CalDAV list naming. Keep deployment data, backups, local credentials and build artifacts out of Git. Move the Compose enrollment token to an ignored local environment file.
44 lines
1.6 KiB
Go
44 lines
1.6 KiB
Go
package store
|
|
|
|
import (
|
|
"github.com/google/uuid"
|
|
)
|
|
|
|
// CreateObjectInDomain records provenance atomically for the API's create,
|
|
// save, then bind workflow. It does not turn globally unique Objects into
|
|
// Domain-local identities, nor infer ownership of legacy unbound Objects.
|
|
func (s *Store) CreateObjectInDomain(domainUUID, kind string) (string, error) {
|
|
if err := s.ensureLocalDomain(domainUUID); err != nil {
|
|
return "", err
|
|
}
|
|
id := uuid.NewString()
|
|
tx, err := s.DB.Begin()
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
defer tx.Rollback()
|
|
if _, err := tx.Exec(`INSERT INTO objects(uuid,kind,created_at) VALUES(?,?,strftime('%s','now'))`, id, kind); err != nil {
|
|
return "", err
|
|
}
|
|
if _, err := tx.Exec(`INSERT INTO object_origins(object_uuid,domain_uuid,created_at) VALUES(?,?,strftime('%s','now'))`, id, domainUUID); err != nil {
|
|
return "", err
|
|
}
|
|
if err := tx.Commit(); err != nil {
|
|
return "", err
|
|
}
|
|
return id, nil
|
|
}
|
|
|
|
// ObjectInDomainAuthorityScope allows broad Domain grants only through a live
|
|
// binding, or through recorded creation provenance while there are NO bindings.
|
|
// Moving the last binding to another Domain never leaves source authority.
|
|
func (s *Store) ObjectInDomainAuthorityScope(domainUUID, objectUUID string) (bool, error) {
|
|
var allowed bool
|
|
err := s.DB.QueryRow(`SELECT EXISTS(SELECT 1 FROM objects o WHERE o.uuid=? AND (
|
|
EXISTS(SELECT 1 FROM paths p WHERE p.object_uuid=o.uuid AND p.domain_uuid=?) OR (
|
|
NOT EXISTS(SELECT 1 FROM paths p WHERE p.object_uuid=o.uuid) AND
|
|
EXISTS(SELECT 1 FROM object_origins x WHERE x.object_uuid=o.uuid AND x.domain_uuid=?))
|
|
))`, objectUUID, domainUUID, domainUUID).Scan(&allowed)
|
|
return allowed, err
|
|
}
|