Skip to content
This repository has been archived by the owner on Aug 26, 2022. It is now read-only.

transfers/admin: allow status change of: Pending -> Reviewable #515

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion api/openapi-admin.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,10 @@ paths:
put:
tags: [Transfers]
summary: Update Transfer status
description: Updates a Transfer status for the specified userId and transferId
description: |+
Updates a Transfer status for the specified userId and transferId.
PENDING transfers may be updated to: CANCELED or REVIEWABLE.
REVIEWABLE transfers may be updated to: CANCELED or PENDING.
operationId: updateTransferStatus
parameters:
- name: transferId
Expand Down
2 changes: 1 addition & 1 deletion pkg/admin/api_transfers.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ type UpdateTransferStatusOpts struct {

/*
UpdateTransferStatus Update Transfer status
Updates a Transfer status for the specified userId and transferId
Updates a Transfer status for the specified userId and transferId. PENDING transfers may be updated to: CANCELED or REVIEWABLE. REVIEWABLE transfers may be updated to: CANCELED or PENDING.
* @param ctx _context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().
* @param transferId transferID that identifies the Transfer
* @param xUserID Unique userID set by an auth proxy or client to identify and isolate objects.
Expand Down
2 changes: 1 addition & 1 deletion pkg/admin/docs/TransfersApi.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ No authorization required

Update Transfer status

Updates a Transfer status for the specified userId and transferId
Updates a Transfer status for the specified userId and transferId. PENDING transfers may be updated to: CANCELED or REVIEWABLE. REVIEWABLE transfers may be updated to: CANCELED or PENDING.

### Required Parameters

Expand Down
9 changes: 5 additions & 4 deletions pkg/transfers/admin/approval.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,9 @@ func updateTransferStatus(logger log.Logger, repo transfers.Repository) http.Han
}
}

func validStatusTransistion(transferID string, incoming client.TransferStatus, proposed client.TransferStatus) error {
func validStatusTransistion(transferID string, current client.TransferStatus, proposed client.TransferStatus) error {
// We only allow a couple of transitions for Transfer statuses as there are several
switch incoming {
switch current {
case client.REVIEWABLE:
// Reviewable transfers can only be moved to pending or canceled after a human has confirmed
// the Transfer can be sent off.
Expand All @@ -77,9 +77,10 @@ func validStatusTransistion(transferID string, incoming client.TransferStatus, p
}
case client.PENDING:
// Pending transfers can only be canceled as if they're already sent we can't undo that.
if proposed == client.CANCELED {
switch proposed {
case client.CANCELED, client.REVIEWABLE:
return nil
}
}
return fmt.Errorf("unable to move transfer=%s from status=%s to status=%s", transferID, incoming, proposed)
return fmt.Errorf("unable to move transfer=%s from status=%s to status=%s", transferID, current, proposed)
}
5 changes: 5 additions & 0 deletions pkg/transfers/admin/approval_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,4 +77,9 @@ func TestAdmin__validStatusTransistion(t *testing.T) {
if err := validStatusTransistion(transferID, client.REVIEWABLE, client.PROCESSED); err == nil {
t.Error("expected error")
}

// Pending to Reviewable
if err := validStatusTransistion(transferID, client.PENDING, client.REVIEWABLE); err != nil {
t.Error(err)
}
}