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:
@@ -28,11 +28,12 @@ import (
|
||||
)
|
||||
|
||||
var (
|
||||
ErrCampaignMissingSources = errors.New("access review campaign missing scope sources")
|
||||
ErrCampaignInProgress = errors.New("access review campaign in progress")
|
||||
ErrCampaignPendingActions = errors.New("access review campaign pending actions")
|
||||
ErrCampaignCompleted = errors.New("access review campaign completed")
|
||||
ErrCampaignCancelled = errors.New("access review campaign cancelled")
|
||||
ErrCampaignMissingSources = errors.New("access review campaign missing scope sources")
|
||||
ErrCampaignNotDraft = errors.New("access review campaign not draft")
|
||||
ErrCampaignNotDeletable = errors.New("access review campaign not deletable")
|
||||
ErrCampaignNotPendingActions = errors.New("access review campaign not pending actions")
|
||||
ErrCampaignCompleted = errors.New("access review campaign completed")
|
||||
ErrCampaignCancelled = errors.New("access review campaign cancelled")
|
||||
)
|
||||
|
||||
type (
|
||||
@@ -40,11 +41,15 @@ type (
|
||||
CampaignID gid.GID
|
||||
}
|
||||
|
||||
CampaignInProgressError struct {
|
||||
CampaignNotDraftError struct {
|
||||
CampaignID gid.GID
|
||||
}
|
||||
|
||||
CampaignPendingActionsError struct {
|
||||
CampaignNotDeletableError struct {
|
||||
CampaignID gid.GID
|
||||
}
|
||||
|
||||
CampaignNotPendingActionsError struct {
|
||||
CampaignID gid.GID
|
||||
}
|
||||
|
||||
@@ -72,28 +77,46 @@ func (e *CampaignMissingSourcesError) Is(target error) bool {
|
||||
return target == ErrCampaignMissingSources
|
||||
}
|
||||
|
||||
func NewCampaignInProgressError(campaignID gid.GID) error {
|
||||
return &CampaignInProgressError{CampaignID: campaignID}
|
||||
func NewCampaignNotDraftError(campaignID gid.GID) error {
|
||||
return &CampaignNotDraftError{CampaignID: campaignID}
|
||||
}
|
||||
|
||||
func (e *CampaignInProgressError) Error() string {
|
||||
return fmt.Sprintf("access review campaign %q is in progress", e.CampaignID)
|
||||
func (e *CampaignNotDraftError) Error() string {
|
||||
return fmt.Sprintf("access review campaign %q is not in draft", e.CampaignID)
|
||||
}
|
||||
|
||||
func (e *CampaignInProgressError) Is(target error) bool {
|
||||
return target == ErrCampaignInProgress
|
||||
func (e *CampaignNotDraftError) Is(target error) bool {
|
||||
return target == ErrCampaignNotDraft
|
||||
}
|
||||
|
||||
func NewCampaignPendingActionsError(campaignID gid.GID) error {
|
||||
return &CampaignPendingActionsError{CampaignID: campaignID}
|
||||
func NewCampaignNotDeletableError(campaignID gid.GID) error {
|
||||
return &CampaignNotDeletableError{CampaignID: campaignID}
|
||||
}
|
||||
|
||||
func (e *CampaignPendingActionsError) Error() string {
|
||||
return fmt.Sprintf("access review campaign %q is pending actions", e.CampaignID)
|
||||
func (e *CampaignNotDeletableError) Error() string {
|
||||
return fmt.Sprintf(
|
||||
"access review campaign %q cannot be deleted unless it is draft or cancelled",
|
||||
e.CampaignID,
|
||||
)
|
||||
}
|
||||
|
||||
func (e *CampaignPendingActionsError) Is(target error) bool {
|
||||
return target == ErrCampaignPendingActions
|
||||
func (e *CampaignNotDeletableError) Is(target error) bool {
|
||||
return target == ErrCampaignNotDeletable
|
||||
}
|
||||
|
||||
func NewCampaignNotPendingActionsError(campaignID gid.GID) error {
|
||||
return &CampaignNotPendingActionsError{CampaignID: campaignID}
|
||||
}
|
||||
|
||||
func (e *CampaignNotPendingActionsError) Error() string {
|
||||
return fmt.Sprintf(
|
||||
"access review campaign %q cannot be closed unless it is pending actions",
|
||||
e.CampaignID,
|
||||
)
|
||||
}
|
||||
|
||||
func (e *CampaignNotPendingActionsError) Is(target error) bool {
|
||||
return target == ErrCampaignNotPendingActions
|
||||
}
|
||||
|
||||
func NewCampaignCompletedError(campaignID gid.GID) error {
|
||||
@@ -101,7 +124,7 @@ func NewCampaignCompletedError(campaignID gid.GID) error {
|
||||
}
|
||||
|
||||
func (e *CampaignCompletedError) Error() string {
|
||||
return fmt.Sprintf("access review campaign %q is completed", e.CampaignID)
|
||||
return fmt.Sprintf("access review campaign %q is already completed", e.CampaignID)
|
||||
}
|
||||
|
||||
func (e *CampaignCompletedError) Is(target error) bool {
|
||||
@@ -113,7 +136,7 @@ func NewCampaignCancelledError(campaignID gid.GID) error {
|
||||
}
|
||||
|
||||
func (e *CampaignCancelledError) Error() string {
|
||||
return fmt.Sprintf("access review campaign %q is cancelled", e.CampaignID)
|
||||
return fmt.Sprintf("access review campaign %q is already cancelled", e.CampaignID)
|
||||
}
|
||||
|
||||
func (e *CampaignCancelledError) Is(target error) bool {
|
||||
|
||||
Reference in New Issue
Block a user