package statestore import ( "context" "io" "github.com/samcharles93/archie-core/internal/domain/org" "github.com/samcharles93/archie-core/internal/domain/storecontract" "github.com/samcharles93/archie-core/internal/domain/workflow/task" "github.com/samcharles93/archie-core/internal/logging" ) // orgTaskLogs serves a task's log only to a caller whose org holds the task. // Log files carry no org; the task row does, so a scoped read asks the task // store, which applies the caller's scope, and answers "no log" for a task the // caller cannot see. type orgTaskLogs struct { storecontract.TaskLogStore tasks interface { TaskByID(ctx context.Context, taskID int64) (*task.Task, error) } } func (l orgTaskLogs) visible(ctx context.Context, taskID int64) (bool, error) { if _, scoped := org.Scope(ctx); !scoped { return true, nil } t, err := l.tasks.TaskByID(ctx, taskID) return t != nil, err } func (l orgTaskLogs) TaskLog(ctx context.Context, taskID int64, attempt int, q logging.Query) (logging.TaskLogPage, error) { if ok, err := l.visible(ctx, taskID); !ok || err != nil { return logging.TaskLogPage{}, err } return l.TaskLogStore.TaskLog(ctx, taskID, attempt, q) } func (l orgTaskLogs) TaskLogContent(ctx context.Context, taskID int64, attempt int, w io.Writer) (bool, error) { if ok, err := l.visible(ctx, taskID); !ok || err != nil { return false, err } return l.TaskLogStore.TaskLogContent(ctx, taskID, attempt, w) }