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 21036 enforce dodid and emplid main #13674

Merged
merged 20 commits into from
Sep 20, 2024
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
4367faf
add yup validation for edipi and emplid
cameroncaci Sep 5, 2024
2887cc3
enforce requirement on backend and some cleanup
cameroncaci Sep 6, 2024
3ee8661
adjust yup error
cameroncaci Sep 6, 2024
a9ed198
change capitalization
cameroncaci Sep 6, 2024
2d459eb
Merge branch 'main' into b-21036-enforce-dodid-and-emplid-main
cameroncaci Sep 10, 2024
055776a
Merge branch 'main' into b-21036-enforce-dodid-and-emplid-main
cameroncaci Sep 11, 2024
073ca03
Merge remote-tracking branch 'origin/MAIN-B-21038' into b-21036-enfor…
cameroncaci Sep 13, 2024
1570575
Merge branch 'b-21036-enforce-dodid-and-emplid-main' of github.com:tr…
cameroncaci Sep 13, 2024
daa946e
Merge branch 'main' into b-21036-enforce-dodid-and-emplid-main
cameroncaci Sep 19, 2024
5c4d48f
Merge branch 'main' into b-21036-enforce-dodid-and-emplid-main
cameroncaci Sep 19, 2024
3eaba66
Merge remote-tracking branch 'origin/main' into b-21036-enforce-dodid…
cameroncaci Sep 19, 2024
9ae3f96
catch up main to int test
cameroncaci Sep 19, 2024
51c6f9f
server gen
cameroncaci Sep 19, 2024
60344bc
prettier
cameroncaci Sep 19, 2024
52ce658
Merge branch 'main' into b-21036-enforce-dodid-and-emplid-main
cameroncaci Sep 19, 2024
c852584
Revert "server gen"
cameroncaci Sep 20, 2024
2d63281
Merge branch 'main' into b-21036-enforce-dodid-and-emplid-main
cameroncaci Sep 20, 2024
3d66dcb
Merge branch 'main' into b-21036-enforce-dodid-and-emplid-main
cameroncaci Sep 20, 2024
35bc758
Merge branch 'main' into b-21036-enforce-dodid-and-emplid-main
cameroncaci Sep 20, 2024
55942b7
Merge branch 'main' into b-21036-enforce-dodid-and-emplid-main
cameroncaci Sep 20, 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
18 changes: 10 additions & 8 deletions pkg/gen/ghcapi/embedded_spec.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 19 additions & 2 deletions pkg/gen/ghcmessages/create_customer_payload.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions pkg/gen/ghcmessages/customer.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

