The storage and wire contract already key resources by (org, kind), but no caller sent an org, so every request acted in the default org. The org now travels on the request context: webui's authorize middleware attaches the verified principal's org, and one request-constructor per wire shape (controlplanerpc's Query/History/Watch/CommandRequest) stamps it back, so a call site cannot send the wrong org and a new one cannot forget it. No behaviour change today: the shared token's principal is the default org's owner, no production path creates another org, and a context with no principal yields DefaultOrgID (what the server already derived from an empty org_id).
38 lines
1.3 KiB
Go
38 lines
1.3 KiB
Go
package controlplane
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
|
|
"github.com/samcharles93/archie-core/internal/config"
|
|
"github.com/samcharles93/archie-core/internal/domain/org"
|
|
"github.com/samcharles93/archie-core/internal/domain/workflow/task"
|
|
"github.com/samcharles93/archie-core/internal/infrastructure/controlplanerpc"
|
|
)
|
|
|
|
const WorkflowEnablementKind = "workflow-enablement"
|
|
|
|
func workflowEnablementDefinition() Definition {
|
|
return Definition{
|
|
Kind: WorkflowEnablementKind,
|
|
Title: "Workflow enablement",
|
|
Document: task.WorkflowEnablement{},
|
|
ApplyMode: "live",
|
|
Seed: func(config.Config) any { return task.WorkflowEnablement{Orgs: map[org.OrgID]task.OrgWorkflows{}} },
|
|
Validate: func(input []byte) error {
|
|
return validateAs(input, func(enablement task.WorkflowEnablement) error { return enablement.Validate() })
|
|
},
|
|
}
|
|
}
|
|
|
|
// WorkflowEnablement returns which workflows each org has disabled.
|
|
func (c *Client) WorkflowEnablement(ctx context.Context) (task.WorkflowEnablement, error) {
|
|
response, err := c.rpc.Query(ctx, controlplanerpc.QueryRequest(ctx, WorkflowEnablementKind))
|
|
if err != nil {
|
|
return task.WorkflowEnablement{}, controlplanerpc.ClientError(err)
|
|
}
|
|
var enablement task.WorkflowEnablement
|
|
err = json.Unmarshal(response.Resource.ValueJson, &enablement)
|
|
return enablement, err
|
|
}
|