(ctx context.Context, id string, actor ActorContext)
| 858 | } |
| 859 | |
| 860 | func (m *Service) publishTaskIntent(ctx context.Context, id string, actor ActorContext) (*Task, error) { |
| 861 | record, err := m.store.GetTask(ctx, id) |
| 862 | if err != nil { |
| 863 | return nil, err |
| 864 | } |
| 865 | if record.Status.Normalize() != TaskStatusDraft { |
| 866 | return nil, fmt.Errorf( |
| 867 | "%w: task %q cannot publish from %q", |
| 868 | ErrInvalidStatusTransition, |
| 869 | record.ID, |
| 870 | record.Status, |
| 871 | ) |
| 872 | } |
| 873 | |
| 874 | candidate := record |
| 875 | candidate.Status = TaskStatusPending |
| 876 | if err := m.ensureTaskExecutable(ctx, candidate); err != nil { |
| 877 | return nil, err |
| 878 | } |
| 879 | |
| 880 | record.Status = TaskStatusPending |
| 881 | record.UpdatedAt = m.now().UTC() |
| 882 | record.ClosedAt = time.Time{} |
| 883 | if err := m.store.UpdateTask(ctx, record); err != nil { |
| 884 | return nil, err |
| 885 | } |
| 886 | |
| 887 | reconciled, err := m.reconcileTaskCascade(ctx, record.ID) |
| 888 | if err != nil { |
| 889 | return nil, err |
| 890 | } |
| 891 | if err := m.recordTaskEvent(ctx, reconciled.ID, "", taskEventPublished, actor, publishedTaskPayload{ |
| 892 | PreviousStatus: TaskStatusDraft, |
| 893 | Status: reconciled.Status, |
| 894 | ApprovalState: reconciled.ApprovalState, |
| 895 | }); err != nil { |
| 896 | return nil, err |
| 897 | } |
| 898 | |
| 899 | return &reconciled, nil |
| 900 | } |
| 901 | |
| 902 | func (m *Service) transitionTaskApproval( |
| 903 | ctx context.Context, |
no test coverage detected