mirror of
https://github.com/hanzoai/base.git
synced 2026-10-21 03:41:50 +00:00
Seven field types a CRM record needs, each one JSON column whose parts a filter, a sort or an aggregate reaches by name: currency (amountMicros, currencyCode), emails, phones, links, address, fullName and actor, plus rating. Empty is NULL. Emails, phones and links normalize what is typed and can keep their primary part unique. An actor is stamped by the server from the writer the save's context states; nothing a request sends sets it. Every field carries a label, description, icon and position, a select's values carry a label, colour and position, and a base collection carries a label, plural, icon, description and an opt-in history flag. Editor HTML is sanitized before it is written. A rule reads the caller's authority in the org it acts in: @request.auth.admin and @request.auth.role, off the token. An IAM-mirrored auth record is never saved, so its fields are now read off the record rather than joined against a row that is not there, which also makes @request.auth.org_id match for the first time. A host that opens one Base per org names it, and a token acting in another org is refused there.
47 lines
1.3 KiB
Go
47 lines
1.3 KiB
Go
package core
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/hanzoai/base/tools/types"
|
|
)
|
|
|
|
// Where a write came from. A request a person makes is manual, an org's own key
|
|
// is api, and the rest are named by the program that states them.
|
|
const (
|
|
ActorManual = "manual"
|
|
ActorAPI = "api"
|
|
ActorImport = "import"
|
|
ActorEmail = "email"
|
|
ActorCalendar = "calendar"
|
|
ActorWorkflow = "workflow"
|
|
ActorAgent = "agent"
|
|
ActorWebhook = "webhook"
|
|
ActorApplication = "application"
|
|
ActorSystem = "system"
|
|
)
|
|
|
|
// ActorSources is every source an actor may name.
|
|
var ActorSources = []string{
|
|
ActorManual, ActorAPI, ActorImport, ActorEmail, ActorCalendar,
|
|
ActorWorkflow, ActorAgent, ActorWebhook, ActorApplication, ActorSystem,
|
|
}
|
|
|
|
type actorKey struct{}
|
|
|
|
// WithActor states who is writing, for every record saved with the returned
|
|
// context: an actor field stamps it and a collection's history records it.
|
|
func WithActor(ctx context.Context, actor types.Actor) context.Context {
|
|
return context.WithValue(ctx, actorKey{}, actor)
|
|
}
|
|
|
|
// ActorFrom answers who is writing. A write nobody stated is the system's.
|
|
func ActorFrom(ctx context.Context) types.Actor {
|
|
if ctx != nil {
|
|
if a, ok := ctx.Value(actorKey{}).(types.Actor); ok && !a.IsZero() {
|
|
return a
|
|
}
|
|
}
|
|
return types.Actor{Source: ActorSystem, Name: "System"}
|
|
}
|