Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

B 20756 #13960

Open
wants to merge 35 commits into
base: main
Choose a base branch
from
Open

B 20756 #13960

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
cfd208d
Updating DTOD error handling
CoryKleinjanCACI Sep 30, 2024
e3e28af
Updating DTOD Error handling
CoryKleinjanCACI Sep 30, 2024
2687785
Updating dtod error handling
CoryKleinjanCACI Oct 1, 2024
b67efaf
Updating dtod error handling
CoryKleinjanCACI Oct 1, 2024
5a9ab07
Link to help desk shows up in new tab
CoryKleinjanCACI Oct 2, 2024
80af217
Adding test to estimatedWeightsProGear
CoryKleinjanCACI Oct 2, 2024
df47fbf
adding check for dtod error message to test
CoryKleinjanCACI Oct 3, 2024
ae91071
Moving DTOD error to constant value
CoryKleinjanCACI Oct 3, 2024
654bc44
Updating DTOD error message display
CoryKleinjanCACI Oct 9, 2024
dcfc59f
Updating error handling for shipment creation
CoryKleinjanCACI Oct 9, 2024
9862fae
Fixing check on error for shipmentForm
CoryKleinjanCACI Oct 9, 2024
e068311
Adding tests for specific error messages
CoryKleinjanCACI Oct 9, 2024
265c65c
Merge branch 'main' into B-20757
CoryKleinjanCACI Oct 9, 2024
da21f9e
Updating DTOD error message handling
CoryKleinjanCACI Oct 9, 2024
0b553a2
Updating non-dtod zip error handling
CoryKleinjanCACI Oct 10, 2024
b07f54d
Updating address creator tests
CoryKleinjanCACI Oct 10, 2024
15c8d29
Updating for linter error
CoryKleinjanCACI Oct 10, 2024
630cf81
Merge branch 'B-20757' into B-20756
CoryKleinjanCACI Oct 17, 2024
772737b
customer can now submit ppms when DTOD is down
CoryKleinjanCACI Oct 18, 2024
ce5d675
Merge branch 'main' into B-20756
CoryKleinjanCACI Oct 18, 2024
2f22647
Adding feature flag to simulate DTOD outage
CoryKleinjanCACI Oct 21, 2024
e1e0150
Updating simulated dtod outage
CoryKleinjanCACI Oct 21, 2024
6ae37f4
Fixing issue with IfMatch on ppm updates
CoryKleinjanCACI Oct 21, 2024
fd32dfa
Merge branch 'main' into B-20756
CoryKleinjanCACI Oct 21, 2024
69a87e8
Updating test calls
CoryKleinjanCACI Oct 21, 2024
fcde5d3
Merge branch 'B-20756' of https://github.com/transcom/mymove into B-2…
CoryKleinjanCACI Oct 21, 2024
4f6b045
Updating dtop distance test calls
CoryKleinjanCACI Oct 21, 2024
569de39
Updating DTOD tests
CoryKleinjanCACI Oct 21, 2024
45b9d59
Updating DTOD tests
CoryKleinjanCACI Oct 21, 2024
d1718aa
Updating DTOD tests
CoryKleinjanCACI Oct 21, 2024
1a91b3c
Adding nil check for session
CoryKleinjanCACI Oct 22, 2024
befb45e
Updating return value for DTOD
CoryKleinjanCACI Oct 22, 2024
ba66420
Merge branch 'main' into B-20756
CoryKleinjanCACI Oct 22, 2024
2a3389c
Merge branch 'main' into B-20756
CoryKleinjanCACI Oct 22, 2024
6738a1c
Merge branch 'main' into B-20756
CoryKleinjanCACI Oct 22, 2024
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
7 changes: 7 additions & 0 deletions .envrc
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,13 @@ export GOTENBERG_PORT=2000
# interactions
export DTOD_USE_MOCK=false

# Simulates the DTOD service being down
#
# This is enabled in local dev environments for playwright. It can be
# set to false during local dev if needed to test/debug DTOD
# interactions
export DTOD_SIMULATE_OUTAGE=false

