Remove accessreview Campaign wrapper type
Apply draft and lifecycle checks on loaded coredata records directly in the campaign service. Signed-off-by: Cursor Agent <cursoragent@cursor.com> Co-authored-by: Bryan FRIMIN <bryan@frimin.fr>
This commit is contained in:
@@ -1,59 +0,0 @@
|
||||
// Copyright (c) 2026 Probo Inc <hello@probo.com>.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
|
||||
package accessreview
|
||||
|
||||
import (
|
||||
"go.probo.inc/probo/pkg/coredata"
|
||||
"go.probo.inc/probo/pkg/gid"
|
||||
)
|
||||
|
||||
// Campaign is the business view of a loaded access review campaign record.
|
||||
type Campaign struct {
|
||||
ID gid.GID
|
||||
status coredata.AccessReviewCampaignStatus
|
||||
}
|
||||
|
||||
func NewCampaignFromCoredata(record *coredata.AccessReviewCampaign) Campaign {
|
||||
return Campaign{
|
||||
ID: record.ID,
|
||||
status: record.Status,
|
||||
}
|
||||
}
|
||||
|
||||
func (c Campaign) IsDraft() bool {
|
||||
return c.status == coredata.AccessReviewCampaignStatusDraft
|
||||
}
|
||||
|
||||
func (c Campaign) IsDeletable() bool {
|
||||
return c.IsDraft() || c.status == coredata.AccessReviewCampaignStatusCancelled
|
||||
}
|
||||
|
||||
func (c Campaign) IsPendingActions() bool {
|
||||
return c.status == coredata.AccessReviewCampaignStatusPendingActions
|
||||
}
|
||||
|
||||
func (c Campaign) IsCompleted() bool {
|
||||
return c.status == coredata.AccessReviewCampaignStatusCompleted
|
||||
}
|
||||
|
||||
func (c Campaign) IsCancelled() bool {
|
||||
return c.status == coredata.AccessReviewCampaignStatusCancelled
|
||||
}
|
||||
@@ -158,9 +158,8 @@ func (s *Service) UpdateCampaign(
|
||||
return fmt.Errorf("cannot load campaign: %w", err)
|
||||
}
|
||||
|
||||
biz := NewCampaignFromCoredata(campaign)
|
||||
if !biz.IsDraft() {
|
||||
return NewCampaignNotDraftError(biz.ID)
|
||||
if campaign.Status != coredata.AccessReviewCampaignStatusDraft {
|
||||
return NewCampaignNotDraftError(campaign.ID)
|
||||
}
|
||||
|
||||
if req.Name != nil && *req.Name != nil {
|
||||
@@ -210,9 +209,9 @@ func (s *Service) DeleteCampaign(
|
||||
return fmt.Errorf("cannot load campaign: %w", err)
|
||||
}
|
||||
|
||||
biz := NewCampaignFromCoredata(campaign)
|
||||
if !biz.IsDeletable() {
|
||||
return NewCampaignNotDeletableError(biz.ID)
|
||||
if campaign.Status != coredata.AccessReviewCampaignStatusDraft &&
|
||||
campaign.Status != coredata.AccessReviewCampaignStatusCancelled {
|
||||
return NewCampaignNotDeletableError(campaign.ID)
|
||||
}
|
||||
|
||||
if err := campaign.Delete(ctx, conn, scope); err != nil {
|
||||
@@ -242,9 +241,8 @@ func (s *Service) AddCampaignSource(
|
||||
return fmt.Errorf("cannot load campaign: %w", err)
|
||||
}
|
||||
|
||||
biz := NewCampaignFromCoredata(campaign)
|
||||
if !biz.IsDraft() {
|
||||
return NewCampaignNotDraftError(biz.ID)
|
||||
if campaign.Status != coredata.AccessReviewCampaignStatusDraft {
|
||||
return NewCampaignNotDraftError(campaign.ID)
|
||||
}
|
||||
if err := source.LoadByID(ctx, conn, scope, req.AccessReviewSourceID); err != nil {
|
||||
if errors.Is(err, coredata.ErrResourceNotFound) {
|
||||
@@ -290,9 +288,8 @@ func (s *Service) RemoveCampaignSource(
|
||||
return fmt.Errorf("cannot load campaign: %w", err)
|
||||
}
|
||||
|
||||
biz := NewCampaignFromCoredata(campaign)
|
||||
if !biz.IsDraft() {
|
||||
return NewCampaignNotDraftError(biz.ID)
|
||||
if campaign.Status != coredata.AccessReviewCampaignStatusDraft {
|
||||
return NewCampaignNotDraftError(campaign.ID)
|
||||
}
|
||||
|
||||
campaignSource := &coredata.AccessReviewCampaignSource{}
|
||||
@@ -400,9 +397,8 @@ func (s *Service) StartCampaign(
|
||||
return fmt.Errorf("cannot load campaign: %w", err)
|
||||
}
|
||||
|
||||
biz := NewCampaignFromCoredata(campaign)
|
||||
if !biz.IsDraft() {
|
||||
return NewCampaignNotDraftError(biz.ID)
|
||||
if campaign.Status != coredata.AccessReviewCampaignStatusDraft {
|
||||
return NewCampaignNotDraftError(campaign.ID)
|
||||
}
|
||||
|
||||
var campaignSources coredata.AccessReviewCampaignSources
|
||||
@@ -455,9 +451,8 @@ func (s *Service) CloseCampaign(
|
||||
return fmt.Errorf("cannot load campaign: %w", err)
|
||||
}
|
||||
|
||||
biz := NewCampaignFromCoredata(campaign)
|
||||
if !biz.IsPendingActions() {
|
||||
return NewCampaignNotPendingActionsError(biz.ID)
|
||||
if campaign.Status != coredata.AccessReviewCampaignStatusPendingActions {
|
||||
return NewCampaignNotPendingActionsError(campaign.ID)
|
||||
}
|
||||
|
||||
entries := coredata.AccessReviewEntries{}
|
||||
@@ -581,13 +576,12 @@ func (s *Service) CancelCampaign(
|
||||
return fmt.Errorf("cannot load campaign: %w", err)
|
||||
}
|
||||
|
||||
biz := NewCampaignFromCoredata(campaign)
|
||||
if biz.IsCompleted() {
|
||||
return NewCampaignCompletedError(biz.ID)
|
||||
if campaign.Status == coredata.AccessReviewCampaignStatusCompleted {
|
||||
return NewCampaignCompletedError(campaign.ID)
|
||||
}
|
||||
|
||||
if biz.IsCancelled() {
|
||||
return NewCampaignCancelledError(biz.ID)
|
||||
if campaign.Status == coredata.AccessReviewCampaignStatusCancelled {
|
||||
return NewCampaignCancelledError(campaign.ID)
|
||||
}
|
||||
|
||||
now := time.Now()
|
||||
|
||||
Reference in New Issue
Block a user