fix(webui): the workflow handlers act in the caller's org

The definitions query was built by hand, so it carried no org and the server
resolved the default one, while the enablement document read beside it and the
enablement write went to the default org outright. A caller in a non-default
org therefore read one org's definitions beside another org's enablement, and
toggled that other org's workflows.

workflowCollection now builds its query with controlplanerpc.QueryRequest, and
the three enablement reads and the write use org.OrgFromContext, so every one of
them names the org the principal put on the request context.
This commit is contained in:
sam committed 2026-09-30 07:33:16 +10:00
1 parent 13b583cdca
commit 5891d581cb
5 files changed
+200 -13

No files matched your search

+7 -8
View File
@@ -8,11 +8,11 @@ import (
"net/http"
"strings"
controlpb "github.com/samcharles93/archie-core/internal/contracts/controlplane/v1"
"github.com/samcharles93/archie-core/internal/domain/messaging"
"github.com/samcharles93/archie-core/internal/domain/org"
"github.com/samcharles93/archie-core/internal/domain/workflow/task"
"github.com/samcharles93/archie-core/internal/events"
"github.com/samcharles93/archie-core/internal/infrastructure/controlplanerpc"
)
const workflowDefinitionsKind = "workflow-definitions"
@@ -118,10 +118,9 @@ func (s *Server) handleWorkRequest(w http.ResponseWriter, r *http.Request) {
}
// enabledWorkflowInterface returns the interface workflow id declares, and
// whether it is defined and enabled for the default org -- the org every
// dashboard caller acts in until access resolves a caller's own. The interface
// is what the work-request handler checks a request's inputs against, so a task
// whose workflow declaration the request cannot satisfy is refused before it is
// whether it is defined and enabled for the caller's org. The interface is what
// the work-request handler checks a request's inputs against, so a task whose
// workflow declaration the request cannot satisfy is refused before it is
// admitted.
func (s *Server) enabledWorkflowInterface(ctx context.Context, id string) (task.WorkflowInterface, bool, error) {
entry, found, err := s.workflowEntry(ctx, id)
@@ -129,7 +128,7 @@ func (s *Server) enabledWorkflowInterface(ctx context.Context, id string) (task.
return task.WorkflowInterface{}, false, err
}
enablement, _, err := s.workflowEnablement(ctx)
if err != nil || !enablement.Enabled(org.DefaultOrgID, id) {
if err != nil || !enablement.Enabled(org.OrgFromContext(ctx), id) {
return task.WorkflowInterface{}, false, err
}
iface, err := task.ParseWorkflowInterface(entry.YAML)
@@ -158,7 +157,7 @@ func (s *Server) workflowCollection(ctx context.Context) (task.WorkflowDefinitio
if s.ControlPlane == nil {
return task.WorkflowDefinitionCollection{}, nil
}
response, err := s.ControlPlane.Query(ctx, &controlpb.QueryRequest{Kind: workflowDefinitionsKind})
response, err := s.ControlPlane.Query(ctx, controlplanerpc.QueryRequest(ctx, workflowDefinitionsKind))
if err != nil {
return task.WorkflowDefinitionCollection{}, err
}
@@ -186,7 +185,7 @@ func (s *Server) workflowDefinitions(ctx context.Context) ([]task.Definition, er
}
definitions := make([]task.Definition, 0, len(collection.Definitions))
for _, entry := range collection.Definitions {
definition := task.Definition{ID: entry.ID, Name: entry.ID, Origin: "database", Enabled: enablement.Enabled(org.DefaultOrgID, entry.ID), Repository: task.RepositoryRequired}
definition := task.Definition{ID: entry.ID, Name: entry.ID, Origin: "database", Enabled: enablement.Enabled(org.OrgFromContext(ctx), entry.ID), Repository: task.RepositoryRequired}
if iface, err := task.ParseWorkflowInterface(entry.YAML); err == nil {
definition.Inputs, definition.Repository = iface.Inputs, iface.RepositoryMode()
}