Skip to content

Commit

Permalink
Merge pull request #225 from Eastern-Research-Group/develop
Browse files Browse the repository at this point in the history
Sync staging with develop
  • Loading branch information
courtneymyers authored Aug 25, 2022
2 parents 1fe7140 + f32677a commit a2f607e
Show file tree
Hide file tree
Showing 5 changed files with 151 additions and 79 deletions.
16 changes: 11 additions & 5 deletions app/client/src/routes/allRebates.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ export default function AllRebates() {
<br />
<TextWithTooltip
text="Form Status"
tooltip="submitted or draft"
tooltip="Draft, Edits Requested, Submitted, or Withdrawn"
/>
</th>

Expand Down Expand Up @@ -344,10 +344,16 @@ form for the fields to be displayed. */
/>
</svg>
<span className="margin-left-05">
{submissionNeedsEdits ||
submissionHasBeenWithdrawn
? bap.rebateStatus
: state}
{
submissionNeedsEdits ||
submissionHasBeenWithdrawn
? bap.rebateStatus
: state === "draft"
? "Draft"
: state === "submitted"
? "Submitted"
: state // fallback, not used
}
</span>
</span>
</td>
Expand Down
9 changes: 7 additions & 2 deletions app/client/src/routes/helpdesk.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export default function Helpdesk() {
const [formDisplayed, setFormDisplayed] = useState(false);

const { content } = useContentState();
const { epaUserData } = useUserState();
const { csbData, epaUserData } = useUserState();
const dispatch = useDialogDispatch();
const helpdeskAccess = useHelpdeskAccess();

Expand All @@ -76,6 +76,7 @@ export default function Helpdesk() {
});

if (
csbData.status !== "success" ||
epaUserData.status !== "success" ||
helpdeskAccess === "idle" ||
helpdeskAccess === "pending"
Expand All @@ -87,6 +88,8 @@ export default function Helpdesk() {
navigate("/", { replace: true });
}

const { enrollmentClosed } = csbData.data;

const { formSchema, submissionData } = rebateFormSubmission.data;

return (
Expand Down Expand Up @@ -252,7 +255,9 @@ export default function Helpdesk() {
<td>
<button
className="usa-button font-sans-2xs margin-right-0 padding-x-105 padding-y-1"
disabled={submissionData.state === "draft"}
disabled={
enrollmentClosed || submissionData.state === "draft"
}
onClick={(ev) => {
dispatch({
type: "DISPLAY_DIALOG",
Expand Down
33 changes: 13 additions & 20 deletions app/server/app/routes/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -319,30 +319,23 @@ router.post("/:id/:comboKey/storage/s3", storeBapComboKeys, (req, res) => {

// --- download s3 file metadata from Forms.gov
router.get("/:id/:comboKey/storage/s3", storeBapComboKeys, (req, res) => {
const { id, comboKey } = req.params;
const { comboKey } = req.params;

checkEnrollmentPeriodAndBapStatus({ id, comboKey, req })
.then(() => {
if (!req.bapComboKeys.includes(comboKey)) {
const message = `User with email ${req.user.mail} attempted to download file without a matching BAP combo key`;
log({ level: "error", message, req });
return res.status(401).json({ message: "Unauthorized" });
}
if (!req.bapComboKeys.includes(comboKey)) {
const message = `User with email ${req.user.mail} attempted to download file without a matching BAP combo key`;
log({ level: "error", message, req });
return res.status(401).json({ message: "Unauthorized" });
}

const storageUrl = `${formioProjectUrl}/${formioFormName}/storage/s3`;
const storageUrl = `${formioProjectUrl}/${formioFormName}/storage/s3`;

axiosFormio(req)
.get(storageUrl, { params: req.query })
.then((axiosRes) => axiosRes.data)
.then((fileMetadata) => res.json(fileMetadata))
.catch((error) => {
const message = "Error downloading Forms.gov file";
return res.status(error?.response?.status || 500).json({ message });
});
})
axiosFormio(req)
.get(storageUrl, { params: req.query })
.then((axiosRes) => axiosRes.data)
.then((fileMetadata) => res.json(fileMetadata))
.catch((error) => {
const message = "CSB enrollment period is closed";
return res.status(400).json({ message });
const message = "Error downloading Forms.gov file";
return res.status(error?.response?.status || 500).json({ message });
});
});

Expand Down
41 changes: 22 additions & 19 deletions app/server/app/routes/help.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,17 @@ const {
} = require("../middleware");
const log = require("../utilities/logger");

const enrollmentClosed = process.env.CSB_ENROLLMENT_PERIOD !== "open";

const router = express.Router();

// Confirm user is both authenticated and authorized with valid helpdesk roles
// confirm user is both authenticated and authorized with valid helpdesk roles
router.use(ensureAuthenticated);
router.use(ensureHelpdesk);

// --- get an existing rebate form's submission data from Forms.gov
router.get("/rebate-form-submission/:id", verifyMongoObjectId, (req, res) => {
const id = req.params.id;
const { id } = req.params;

axiosFormio(req)
.get(`${formioProjectUrl}/${formioFormName}/submission/${id}`)
Expand All @@ -41,35 +43,37 @@ router.get("/rebate-form-submission/:id", verifyMongoObjectId, (req, res) => {
});
})
.catch((error) => {
res.status(error?.response?.status || 500).json({
message: `Error getting Forms.gov rebate form submission ${id}`,
});
const message = `Error getting Forms.gov rebate form submission ${id}`;
return res.status(error?.response?.status || 500).json({ message });
});
});

// --- change a submitted Forms.gov rebate form's submission back to 'draft'
router.post("/rebate-form-submission/:id", verifyMongoObjectId, (req, res) => {
const id = req.params.id;
const userEmail = req.user.mail;
const formioSubmissionUrl = `${formioProjectUrl}/${formioFormName}/submission/${id}`;
const { id } = req.params;
const { mail } = req.user;

if (enrollmentClosed) {
const message = "CSB enrollment period is closed";
return res.status(400).json({ message });
}

const existingSubmissionUrl = `${formioProjectUrl}/${formioFormName}/submission/${id}`;

axiosFormio(req)
.get(formioSubmissionUrl)
.get(existingSubmissionUrl)
.then((axiosRes) => axiosRes.data)
.then((existingSubmission) => {
axiosFormio(req)
.put(formioSubmissionUrl, {
.put(existingSubmissionUrl, {
state: "draft",
data: { ...existingSubmission.data, last_updated_by: userEmail },
data: { ...existingSubmission.data, last_updated_by: mail },
metadata: { ...existingSubmission.metadata, ...formioCsbMetadata },
})
.then((axiosRes) => axiosRes.data)
.then((updatedSubmission) => {
log({
level: "info",
message: `User with email ${userEmail} updated rebate form submission ${id} from submitted to draft.`,
req,
});
const message = `User with email ${mail} updated rebate form submission ${id} from submitted to draft.`;
log({ level: "info", message, req });

axiosFormio(req)
.get(`${formioProjectUrl}/form/${updatedSubmission.form}`)
Expand All @@ -86,9 +90,8 @@ router.post("/rebate-form-submission/:id", verifyMongoObjectId, (req, res) => {
});
})
.catch((error) => {
res.status(error?.response?.status || 500).json({
message: `Error updating Forms.gov rebate form submission ${id}`,
});
const message = `Error updating Forms.gov rebate form submission ${id}`;
return res.status(error?.response?.status || 500).json({ message });
});
});

Expand Down
131 changes: 98 additions & 33 deletions docs/csb-openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,47 @@
"parameters": [{ "$ref": "#/components/parameters/scan" }]
}
},
"/api/csb-data": {
"get": {
"summary": "/api/csb-data",
"responses": {
"200": {
"description": "OK",
"content": {
"application/json": {
"schema": {
"type": "object",
"properties": {
"enrollmentClosed": {
"type": "boolean",
"example": true
}
}
}
}
}
},
"401": {
"description": "Unauthorized",
"content": {
"application/json": {
"schema": {
"type": "object",
"properties": {
"message": {
"type": "string",
"example": "Unauthorized"
}
}
}
}
}
}
},
"tags": [],
"parameters": [{ "$ref": "#/components/parameters/scan" }]
}
},
"/api/epa-data": {
"get": {
"summary": "/api/epa-data",
Expand All @@ -284,7 +325,21 @@
"content": {
"application/json": {
"schema": {
"type": "object"
"type": "object",
"properties": {
"mail": {
"type": "string",
"example": "[email protected]"
},
"memberof": {
"type": "string",
"example": "csb_admin,csb_helpdesk"
},
"exp": {
"type": "number",
"example": 1661376902
}
}
}
}
}
Expand All @@ -310,18 +365,33 @@
"parameters": [{ "$ref": "#/components/parameters/scan" }]
}
},
"/api/sam-data": {
"/api/bap-data": {
"get": {
"summary": "/api/sam-data",
"summary": "/api/bap-data",
"responses": {
"200": {
"description": "OK",
"content": {
"application/json": {
"schema": {
"type": "array",
"items": {
"type": "object"
"type": "object",
"properties": {
"samResults": {
"type": "boolean",
"example": true
},
"samEntities": {
"type": "array",
"items": {
"type": "object"
}
},
"rebateSubmissions": {
"type": "array",
"items": {
"type": "object"
}
}
}
}
}
Expand Down Expand Up @@ -351,9 +421,9 @@
"parameters": [{ "$ref": "#/components/parameters/scan" }]
}
},
"/api/{bapComboKey}/storage/s3": {
"/api/{id}/{comboKey}/storage/s3": {
"get": {
"summary": "/api/{bapComboKey}/storage/s3",
"summary": "/api/{id}/{comboKey}/storage/s3",
"responses": {
"200": {
"description": "OK"
Expand All @@ -362,7 +432,15 @@
"tags": [],
"parameters": [
{
"name": "bapComboKey",
"name": "id",
"in": "path",
"required": true,
"schema": {
"type": "string"
}
},
{
"name": "comboKey",
"in": "path",
"required": true,
"schema": {
Expand All @@ -373,7 +451,7 @@
]
},
"post": {
"summary": "/api/{bapComboKey}/storage/s3",
"summary": "/api/{id}/{comboKey}/storage/s3",
"responses": {
"200": {
"description": "OK"
Expand All @@ -382,7 +460,15 @@
"tags": [],
"parameters": [
{
"name": "bapComboKey",
"name": "id",
"in": "path",
"required": true,
"schema": {
"type": "string"
}
},
{
"name": "comboKey",
"in": "path",
"required": true,
"schema": {
Expand Down Expand Up @@ -505,28 +591,7 @@
"content": {
"application/json": {
"schema": {
"type": "object",
"properties": {
"userAccess": {
"type": "boolean",
"example": true
},
"formSchema": {
"type": "object",
"properties": {
"url": {
"type": "string",
"example": "https://formmio/project/form/id"
},
"json": {
"type": "object"
}
}
},
"submissionData": {
"type": "object"
}
}
"type": "object"
}
}
}
Expand Down

0 comments on commit a2f607e

Please sign in to comment.