Use business campaign rules instead of status errors

Introduce accessreview.Campaign with draft/deletable predicates and
operation-specific client errors. Drop errUnlessDraftCampaign and
status-to-sentinel switches in the service layer.

Signed-off-by: Cursor Agent <cursoragent@cursor.com>

Co-authored-by: Bryan FRIMIN <bryan@frimin.fr>
This commit is contained in:
Cursor Agent
2026-07-27 13:37:49 +00:00
parent 5dca6bb883
commit 3f545652d5
5 changed files with 163 additions and 105 deletions

View File

@@ -761,13 +761,7 @@ func (r *mutationResolver) UpdateAccessReviewCampaign(ctx context.Context, input
return nil, gqlutils.NotFound(ctx, err)
}
if errorx.AnyOf(
err,
accessreview.ErrCampaignInProgress,
accessreview.ErrCampaignPendingActions,
accessreview.ErrCampaignCompleted,
accessreview.ErrCampaignCancelled,
) {
if errorx.AnyOf(err, accessreview.ErrCampaignNotDraft) {
return nil, gqlutils.Invalid(ctx, err)
}
@@ -793,6 +787,10 @@ func (r *mutationResolver) DeleteAccessReviewCampaign(ctx context.Context, input
return nil, gqlutils.NotFound(ctx, err)
}
if errors.Is(err, accessreview.ErrCampaignNotDeletable) {
return nil, gqlutils.Invalid(ctx, err)
}
r.logger.ErrorCtx(ctx, "cannot delete access review campaign", log.Error(err))
return nil, gqlutils.Internal(ctx)
@@ -815,10 +813,7 @@ func (r *mutationResolver) StartAccessReviewCampaign(ctx context.Context, input
if errorx.AnyOf(
err,
accessreview.ErrCampaignMissingSources,
accessreview.ErrCampaignInProgress,
accessreview.ErrCampaignPendingActions,
accessreview.ErrCampaignCompleted,
accessreview.ErrCampaignCancelled,
accessreview.ErrCampaignNotDraft,
) {
return nil, gqlutils.Invalid(ctx, err)
}
@@ -842,6 +837,10 @@ func (r *mutationResolver) CloseAccessReviewCampaign(ctx context.Context, input
campaign, err := r.accessReview.CloseCampaign(ctx, scope, input.AccessReviewCampaignID)
if err != nil {
if errors.Is(err, accessreview.ErrCampaignNotPendingActions) {
return nil, gqlutils.Invalid(ctx, err)
}
r.logger.ErrorCtx(ctx, "cannot close access review campaign", log.Error(err))
return nil, gqlutils.Internal(ctx)
@@ -895,13 +894,7 @@ func (r *mutationResolver) AddAccessReviewCampaignSource(ctx context.Context, in
return nil, gqlutils.NotFound(ctx, err)
}
if errorx.AnyOf(
err,
accessreview.ErrCampaignInProgress,
accessreview.ErrCampaignPendingActions,
accessreview.ErrCampaignCompleted,
accessreview.ErrCampaignCancelled,
) {
if errors.Is(err, accessreview.ErrCampaignNotDraft) {
return nil, gqlutils.Invalid(ctx, err)
}
@@ -931,6 +924,10 @@ func (r *mutationResolver) RemoveAccessReviewCampaignSource(ctx context.Context,
},
)
if err != nil {
if errors.Is(err, accessreview.ErrCampaignNotDraft) {
return nil, gqlutils.Invalid(ctx, err)
}
r.logger.ErrorCtx(ctx, "cannot remove scope source from access review campaign", log.Error(err))
return nil, gqlutils.Internal(ctx)