# Client build flags
#
# Send error logs to the console for local development. Set to 'otel'
Expand Down
10 changes: 5 additions & 5 deletions pkg/auth/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -283,29 +283,29 @@ func SessionFromContext(ctx context.Context) *Session {

// IsServiceMember checks whether the authenticated user is a ServiceMember
func (s *Session) IsServiceMember() bool {
return s.ServiceMemberID != uuid.Nil
return s != nil && s.ServiceMemberID != uuid.Nil
}

// IsOfficeUser checks whether the authenticated user is an OfficeUser
func (s *Session) IsOfficeUser() bool {
return s.OfficeUserID != uuid.Nil
return s != nil && s.OfficeUserID != uuid.Nil
}

// IsAdminUser checks whether the authenticated user is an AdminUser
func (s *Session) IsAdminUser() bool {
return s.AdminUserID != uuid.Nil
return s != nil && s.AdminUserID != uuid.Nil
}

// IsSystemAdmin checks whether the authenticated admin user is a system admin
func (s *Session) IsSystemAdmin() bool {
role := "SYSTEM_ADMIN"
return s.IsAdminUser() && s.AdminUserRole == role
return s != nil && s.IsAdminUser() && s.AdminUserRole == role
}

// IsProgramAdmin checks whether the authenticated admin user is a program admin
func (s *Session) IsProgramAdmin() bool {
role := "PROGRAM_ADMIN"
return s.IsAdminUser() && s.AdminUserRole == role
return s != nil && s.IsAdminUser() && s.AdminUserRole == role
}

func SessionIDMiddleware(appnames ApplicationServername, sessionManagers AppSessionManagers) func(next http.Handler) http.Handler {
Expand Down
5 changes: 5 additions & 0 deletions pkg/cli/route.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ const (

// DTODUseMockFlag is the DTOD Use Mock Flag
DTODUseMockFlag string = "dtod-use-mock"

// DTODSimulateOutage is the DTOD Use Mock Flag
DTODSimulateOutageFlag string = "dtod-simulate-outage"
)

// InitRouteFlags initializes Route command line flags
Expand All @@ -42,6 +45,8 @@ func InitRouteFlags(flag *pflag.FlagSet) {
flag.String(DTODApiWSDLFlag, "", "WSDL for sending a SOAP request to DTOD")

flag.Bool(DTODUseMockFlag, false, "Whether to use a mocked version of DTOD")

flag.Bool(DTODSimulateOutageFlag, false, "Simulates the DTOD service being unnavailable")
}

// CheckRoute validates Route command line flags
Expand Down
20 changes: 20 additions & 0 deletions pkg/handlers/ghcapi/mto_shipment.go
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,11 @@ func (h CreateMTOShipmentHandler) Handle(params mtoshipmentops.CreateMTOShipment
Message: handlers.FmtString(err.Error()),
}
return mtoshipmentops.NewCreateMTOShipmentNotFound().WithPayload(&payload), err
case apperror.EventError:
payload := ghcmessages.Error{
Message: handlers.FmtString(err.Error()),
}
return mtoshipmentops.NewUpdateMTOShipmentBadRequest().WithPayload(&payload), err
case apperror.InvalidInputError:
payload := payloadForValidationError(
"Validation errors",
Expand Down Expand Up @@ -309,6 +314,11 @@ func (h UpdateShipmentHandler) Handle(params mtoshipmentops.UpdateMTOShipmentPar
switch err.(type) {
case apperror.NotFoundError:
return mtoshipmentops.NewUpdateMTOShipmentNotFound(), err
case apperror.EventError:
payload := ghcmessages.Error{
Message: handlers.FmtString(err.Error()),
}
return mtoshipmentops.NewUpdateMTOShipmentBadRequest().WithPayload(&payload), err
default:
msg := fmt.Sprintf("%v | Instance: %v", handlers.FmtString(err.Error()), h.GetTraceIDFromRequest(params.HTTPRequest))

Expand Down Expand Up @@ -338,6 +348,11 @@ func (h UpdateShipmentHandler) Handle(params mtoshipmentops.UpdateMTOShipmentPar
switch e := err.(type) {
case apperror.NotFoundError:
return mtoshipmentops.NewUpdateMTOShipmentNotFound(), err
case apperror.EventError:
payload := ghcmessages.Error{
Message: handlers.FmtString(err.Error()),
}
return mtoshipmentops.NewUpdateMTOShipmentBadRequest().WithPayload(&payload), err
case apperror.ForbiddenError:
msg := fmt.Sprintf("%v | Instance: %v", handlers.FmtString(err.Error()), h.GetTraceIDFromRequest(params.HTTPRequest))
return mtoshipmentops.NewUpdateMTOShipmentForbidden().WithPayload(
Expand Down Expand Up @@ -922,6 +937,11 @@ func (h RequestShipmentReweighHandler) Handle(params shipmentops.RequestShipment
switch err.(type) {
case apperror.NotFoundError:
return mtoshipmentops.NewUpdateMTOShipmentNotFound()
case apperror.EventError:
payload := ghcmessages.Error{
Message: handlers.FmtString(err.Error()),
}
return mtoshipmentops.NewUpdateMTOShipmentBadRequest().WithPayload(&payload)
default:
msg := fmt.Sprintf("%v | Instance: %v", handlers.FmtString(err.Error()), h.GetTraceIDFromRequest(params.HTTPRequest))

Expand Down
14 changes: 14 additions & 0 deletions pkg/handlers/internalapi/mto_shipment.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,13 @@ func (h CreateMTOShipmentHandler) Handle(params mtoshipmentops.CreateMTOShipment
h.GetTraceIDFromRequest(params.HTTPRequest),
),
), err
case apperror.EventError:
return mtoshipmentops.NewUpdateMTOShipmentBadRequest().WithPayload(
payloads.ClientError(handlers.InternalServerErrMessage,
err.Error(),
h.GetTraceIDFromRequest(params.HTTPRequest),
),
), err
case apperror.InvalidInputError:
return mtoshipmentops.
NewCreateMTOShipmentUnprocessableEntity().
Expand Down Expand Up @@ -167,6 +174,13 @@ func (h UpdateMTOShipmentHandler) Handle(params mtoshipmentops.UpdateMTOShipment
h.GetTraceIDFromRequest(params.HTTPRequest),
),
), err
case apperror.EventError:
return mtoshipmentops.NewUpdateMTOShipmentBadRequest().WithPayload(
payloads.ClientError(handlers.InternalServerErrMessage,
err.Error(),
h.GetTraceIDFromRequest(params.HTTPRequest),
),
), err
case apperror.InvalidInputError:
return mtoshipmentops.
NewUpdateMTOShipmentUnprocessableEntity().
Expand Down
4 changes: 2 additions & 2 deletions pkg/models/ppm_shipment.go
Original file line number Diff line number Diff line change
Expand Up @@ -274,9 +274,9 @@ func (p PPMShipment) Validate(_ *pop.Connection) (*validate.Errors, error) {
&OptionalPoundIsNonNegative{Name: "EstimatedWeight", Field: p.EstimatedWeight},
&OptionalPoundIsNonNegative{Name: "ProGearWeight", Field: p.ProGearWeight},
&OptionalPoundIsNonNegative{Name: "SpouseProGearWeight", Field: p.SpouseProGearWeight},
&OptionalCentIsPositive{Name: "EstimatedIncentive", Field: p.EstimatedIncentive},
&OptionalCentIsNotNegative{Name: "EstimatedIncentive", Field: p.EstimatedIncentive},
&OptionalCentIsPositive{Name: "FinalIncentive", Field: p.FinalIncentive},
&OptionalCentIsPositive{Name: "AdvanceAmountRequested", Field: p.AdvanceAmountRequested},
&OptionalCentIsNotNegative{Name: "AdvanceAmountRequested", Field: p.AdvanceAmountRequested},
&OptionalStringInclusion{Name: "AdvanceStatus", List: AllowedPPMAdvanceStatuses, Field: (*string)(p.AdvanceStatus)},
&OptionalCentIsPositive{Name: "AdvanceAmountReceived", Field: p.AdvanceAmountReceived},
&OptionalStringInclusion{Name: "SITLocation", List: AllowedSITLocationTypes, Field: (*string)(p.SITLocation)},
Expand Down
8 changes: 4 additions & 4 deletions pkg/models/ppm_shipment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,9 @@ func (suite *ModelSuite) TestPPMShipmentValidation() {
EstimatedWeight: models.PoundPointer(unit.Pound(-1)),
ProGearWeight: models.PoundPointer(unit.Pound(-1)),
SpouseProGearWeight: models.PoundPointer(unit.Pound(-1)),
EstimatedIncentive: models.CentPointer(unit.Cents(0)),
EstimatedIncentive: models.CentPointer(unit.Cents(-1)),
FinalIncentive: models.CentPointer(unit.Cents(0)),
AdvanceAmountRequested: models.CentPointer(unit.Cents(0)),
AdvanceAmountRequested: models.CentPointer(unit.Cents(-1)),
AdvanceStatus: &blankAdvanceStatus,
AdvanceAmountReceived: models.CentPointer(unit.Cents(0)),
SITLocation: &blankSITLocation,
Expand All @@ -97,9 +97,9 @@ func (suite *ModelSuite) TestPPMShipmentValidation() {
"estimated_weight": {"-1 is less than zero."},
"pro_gear_weight": {"-1 is less than zero."},
"spouse_pro_gear_weight": {"-1 is less than zero."},
"estimated_incentive": {"EstimatedIncentive must be greater than zero, got: 0."},
"estimated_incentive": {"EstimatedIncentive cannot be negative, got: -1."},
"final_incentive": {"FinalIncentive must be greater than zero, got: 0."},
"advance_amount_requested": {"AdvanceAmountRequested must be greater than zero, got: 0."},
"advance_amount_requested": {"AdvanceAmountRequested cannot be negative, got: -1."},
"advance_status": {fmt.Sprintf("AdvanceStatus is not in the list [%s].", validPPMShipmentAdvanceStatuses)},
"advance_amount_received": {"AdvanceAmountReceived must be greater than zero, got: 0."},
"sitlocation": {fmt.Sprintf("SITLocation is not in the list [%s].", validSITLocations)},
Expand Down
5 changes: 3 additions & 2 deletions pkg/models/us_post_region_city.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@ package models

import (
"database/sql"
"fmt"
"time"

"github.com/gobuffalo/pop/v6"
"github.com/gobuffalo/validate/v3"
"github.com/gobuffalo/validate/v3/validators"
"github.com/gofrs/uuid"

"github.com/transcom/mymove/pkg/apperror"
)

// UsPostRegionCity represents postal region information retrieved from TRDM
Expand Down Expand Up @@ -49,7 +50,7 @@ func FindCountyByZipCode(db *pop.Connection, zipCode string) (string, error) {
if err != nil {
switch err {
case sql.ErrNoRows:
return "", fmt.Errorf("No county found for provided zip code %s", zipCode)
return "", apperror.NewEventError("No county found for provided zip code "+zipCode+".", err)
default:
return "", err
}
Expand Down
15 changes: 15 additions & 0 deletions pkg/models/validators.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,21 @@ func (v *OptionalCentIsPositive) IsValid(errors *validate.Errors) {
}
}

// OptionalCentIsNotNegative adds an error if the Field is less than or equal to zero
type OptionalCentIsNotNegative struct {
Name string
Field *unit.Cents
}

// IsValid adds an error if the Field is less than or equal to zero
func (v *OptionalCentIsNotNegative) IsValid(errors *validate.Errors) {
if v.Field != nil {
if *v.Field < 0 {
errors.Add(validators.GenerateKey(v.Name), fmt.Sprintf("%s cannot be negative, got: %d.", v.Name, *v.Field))
}
}
}

// OptionalPoundIsNonNegative adds an error if the Field is less than zero
type OptionalPoundIsNonNegative struct {
Name string
Expand Down
2 changes: 2 additions & 0 deletions pkg/notifications/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@ package notifications
const OneSourceTransportationOfficeLink = "https://installations.militaryonesource.mil/search?program-service=2/view-by=ALL"
const MyMoveLink = "https://my.move.mil/"
const WashingtonHQServicesLink = "https://www.esd.whs.mil"

const DtodErrorMessage = "We are unable to calculate your distance. It may be that you have entered an invalid ZIP Code, or the system that calculates distance (DTOD) may be down. Please check your ZIP Code to ensure it was entered correctly and is not a PO Box."
Original file line number Diff line number Diff line change
Expand Up @@ -510,6 +510,10 @@ func (s *ServiceItemParamKeyData) ServiceParamValue(appCtx appcontext.AppContext
if lookup, ok := s.lookups[key]; ok {
value, err := lookup.lookup(appCtx, s)
if err != nil {
switch err.(type) {
case apperror.EventError:
return "", err
}
return "", fmt.Errorf(" failed ServiceParamValue %sLookup with error %w", key, err)
}
// Save param value to cache
Expand Down
4 changes: 2 additions & 2 deletions pkg/route/dtod_planner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ func (suite *GHCTestSuite) TestDTODZipTransitDistance() {
},
})

plannerMileage := NewDTODZip5Distance(fakeUsername, fakePassword, testSoapClient)
plannerMileage := NewDTODZip5Distance(fakeUsername, fakePassword, testSoapClient, false)
planner := NewDTODPlanner(plannerMileage)
distance, err := planner.ZipTransitDistance(suite.AppContextForTest(), "30907", "30301")
suite.NoError(err)
Expand All @@ -123,7 +123,7 @@ func (suite *GHCTestSuite) TestDTODZipTransitDistance() {
mock.Anything,
).Return(soapResponseForDistance("150.33"), errors.New("some error"))

plannerMileage := NewDTODZip5Distance(fakeUsername, fakePassword, testSoapClient)
plannerMileage := NewDTODZip5Distance(fakeUsername, fakePassword, testSoapClient, false)
planner := NewDTODPlanner(plannerMileage)
distance, err := planner.ZipTransitDistance(suite.AppContextForTest(), "30907", "30901")
suite.Error(err)
Expand Down
Loading
Loading