Skip to content

Commit

Permalink
Revert amp change (#139835)
Browse files Browse the repository at this point in the history
  • Loading branch information
ntsummers1 authored Nov 22, 2024
1 parent 7733260 commit 9985b42
Show file tree
Hide file tree
Showing 26 changed files with 427 additions and 584 deletions.
10 changes: 4 additions & 6 deletions services/app-api/handlers/uploads/delete.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,20 @@ import { UnauthorizedError } from "../../libs/httpErrors";
*/
export const deleteUpload = handler(async (event, _context) => {
const user = getUserCredentialsFromJwt(event);
const body = event.body ? JSON.parse(event.body) : null;
const state = event.pathParameters ? event.pathParameters["state"] : "";
const fileId = event.pathParameters ? event.pathParameters["fileId"] : "";

if (user.role !== AppRoles.STATE_USER || !fileId || !state) {
if (user.role !== AppRoles.STATE_USER || !body || !body.fileId || !state) {
throw new UnauthorizedError("Unauthorized");
}

const decodedFileId = decodeURIComponent(fileId);
// Get file, check aws filename before deleting
const documentParams = {
TableName: process.env.uploadsTableName!,
KeyConditionExpression:
"uploadedState = :uploadedState AND fileId = :fileId",
ExpressionAttributeValues: {
":uploadedState": state,
":fileId": decodedFileId,
":fileId": body.fileId,
},
};
const results = await dynamoDb.query(documentParams);
Expand All @@ -46,7 +44,7 @@ export const deleteUpload = handler(async (event, _context) => {
TableName: process.env.uploadsTableName!,
Key: {
uploadedState: state,
fileId: decodedFileId,
fileId: body.fileId,
},
};

Expand Down
3 changes: 2 additions & 1 deletion services/app-api/handlers/uploads/tests/delete.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ describe("Test Delete Upload Handler", () => {
test("Should Call S3 delete when entry exists", async () => {
const event: APIGatewayProxyEvent = {
...testEvent,
pathParameters: { year: "2022", state: "AL", fileId: "uniqueIdString" },
body: `{"fileId": "uniqueIdString"}`,
pathParameters: { year: "2022", state: "AL" },
};

const res = await deleteUpload(event, null);
Expand Down
2 changes: 1 addition & 1 deletion services/app-api/serverless.yml
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ functions:
handler: handlers/uploads/delete.deleteUpload
events:
- http:
path: uploads/{year}/{state}/{fileId}
path: uploads/{year}/{state}
method: delete
cors: true
authorizer: aws_iam
Expand Down
7 changes: 5 additions & 2 deletions services/ui-src/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"@testing-library/user-event": "^14.5.1",
"@vitejs/plugin-react": "^4.2.1",
"aws-amplify": "^5.3.4",
"date-fns": "^4.1.0",
"date-fns": "^3.6.0",
"font-awesome": "^4.7.0",
"jsonpath": "^1.1.1",
"launchdarkly-react-client-sdk": "^3.6.0",
Expand Down Expand Up @@ -119,7 +119,10 @@
"moduleNameMapper": {
"\\.(css|less|scss)$": "<rootDir>/src/util/testing/styleMock.js",
"\\.(jpg|jpeg|png|gif|webp|svg|mp4|webm|wav|mp3|m4a)$": "<rootDir>/src/util/testing/mockAsset.ts"
}
},
"transformIgnorePatterns": [
"node_modules/(?!axios)"
]
},
"resolutions": {
"react-error-overlay": "6.0.9",
Expand Down
12 changes: 6 additions & 6 deletions services/ui-src/src/actions/certify.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import requestOptions from "../hooks/authHooks/requestOptions";
import { REPORT_STATUS } from "../types";
import { apiLib } from "../util/apiLib";

Expand All @@ -18,14 +19,13 @@ export const certifyAndSubmit = () => async (dispatch, getState) => {
dispatch({ type: CERTIFY_AND_SUBMIT });

try {
const opts = {
body: {
status: REPORT_STATUS.certified,
username: username,
},
const opts = await requestOptions();
opts.body = {
status: REPORT_STATUS.certified,
username: username,
};

await apiLib.post(`/state_status/${year}/${state}`, opts);
apiLib.post("carts-api", `/state_status/${year}/${state}`, opts);
dispatch({
type: CERTIFY_AND_SUBMIT_SUCCESS,
user: username,
Expand Down
8 changes: 7 additions & 1 deletion services/ui-src/src/actions/download.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import requestOptions from "../hooks/authHooks/requestOptions";
import { apiLib } from "../util/apiLib";

export const GET_TEMPLATE = "GET_TEMPLATE";
Expand All @@ -7,7 +8,12 @@ export const GET_TEMPLATE_FAILURE = "GET_TEMPLATE_FAILURE";
export const getFiscalYearTemplate = (year) => async (dispatch) => {
dispatch({ type: GET_TEMPLATE, data: "" });
try {
const data = await apiLib.get(`/fiscalYearTemplate/${year}`);
const opts = await requestOptions();
const data = await apiLib.get(
"carts-api",
`/fiscalYearTemplate/${year}`,
opts
);

dispatch({
type: GET_TEMPLATE_SUCCESS,
Expand Down
24 changes: 18 additions & 6 deletions services/ui-src/src/actions/initial.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/* eslint-disable no-underscore-dangle, no-console */
import requestOptions from "../hooks/authHooks/requestOptions";
import { getProgramData, getStateData, getUserData } from "../store/stateUser";
import { apiLib } from "../util/apiLib";

Expand All @@ -13,7 +14,8 @@ export const LOAD_LASTYEAR_SECTIONS = "LOAD_LASTYEAR_SECTIONS";
export const getAllStatesData = () => {
return async (dispatch) => {
try {
const data = await apiLib.get(`/state`);
const opts = await requestOptions();
const data = await apiLib.get("carts-api", `/state`, opts);

dispatch({ type: GET_ALL_STATES_DATA, data });
} catch (err) {
Expand All @@ -24,7 +26,8 @@ export const getAllStatesData = () => {
};

export const getAllStateStatuses = () => async (dispatch) => {
const results = await apiLib.get(`/state_status`);
const opts = await requestOptions();
const results = await apiLib.get("carts-api", `/state_status`, opts);
const data = results.Items;

const payload = data
Expand Down Expand Up @@ -68,7 +71,8 @@ export const getAllStateStatuses = () => async (dispatch) => {
export const getStateAllStatuses =
(selectedYears = [], selectedStates = [], selectedStatus = []) =>
async (dispatch) => {
const results = await apiLib.get(`/state_status`);
const opts = await requestOptions();
const results = await apiLib.get("carts-api", `/state_status`, opts);
const data = results.Items;
let yearFilter = () => {};
let stateFilter = () => {};
Expand Down Expand Up @@ -118,12 +122,17 @@ export const getStateAllStatuses =

export const loadSections = ({ stateCode, selectedYear }) => {
return async (dispatch) => {
const data = await apiLib.get(`/section/${selectedYear}/${stateCode}`);
const opts = await requestOptions();
const data = await apiLib.get(
"carts-api",
`/section/${selectedYear}/${stateCode}`,
opts
);

const lastYear = parseInt(selectedYear) - 1;
let lastYearData = undefined;
const priorData = await apiLib
.get(`/section/${lastYear}/${stateCode}`)
.get("carts-api", `/section/${lastYear}/${stateCode}`, opts)
.catch((err) => {
console.log("--- ERROR PRIOR YEAR SECTIONS ---");
console.log(err);
Expand All @@ -144,8 +153,11 @@ export const loadSections = ({ stateCode, selectedYear }) => {

export const loadEnrollmentCounts = ({ stateCode, selectedYear }) => {
return async (dispatch) => {
const opts = await requestOptions();
const data = await apiLib.get(
`/enrollment_counts/${selectedYear}/${stateCode}`
"carts-api",
`/enrollment_counts/${selectedYear}/${stateCode}`,
opts
);

dispatch({ type: SET_ENROLLMENT_COUNTS, data });
Expand Down
16 changes: 8 additions & 8 deletions services/ui-src/src/actions/uncertify.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import requestOptions from "../hooks/authHooks/requestOptions";
import { REPORT_STATUS } from "../types";
import { apiLib } from "../util/apiLib";

Expand All @@ -15,16 +16,15 @@ export const uncertifyReport =

dispatch({ type: UNCERTIFY });
try {
const opts = {
body: {
status: REPORT_STATUS.in_progress,
username: username,
year: reportYear,
state: state,
},
const opts = await requestOptions();
opts.body = {
status: REPORT_STATUS.in_progress,
username: username,
year: reportYear,
state: state,
};

await apiLib.post(`/state_status/${year}/${state}`, opts);
await apiLib.post("carts-api", `/state_status/${year}/${state}`, opts);
dispatch({
type: UNCERTIFY_SUCCESS,
user: username,
Expand Down
7 changes: 3 additions & 4 deletions services/ui-src/src/components/layout/FormTemplates.jsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import requestOptions from "../../hooks/authHooks/requestOptions";
import React, { useState } from "react";
import "react-data-table-component-extensions/dist/index.css";
import { Button } from "@cmsgov/design-system";
Expand All @@ -14,10 +15,8 @@ const FormTemplates = () => {
setInprogress(true);

try {
const opts = {
body: { year: selectedYear },
};
await apiLib.post("/formTemplates", opts);
const opts = await requestOptions({ year: selectedYear });
await apiLib.post("carts-api", "/formTemplates", opts);
window.alert("Request Completed");
history.push("/");
} catch (e) {
Expand Down
9 changes: 3 additions & 6 deletions services/ui-src/src/components/layout/FormTemplates.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,15 @@ import React from "react";
import { shallow } from "enzyme";
import FormTemplates from "./FormTemplates";
import { act, render, fireEvent } from "@testing-library/react";
import { apiLib } from "../../util/apiLib";

jest.mock("../../hooks/authHooks");
window.alert = jest.fn();

const mockPost = jest.fn();
jest.mock("aws-amplify", () => ({
API: {
post: () => mockPost(),
},
}));
jest.mock("../../hooks/authHooks");
window.alert = jest.fn();

const mockHistoryPush = jest.fn();
jest.mock("react-router-dom", () => ({
Expand All @@ -33,13 +31,12 @@ describe("FormTemplates Component", () => {
});

it("fires the generate forms event on button click, then navigates", async () => {
const apiSpy = jest.spyOn(apiLib, "post");
const { getByTestId } = render(formTemplate);
const generateButton = getByTestId("generate-forms-button");
await act(async () => {
fireEvent.click(generateButton);
});
expect(apiSpy).toHaveBeenCalled();
expect(mockPost).toHaveBeenCalled();
expect(mockHistoryPush).toHaveBeenCalledWith("/");
});
});
10 changes: 5 additions & 5 deletions services/ui-src/src/components/sections/Print.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import Section from "../layout/Section";
// utils
import statesArray from "../utils/statesArray";
import { loadEnrollmentCounts, loadSections } from "../../actions/initial";
import requestOptions from "../../hooks/authHooks/requestOptions";
import { apiLib } from "../../util/apiLib";

/**
Expand Down Expand Up @@ -82,13 +83,12 @@ const Print = () => {
.replaceAll("\u2014", "-");

const base64String = btoa(unescape(encodeURIComponent(htmlString)));
const opts = {
body: {
encodedHtml: base64String,
},
const opts = await requestOptions();
opts.body = {
encodedHtml: base64String,
};

const res = await apiLib.post("/print_pdf", opts);
const res = await apiLib.post("carts-api", "/print_pdf", opts);
openPdf(res.data);
};
// Load formData via side effect
Expand Down
6 changes: 3 additions & 3 deletions services/ui-src/src/components/sections/login/LocalLogins.jsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from "react";
import { useHistory } from "react-router-dom";
import { Auth } from "aws-amplify";
import { useFormFields } from "../../../hooks/useFormFields";
import { loginUser } from "../../../util/apiLib";

const LocalLogin = () => {
const history = useHistory();
Expand All @@ -12,8 +12,8 @@ const LocalLogin = () => {
async function handleLogin(event) {
event.preventDefault();
try {
await loginUser(fields.email, fields.password);
history.push("/");
await Auth.signIn(fields.email, fields.password);
history.push(`/`);
} catch (error) {
console.log("Error while logging in.", error); // eslint-disable-line no-console
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@ import { shallow } from "enzyme";
import { act, render, fireEvent } from "@testing-library/react";
import { LocalLogins } from "./LocalLogins";

const mockPost = jest.fn();
const localLogins = <LocalLogins />;
const mockLoginUser = jest.fn();
jest.mock("../../../util/apiLib", () => ({
loginUser: (username, password) => mockLoginUser(username, password),
jest.mock("aws-amplify", () => ({
Auth: {
signIn: (email, password) => mockPost(email, password),
},
}));
const mockHistoryPush = jest.fn();
jest.mock("react-router-dom", () => ({
Expand Down Expand Up @@ -36,10 +38,7 @@ describe("LocalLogin component", () => {
await act(async () => {
fireEvent.click(generateButton);
});
expect(mockLoginUser).toHaveBeenCalledWith(
"[email protected]",
"superS3cure" // pragma: allowlist secret
);
expect(mockPost).toHaveBeenCalledWith("[email protected]", "superS3cure");
expect(mockHistoryPush).toHaveBeenCalledWith("/");
});
});
9 changes: 4 additions & 5 deletions services/ui-src/src/hooks/authHooks/authLifecycle.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { Hub } from "aws-amplify";
import { Auth, Hub } from "aws-amplify";
import { add } from "date-fns";
import { setAuthTimeout } from "../../store/stateUser";
import { logoutUser, refreshSession } from "../../util/apiLib";

/*
* After the token expires, refresh tokens will be used in the allotted idle window.
Expand All @@ -28,7 +27,7 @@ class AuthManager {
const isExpired = expiration && new Date(expiration).valueOf() < Date.now();
if (isExpired) {
localStorage.removeItem("mdctcarts_session_exp");
logoutUser().then(() => {
Auth.signOut().then(() => {
window.location.href = "/";
});
}
Expand Down Expand Up @@ -57,7 +56,7 @@ class AuthManager {
* Manual refresh of credentials paired with an instant timer clear
*/
async refreshCredentials() {
await refreshSession();
await Auth.currentAuthenticatedUser({ bypassCache: true }); // Force a token refresh
this.setTimer();
}

Expand All @@ -76,7 +75,7 @@ class AuthManager {
this.promptTimeout(exp);
this.timeoutForceId = setTimeout(() => {
localStorage.removeItem("mdctcarts_session_exp");
logoutUser();
Auth.signOut();
}, IDLE_WINDOW - PROMPT_AT);
},
PROMPT_AT,
Expand Down
1 change: 1 addition & 0 deletions services/ui-src/src/hooks/authHooks/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export * from "./useUser";
export * from "./userProvider";
export * from "./requestOptions";
export * from "./authLifecycle";
Loading

0 comments on commit 9985b42

Please sign in to comment.