Skip to content

Commit

Permalink
Revert "fix: check update payload diff"
Browse files Browse the repository at this point in the history
This reverts commit 2dab9f5.
  • Loading branch information
rahmatrhd committed Sep 4, 2024
1 parent 99362a3 commit 2e4419c
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 19 deletions.
3 changes: 1 addition & 2 deletions api/handler/v1beta1/grant.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,7 @@ func (s *GRPCServer) UpdateGrant(ctx context.Context, req *guardianv1beta1.Updat
case errors.Is(err, grant.ErrGrantNotFound):
return nil, status.Error(codes.NotFound, err.Error())
case errors.Is(err, grant.ErrEmptyOwner),
errors.Is(err, domain.ErrInvalidGrantUpdateRequest),
errors.Is(err, domain.ErrGrantUpdateNoChanges):
errors.Is(err, domain.ErrInvalidGrantUpdateRequest):
return nil, status.Error(codes.InvalidArgument, err.Error())
default:
return nil, s.internalError(ctx, "failed to update grant: %v", err)
Expand Down
19 changes: 2 additions & 17 deletions domain/grant.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ var (
ErrDuplicateActiveGrant = errors.New("grant already exists")
ErrInvalidGrantRestoreParams = errors.New("invalid grant restore parameters")
ErrInvalidGrantUpdateRequest = errors.New("invalid grant update request")
ErrGrantUpdateNoChanges = errors.New("no changes in grant update request")
)

type Grant struct {
Expand Down Expand Up @@ -175,15 +174,9 @@ func (gu *GrantUpdate) Validate(current Grant) error {
return fmt.Errorf("can't update grant in status %q", current.Status)
}

anyFieldUpdated := false

// owner
if gu.Owner != nil {
if *gu.Owner == "" {
return errors.New("owner should not be empty")
} else if *gu.Owner != current.Owner {
anyFieldUpdated = true
}
if gu.Owner != nil && *gu.Owner == "" {
return errors.New("owner should not be empty")
}

// expiration date
Expand All @@ -200,14 +193,6 @@ func (gu *GrantUpdate) Validate(current Grant) error {
if gu.ExpirationDateReason == nil || *gu.ExpirationDateReason == "" {
return errors.New("expiration date reason is required")
}

if current.ExpirationDate == nil || (gu.ExpirationDate.Compare(*current.ExpirationDate) != 0) {
anyFieldUpdated = true
}
}

if !anyFieldUpdated {
return ErrGrantUpdateNoChanges
}

return nil
Expand Down

0 comments on commit 2e4419c

Please sign in to comment.