51 changes: 22 additions & 29 deletions pkg/handlers/ghcapi/customer.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,6 @@ func (h CreateCustomerWithOktaOptionHandler) Handle(params customercodeop.Create
payload := params.Body
var err error
var serviceMembers []models.ServiceMember
var edipi *string
var dodidUniqueFeatureFlag bool

// evaluating feature flag to see if we need to check if the DODID exists already
Expand All @@ -177,30 +176,31 @@ func (h CreateCustomerWithOktaOptionHandler) Handle(params customercodeop.Create
}

if dodidUniqueFeatureFlag {
if payload.Edipi == nil || *payload.Edipi == "" {
edipi = nil
} else {
query := `SELECT service_members.edipi
query := `SELECT service_members.edipi
FROM service_members
WHERE service_members.edipi = $1`
err := appCtx.DB().RawQuery(query, payload.Edipi).All(&serviceMembers)
if err != nil {
errorMsg := apperror.NewBadDataError("error when checking for existing service member")
payload := payloadForValidationError("Unable to create a customer", errorMsg.Error(), h.GetTraceIDFromRequest(params.HTTPRequest), validate.NewErrors())
return customercodeop.NewCreateCustomerWithOktaOptionUnprocessableEntity().WithPayload(payload), errorMsg
} else if len(serviceMembers) > 0 {
errorMsg := apperror.NewConflictError(h.GetTraceIDFromRequest(params.HTTPRequest), "Service member with this DODID already exists. Please use a different DODID number.")
payload := payloadForValidationError("Unable to create a customer", errorMsg.Error(), h.GetTraceIDFromRequest(params.HTTPRequest), validate.NewErrors())
return customercodeop.NewCreateCustomerWithOktaOptionUnprocessableEntity().WithPayload(payload), errorMsg
}
err := appCtx.DB().RawQuery(query, payload.Edipi).All(&serviceMembers)
if err != nil {
errorMsg := apperror.NewBadDataError("error when checking for existing service member")
payload := payloadForValidationError("Unable to create a customer", errorMsg.Error(), h.GetTraceIDFromRequest(params.HTTPRequest), validate.NewErrors())
return customercodeop.NewCreateCustomerWithOktaOptionUnprocessableEntity().WithPayload(payload), errorMsg
} else if len(serviceMembers) > 0 {
errorMsg := apperror.NewConflictError(h.GetTraceIDFromRequest(params.HTTPRequest), "Service member with this DODID already exists. Please use a different DODID number.")
payload := payloadForValidationError("Unable to create a customer", errorMsg.Error(), h.GetTraceIDFromRequest(params.HTTPRequest), validate.NewErrors())
return customercodeop.NewCreateCustomerWithOktaOptionUnprocessableEntity().WithPayload(payload), errorMsg
}
}

if len(serviceMembers) == 0 {
edipi = params.Body.Edipi
// Endpoint specific EDIPI and EMPLID check
// The following validation currently is only intended for the customer creation
// conducted by an office user such as the Service Counselor
if payload.Affiliation != nil && *payload.Affiliation == ghcmessages.AffiliationCOASTGUARD {
// EMPLID cannot be null
if payload.Emplid == nil {
errorMsg := apperror.NewConflictError(h.GetTraceIDFromRequest(params.HTTPRequest), "Service members from the Coast Guard require an EMPLID for creation.")
payload := payloadForValidationError("Unable to create a customer", errorMsg.Error(), h.GetTraceIDFromRequest(params.HTTPRequest), validate.NewErrors())
return customercodeop.NewCreateCustomerWithOktaOptionUnprocessableEntity().WithPayload(payload), errorMsg
}
} else {
// If the feature flag is not enabled, we will just set the dodid and continue
edipi = params.Body.Edipi
}

var newServiceMember models.ServiceMember
Expand Down Expand Up @@ -250,18 +250,11 @@ func (h CreateCustomerWithOktaOptionHandler) Handle(params customercodeop.Create
residentialAddress := addressModelFromPayload(&payload.ResidentialAddress.Address)
backupMailingAddress := addressModelFromPayload(&payload.BackupMailingAddress.Address)

var emplid *string
if *payload.Emplid == "" {
emplid = nil
} else {
emplid = payload.Emplid
}

// Create a new serviceMember using the userID
newServiceMember = models.ServiceMember{
UserID: userID,
Edipi: edipi,
Emplid: emplid,
Edipi: &payload.Edipi,
Emplid: payload.Emplid,
Affiliation: (*models.ServiceMemberAffiliation)(payload.Affiliation),
FirstName: &payload.FirstName,
MiddleName: payload.MiddleName,
Expand Down
81 changes: 78 additions & 3 deletions pkg/handlers/ghcapi/customer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func (suite *HandlerSuite) TestGetCustomerHandlerIntegration() {
suite.NoError(getCustomerPayload.Validate(strfmt.Default))

suite.Equal(strfmt.UUID(customer.ID.String()), getCustomerPayload.ID)
suite.Equal(*customer.Edipi, getCustomerPayload.DodID)
suite.Equal(*customer.Edipi, getCustomerPayload.Edipi)
suite.Equal(strfmt.UUID(customer.UserID.String()), getCustomerPayload.UserID)
suite.Equal(customer.Affiliation.String(), getCustomerPayload.Agency)
suite.Equal(customer.PersonalEmail, getCustomerPayload.Email)
Expand Down Expand Up @@ -162,7 +162,7 @@ func (suite *HandlerSuite) TestCreateCustomerWithOktaOptionHandler() {
FirstName: "First",
Telephone: handlers.FmtString("223-455-3399"),
Affiliation: &affiliation,
Edipi: handlers.FmtString(""),
Edipi: "",
Emplid: handlers.FmtString(""),
PersonalEmail: *handlers.FmtString("email@email.com"),
BackupContact: &ghcmessages.BackupContact{
Expand Down Expand Up @@ -260,7 +260,7 @@ func (suite *HandlerSuite) TestCreateCustomerWithOktaOptionHandler() {
FirstName: "First",
Telephone: handlers.FmtString("223-455-3399"),
Affiliation: &affiliation,
Edipi: customer.Edipi,
Edipi: *customer.Edipi,
PersonalEmail: *handlers.FmtString("email@email.com"),
BackupContact: &ghcmessages.BackupContact{
Name: handlers.FmtString("New Backup Contact"),
Expand Down Expand Up @@ -298,6 +298,81 @@ func (suite *HandlerSuite) TestCreateCustomerWithOktaOptionHandler() {
response := handler.Handle(params)
suite.Assertions.IsType(&customerops.CreateCustomerWithOktaOptionUnprocessableEntity{}, response)
})

suite.Run("Unable to create customer of affiliation Coast Guard with no EMPLID", func() {
// in order to call the endpoint, we need to be an authenticated office user that's a SC
officeUser := factory.BuildOfficeUserWithRoles(suite.DB(), nil, []roles.RoleType{roles.RoleTypeTOO})
officeUser.User.Roles = append(officeUser.User.Roles, roles.Role{
RoleType: roles.RoleTypeServicesCounselor,
})

// Build provider
provider, err := factory.BuildOktaProvider(officeProviderName)
suite.NoError(err)

mockAndActivateOktaEndpoints(provider)

residentialAddress := ghcmessages.Address{
StreetAddress1: handlers.FmtString("123 New Street"),
City: handlers.FmtString("Newcity"),
State: handlers.FmtString("MA"),
PostalCode: handlers.FmtString("02110"),
}

backupAddress := ghcmessages.Address{
StreetAddress1: handlers.FmtString("123 Backup Street"),
City: handlers.FmtString("Backupcity"),
State: handlers.FmtString("MA"),
PostalCode: handlers.FmtString("02115"),
}

affiliation := ghcmessages.AffiliationCOASTGUARD

body := &ghcmessages.CreateCustomerPayload{
LastName: "Last",
FirstName: "First",
Telephone: handlers.FmtString("223-455-3399"),
Affiliation: &affiliation,
Edipi: "1234567890",
PersonalEmail: *handlers.FmtString("email@email.com"),
BackupContact: &ghcmessages.BackupContact{
Name: handlers.FmtString("New Backup Contact"),
Phone: handlers.FmtString("445-345-1212"),
Email: handlers.FmtString("newbackup@mail.com"),
},
ResidentialAddress: struct {
ghcmessages.Address
}{
Address: residentialAddress,
},
BackupMailingAddress: struct {
ghcmessages.Address
}{
Address: backupAddress,
},
CreateOktaAccount: true,
// when CacUser is false, this indicates a non-CAC user so CacValidated is set to true
CacUser: false,
}

defer goth.ClearProviders()
goth.UseProviders(provider)

request := httptest.NewRequest("POST", "/customer", nil)
request = suite.AuthenticateOfficeRequest(request, officeUser)
params := customerops.CreateCustomerWithOktaOptionParams{
HTTPRequest: request,
Body: body,
}
handlerConfig := suite.HandlerConfig()
handler := CreateCustomerWithOktaOptionHandler{
handlerConfig,
}
response := handler.Handle(params)
suite.Assertions.IsType(&customerops.CreateCustomerWithOktaOptionUnprocessableEntity{}, response)
failedToCreateCustomerPayload := response.(*customerops.CreateCustomerWithOktaOptionUnprocessableEntity).Payload.ClientError.Detail
suite.Equal("ID: 00000000-0000-0000-0000-000000000000 is in a conflicting state Service members from the Coast Guard require an EMPLID for creation.", *failedToCreateCustomerPayload)
})
}

func (suite *HandlerSuite) TestSearchCustomersHandler() {
Expand Down
2 changes: 1 addition & 1 deletion pkg/handlers/ghcapi/internal/payloads/model_to_payload.go
Original file line number Diff line number Diff line change
Expand Up @@ -490,7 +490,7 @@ func Customer(customer *models.ServiceMember) *ghcmessages.Customer {
payload := ghcmessages.Customer{
Agency: swag.StringValue((*string)(customer.Affiliation)),
CurrentAddress: Address(customer.ResidentialAddress),
DodID: swag.StringValue(customer.Edipi),
Edipi: swag.StringValue(customer.Edipi),
Email: customer.PersonalEmail,
FirstName: swag.StringValue(customer.FirstName),
ID: strfmt.UUID(customer.ID.String()),
Expand Down
14 changes: 1 addition & 13 deletions pkg/handlers/ghcapi/orders.go
Original file line number Diff line number Diff line change
Expand Up @@ -323,24 +323,12 @@ func (h CreateOrderHandler) Handle(params orderop.CreateOrderParams) middleware.
}

if newOrder.OrdersType == "SAFETY" {
// if creating a Safety move, clear out the DoDID and OktaID for the customer
// if creating a Safety move, clear out the OktaID for the customer since they won't log into MilMove
err = models.UpdateUserOktaID(appCtx.DB(), &newOrder.ServiceMember.User, "")
if err != nil {
appCtx.Logger().Error("Authorization error updating user", zap.Error(err))
return orderop.NewUpdateOrderInternalServerError(), err
}

err = models.UpdateServiceMemberDoDID(appCtx.DB(), &newOrder.ServiceMember, nil)
if err != nil {
appCtx.Logger().Error("Authorization error updating service member", zap.Error(err))
return orderop.NewUpdateOrderInternalServerError(), err
}

err = models.UpdateServiceMemberEMPLID(appCtx.DB(), &newOrder.ServiceMember, nil)
if err != nil {
appCtx.Logger().Error("Authorization error updating service member", zap.Error(err))
return orderop.NewUpdateOrderInternalServerError(), err
}
}

newMove, verrs, err := newOrder.CreateNewMove(appCtx.DB(), moveOptions)
Expand Down
4 changes: 2 additions & 2 deletions pkg/handlers/ghcapi/queues_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -833,7 +833,7 @@ func (suite *HandlerSuite) TestGetMoveQueuesHandlerCustomerInfoFilters() {
result := payload.QueueMoves[0]

suite.Len(payload.QueueMoves, 1)
suite.Equal("11111", result.Customer.DodID)
suite.Equal("11111", result.Customer.Edipi)
})

suite.Run("returns results matching Move ID search term", func() {
Expand Down Expand Up @@ -1525,7 +1525,7 @@ func (suite *HandlerSuite) TestGetServicesCounselingQueueHandler() {

suite.Len(payload.QueueMoves, 2)
suite.Equal(order.ServiceMember.ID.String(), result1.Customer.ID.String())
suite.Equal(*order.ServiceMember.Edipi, result1.Customer.DodID)
suite.Equal(*order.ServiceMember.Edipi, result1.Customer.Edipi)
suite.Equal(subtestData.needsCounselingMove.Locator, result1.Locator)
suite.EqualValues(subtestData.needsCounselingMove.Status, result1.Status)
suite.Equal(subtestData.needsCounselingEarliestShipment.RequestedPickupDate.Format(time.RFC3339Nano), (time.Time)(*result1.RequestedMoveDate).Format(time.RFC3339Nano))
Expand Down
8 changes: 4 additions & 4 deletions src/components/CustomerHeader/CustomerHeader.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { mount } from 'enzyme';
import CustomerHeader from './index';

const props = {
customer: { last_name: 'Kerry', first_name: 'Smith', dodID: '999999999', emplid: '7777777', agency: 'COAST_GUARD' },
customer: { last_name: 'Kerry', first_name: 'Smith', edipi: '999999999', emplid: '7777777', agency: 'COAST_GUARD' },
order: {
agency: 'COAST_GUARD',
grade: 'E_6',
Expand All @@ -25,7 +25,7 @@ const props = {
};

const propsRetiree = {
customer: { last_name: 'Kerry', first_name: 'Smith', dodID: '999999999' },
customer: { last_name: 'Kerry', first_name: 'Smith', edipi: '999999999' },
order: {
agency: 'NAVY',
grade: 'E_6',
Expand All @@ -45,7 +45,7 @@ const propsRetiree = {
};

const propsUSMC = {
customer: { last_name: 'Kerry', first_name: 'Smith', dodID: '999999999' },
customer: { last_name: 'Kerry', first_name: 'Smith', edipi: '999999999' },
order: {
agency: 'MARINES',
grade: 'E_6',
Expand Down Expand Up @@ -77,7 +77,7 @@ describe('CustomerHeader component', () => {
expect(wrapper.find('[data-testid="nameBlock"]').text()).toContain('Kerry, Smith');
expect(wrapper.find('[data-testid="nameBlock"]').text()).toContain('FKLCTR');
expect(wrapper.find('[data-testid="deptPayGrade"]').text()).toContain('Coast Guard E-6');
expect(wrapper.find('[data-testid="dodId"]').text()).toContain('DoD ID 999999999');
expect(wrapper.find('[data-testid="edipi"]').text()).toContain('DoD ID 999999999');
expect(wrapper.find('[data-testid="emplid"]').text()).toContain('EMPLID 7777777');
expect(wrapper.find('[data-testid="infoBlock"]').text()).toContain('JBSA Lackland');
expect(wrapper.find('[data-testid="infoBlock"]').text()).toContain('JB Lewis-McChord');
Expand Down
4 changes: 2 additions & 2 deletions src/components/CustomerHeader/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ const CustomerHeader = ({ customer, order, moveCode, move, userRole }) => {
{ORDERS_BRANCH_OPTIONS[`${order.agency}`]} {ORDERS_PAY_GRADE_OPTIONS[`${order.grade}`]}
</span>
<span className={styles.verticalBar}>|</span>
<span data-testid="dodId" className={styles.details}>
DoD ID {customer.dodID}
<span data-testid="edipi" className={styles.details}>
DoD ID {customer.edipi}
</span>
{isCoastGuard && (
<>
Expand Down
Loading
Loading