Skip to content

Commit a2f607e

Browse files
Merge pull request #225 from Eastern-Research-Group/develop
Sync staging with develop
2 parents 1fe7140 + f32677a commit a2f607e

File tree

5 files changed

+151
-79
lines changed

5 files changed

+151
-79
lines changed

app/client/src/routes/allRebates.tsx

+11-5
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ export default function AllRebates() {
134134
<br />
135135
<TextWithTooltip
136136
text="Form Status"
137-
tooltip="submitted or draft"
137+
tooltip="Draft, Edits Requested, Submitted, or Withdrawn"
138138
/>
139139
</th>
140140

@@ -344,10 +344,16 @@ form for the fields to be displayed. */
344344
/>
345345
</svg>
346346
<span className="margin-left-05">
347-
{submissionNeedsEdits ||
348-
submissionHasBeenWithdrawn
349-
? bap.rebateStatus
350-
: state}
347+
{
348+
submissionNeedsEdits ||
349+
submissionHasBeenWithdrawn
350+
? bap.rebateStatus
351+
: state === "draft"
352+
? "Draft"
353+
: state === "submitted"
354+
? "Submitted"
355+
: state // fallback, not used
356+
}
351357
</span>
352358
</span>
353359
</td>

app/client/src/routes/helpdesk.tsx

+7-2
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ export default function Helpdesk() {
6262
const [formDisplayed, setFormDisplayed] = useState(false);
6363

6464
const { content } = useContentState();
65-
const { epaUserData } = useUserState();
65+
const { csbData, epaUserData } = useUserState();
6666
const dispatch = useDialogDispatch();
6767
const helpdeskAccess = useHelpdeskAccess();
6868

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

7878
if (
79+
csbData.status !== "success" ||
7980
epaUserData.status !== "success" ||
8081
helpdeskAccess === "idle" ||
8182
helpdeskAccess === "pending"
@@ -87,6 +88,8 @@ export default function Helpdesk() {
8788
navigate("/", { replace: true });
8889
}
8990

91+
const { enrollmentClosed } = csbData.data;
92+
9093
const { formSchema, submissionData } = rebateFormSubmission.data;
9194

9295
return (
@@ -252,7 +255,9 @@ export default function Helpdesk() {
252255
<td>
253256
<button
254257
className="usa-button font-sans-2xs margin-right-0 padding-x-105 padding-y-1"
255-
disabled={submissionData.state === "draft"}
258+
disabled={
259+
enrollmentClosed || submissionData.state === "draft"
260+
}
256261
onClick={(ev) => {
257262
dispatch({
258263
type: "DISPLAY_DIALOG",

app/server/app/routes/api.js

+13-20
Original file line numberDiff line numberDiff line change
@@ -319,30 +319,23 @@ router.post("/:id/:comboKey/storage/s3", storeBapComboKeys, (req, res) => {
319319

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

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

332-
const storageUrl = `${formioProjectUrl}/${formioFormName}/storage/s3`;
330+
const storageUrl = `${formioProjectUrl}/${formioFormName}/storage/s3`;
333331

334-
axiosFormio(req)
335-
.get(storageUrl, { params: req.query })
336-
.then((axiosRes) => axiosRes.data)
337-
.then((fileMetadata) => res.json(fileMetadata))
338-
.catch((error) => {
339-
const message = "Error downloading Forms.gov file";
340-
return res.status(error?.response?.status || 500).json({ message });
341-
});
342-
})
332+
axiosFormio(req)
333+
.get(storageUrl, { params: req.query })
334+
.then((axiosRes) => axiosRes.data)
335+
.then((fileMetadata) => res.json(fileMetadata))
343336
.catch((error) => {
344-
const message = "CSB enrollment period is closed";
345-
return res.status(400).json({ message });
337+
const message = "Error downloading Forms.gov file";
338+
return res.status(error?.response?.status || 500).json({ message });
346339
});
347340
});
348341

app/server/app/routes/help.js

+22-19
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,17 @@ const {
1313
} = require("../middleware");
1414
const log = require("../utilities/logger");
1515

16+
const enrollmentClosed = process.env.CSB_ENROLLMENT_PERIOD !== "open";
17+
1618
const router = express.Router();
1719

18-
// Confirm user is both authenticated and authorized with valid helpdesk roles
20+
// confirm user is both authenticated and authorized with valid helpdesk roles
1921
router.use(ensureAuthenticated);
2022
router.use(ensureHelpdesk);
2123

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

2628
axiosFormio(req)
2729
.get(`${formioProjectUrl}/${formioFormName}/submission/${id}`)
@@ -41,35 +43,37 @@ router.get("/rebate-form-submission/:id", verifyMongoObjectId, (req, res) => {
4143
});
4244
})
4345
.catch((error) => {
44-
res.status(error?.response?.status || 500).json({
45-
message: `Error getting Forms.gov rebate form submission ${id}`,
46-
});
46+
const message = `Error getting Forms.gov rebate form submission ${id}`;
47+
return res.status(error?.response?.status || 500).json({ message });
4748
});
4849
});
4950

5051
// --- change a submitted Forms.gov rebate form's submission back to 'draft'
5152
router.post("/rebate-form-submission/:id", verifyMongoObjectId, (req, res) => {
52-
const id = req.params.id;
53-
const userEmail = req.user.mail;
54-
const formioSubmissionUrl = `${formioProjectUrl}/${formioFormName}/submission/${id}`;
53+
const { id } = req.params;
54+
const { mail } = req.user;
55+
56+
if (enrollmentClosed) {
57+
const message = "CSB enrollment period is closed";
58+
return res.status(400).json({ message });
59+
}
60+
61+
const existingSubmissionUrl = `${formioProjectUrl}/${formioFormName}/submission/${id}`;
5562

5663
axiosFormio(req)
57-
.get(formioSubmissionUrl)
64+
.get(existingSubmissionUrl)
5865
.then((axiosRes) => axiosRes.data)
5966
.then((existingSubmission) => {
6067
axiosFormio(req)
61-
.put(formioSubmissionUrl, {
68+
.put(existingSubmissionUrl, {
6269
state: "draft",
63-
data: { ...existingSubmission.data, last_updated_by: userEmail },
70+
data: { ...existingSubmission.data, last_updated_by: mail },
6471
metadata: { ...existingSubmission.metadata, ...formioCsbMetadata },
6572
})
6673
.then((axiosRes) => axiosRes.data)
6774
.then((updatedSubmission) => {
68-
log({
69-
level: "info",
70-
message: `User with email ${userEmail} updated rebate form submission ${id} from submitted to draft.`,
71-
req,
72-
});
75+
const message = `User with email ${mail} updated rebate form submission ${id} from submitted to draft.`;
76+
log({ level: "info", message, req });
7377

7478
axiosFormio(req)
7579
.get(`${formioProjectUrl}/form/${updatedSubmission.form}`)
@@ -86,9 +90,8 @@ router.post("/rebate-form-submission/:id", verifyMongoObjectId, (req, res) => {
8690
});
8791
})
8892
.catch((error) => {
89-
res.status(error?.response?.status || 500).json({
90-
message: `Error updating Forms.gov rebate form submission ${id}`,
91-
});
93+
const message = `Error updating Forms.gov rebate form submission ${id}`;
94+
return res.status(error?.response?.status || 500).json({ message });
9295
});
9396
});
9497

docs/csb-openapi.json

+98-33
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,47 @@
275275
"parameters": [{ "$ref": "#/components/parameters/scan" }]
276276
}
277277
},
278+
"/api/csb-data": {
279+
"get": {
280+
"summary": "/api/csb-data",
281+
"responses": {
282+
"200": {
283+
"description": "OK",
284+
"content": {
285+
"application/json": {
286+
"schema": {
287+
"type": "object",
288+
"properties": {
289+
"enrollmentClosed": {
290+
"type": "boolean",
291+
"example": true
292+
}
293+
}
294+
}
295+
}
296+
}
297+
},
298+
"401": {
299+
"description": "Unauthorized",
300+
"content": {
301+
"application/json": {
302+
"schema": {
303+
"type": "object",
304+
"properties": {
305+
"message": {
306+
"type": "string",
307+
"example": "Unauthorized"
308+
}
309+
}
310+
}
311+
}
312+
}
313+
}
314+
},
315+
"tags": [],
316+
"parameters": [{ "$ref": "#/components/parameters/scan" }]
317+
}
318+
},
278319
"/api/epa-data": {
279320
"get": {
280321
"summary": "/api/epa-data",
@@ -284,7 +325,21 @@
284325
"content": {
285326
"application/json": {
286327
"schema": {
287-
"type": "object"
328+
"type": "object",
329+
"properties": {
330+
"mail": {
331+
"type": "string",
332+
"example": "[email protected]"
333+
},
334+
"memberof": {
335+
"type": "string",
336+
"example": "csb_admin,csb_helpdesk"
337+
},
338+
"exp": {
339+
"type": "number",
340+
"example": 1661376902
341+
}
342+
}
288343
}
289344
}
290345
}
@@ -310,18 +365,33 @@
310365
"parameters": [{ "$ref": "#/components/parameters/scan" }]
311366
}
312367
},
313-
"/api/sam-data": {
368+
"/api/bap-data": {
314369
"get": {
315-
"summary": "/api/sam-data",
370+
"summary": "/api/bap-data",
316371
"responses": {
317372
"200": {
318373
"description": "OK",
319374
"content": {
320375
"application/json": {
321376
"schema": {
322-
"type": "array",
323-
"items": {
324-
"type": "object"
377+
"type": "object",
378+
"properties": {
379+
"samResults": {
380+
"type": "boolean",
381+
"example": true
382+
},
383+
"samEntities": {
384+
"type": "array",
385+
"items": {
386+
"type": "object"
387+
}
388+
},
389+
"rebateSubmissions": {
390+
"type": "array",
391+
"items": {
392+
"type": "object"
393+
}
394+
}
325395
}
326396
}
327397
}
@@ -351,9 +421,9 @@
351421
"parameters": [{ "$ref": "#/components/parameters/scan" }]
352422
}
353423
},
354-
"/api/{bapComboKey}/storage/s3": {
424+
"/api/{id}/{comboKey}/storage/s3": {
355425
"get": {
356-
"summary": "/api/{bapComboKey}/storage/s3",
426+
"summary": "/api/{id}/{comboKey}/storage/s3",
357427
"responses": {
358428
"200": {
359429
"description": "OK"
@@ -362,7 +432,15 @@
362432
"tags": [],
363433
"parameters": [
364434
{
365-
"name": "bapComboKey",
435+
"name": "id",
436+
"in": "path",
437+
"required": true,
438+
"schema": {
439+
"type": "string"
440+
}
441+
},
442+
{
443+
"name": "comboKey",
366444
"in": "path",
367445
"required": true,
368446
"schema": {
@@ -373,7 +451,7 @@
373451
]
374452
},
375453
"post": {
376-
"summary": "/api/{bapComboKey}/storage/s3",
454+
"summary": "/api/{id}/{comboKey}/storage/s3",
377455
"responses": {
378456
"200": {
379457
"description": "OK"
@@ -382,7 +460,15 @@
382460
"tags": [],
383461
"parameters": [
384462
{
385-
"name": "bapComboKey",
463+
"name": "id",
464+
"in": "path",
465+
"required": true,
466+
"schema": {
467+
"type": "string"
468+
}
469+
},
470+
{
471+
"name": "comboKey",
386472
"in": "path",
387473
"required": true,
388474
"schema": {
@@ -505,28 +591,7 @@
505591
"content": {
506592
"application/json": {
507593
"schema": {
508-
"type": "object",
509-
"properties": {
510-
"userAccess": {
511-
"type": "boolean",
512-
"example": true
513-
},
514-
"formSchema": {
515-
"type": "object",
516-
"properties": {
517-
"url": {
518-
"type": "string",
519-
"example": "https://formmio/project/form/id"
520-
},
521-
"json": {
522-
"type": "object"
523-
}
524-
}
525-
},
526-
"submissionData": {
527-
"type": "object"
528-
}
529-
}
594+
"type": "object"
530595
}
531596
}
532597
}

0 commit comments

Comments
 (0)