From de51a811226a28def7ae71c07b71203fd7d3c8a2 Mon Sep 17 00:00:00 2001 From: nvms Date: Thu, 11 Jul 2024 12:41:03 -0400 Subject: [PATCH 01/11] initial pass --- frontend/src/fetchers/activityReports.js | 5 ++ frontend/src/pages/ActivityReport/index.js | 4 +- src/routes/activityReports/handlers.js | 8 ++++ src/routes/activityReports/index.js | 2 + src/services/activityReports.js | 56 +++++++++++++++------- 5 files changed, 56 insertions(+), 19 deletions(-) diff --git a/frontend/src/fetchers/activityReports.js b/frontend/src/fetchers/activityReports.js index 1569eb760f..392899455b 100644 --- a/frontend/src/fetchers/activityReports.js +++ b/frontend/src/fetchers/activityReports.js @@ -102,6 +102,11 @@ export const getRecipients = async (region) => { return recipients.json(); }; +export const getRecipientsForAR = async (region, reportId) => { + const recipients = await get(join(activityReportUrl, 'activity-recipients/', reportId, '/', `?region=${region}`)); + return recipients.json(); +}; + export const getGoals = async (grantIds) => { const params = grantIds.map((grantId) => `grantIds=${grantId}`); const url = join(activityReportUrl, 'goals', `?${params.join('&')}`); diff --git a/frontend/src/pages/ActivityReport/index.js b/frontend/src/pages/ActivityReport/index.js index 41bded708a..efac0b8777 100644 --- a/frontend/src/pages/ActivityReport/index.js +++ b/frontend/src/pages/ActivityReport/index.js @@ -34,7 +34,7 @@ import { submitReport, saveReport, getReport, - getRecipients, + getRecipientsForAR, createReport, getCollaborators, getApprovers, @@ -278,7 +278,7 @@ function ActivityReport({ } const apiCalls = [ - getRecipients(report.regionId), + getRecipientsForAR(report.regionId, reportId.current), getCollaborators(report.regionId), getApprovers(report.regionId), getGroupsForActivityReport(report.regionId), diff --git a/src/routes/activityReports/handlers.js b/src/routes/activityReports/handlers.js index a9b6ae6233..e2aeba2640 100644 --- a/src/routes/activityReports/handlers.js +++ b/src/routes/activityReports/handlers.js @@ -722,6 +722,14 @@ export async function getActivityRecipients(req, res) { res.json(activityRecipients); } +export async function getActivityRecipientsReportId(req, res) { + const { region } = req.query; + const { reportId } = req.params; + const targetRegion = parseInt(region, DECIMAL_BASE); + const activityRecipients = await possibleRecipients(targetRegion, reportId); + res.json(activityRecipients); +} + /** * Retrieve an activity report * diff --git a/src/routes/activityReports/index.js b/src/routes/activityReports/index.js index e787b72cd8..93f74a0ba9 100644 --- a/src/routes/activityReports/index.js +++ b/src/routes/activityReports/index.js @@ -9,6 +9,7 @@ import { getReports, getReportAlerts, getActivityRecipients, + getActivityRecipientsReportId, getGoals, reviewReport, resetToDraft, @@ -40,6 +41,7 @@ router.post('/', transactionWrapper(createReport)); router.get('/approvers', transactionWrapper(getApprovers)); router.get('/groups', transactionWrapper(getGroups)); router.get('/activity-recipients', transactionWrapper(getActivityRecipients)); +router.get('/activity-recipients/:reportId', transactionWrapper(getActivityRecipientsReportId)); router.get('/goals', transactionWrapper(getGoals)); router.post('/goals', transactionWrapper(createGoalsForReport)); router.post('/objectives', transactionWrapper(saveOtherEntityObjectivesForReport)); diff --git a/src/services/activityReports.js b/src/services/activityReports.js index 1e2dcfe398..3edd6432ee 100644 --- a/src/services/activityReports.js +++ b/src/services/activityReports.js @@ -14,6 +14,7 @@ import { ActivityReportCollaborator, ActivityReportFile, sequelize, + Sequelize, ActivityRecipient, File, Grant, @@ -1125,33 +1126,54 @@ export async function setStatus(report, status) { * @param {number} [regionId] - A region id to query against * @returns {*} Grants and Other entities */ -export async function possibleRecipients(regionId) { - const where = { status: 'Active', regionId }; - +export async function possibleRecipients(regionId, activityReportId = null) { const grants = await Recipient.findAll({ - attributes: ['id', 'name'], + attributes: [ + 'id', + 'name', + ], order: ['name'], - include: [{ - where, - model: Grant, - as: 'grants', - attributes: [['id', 'activityRecipientId'], 'name', 'number'], - include: [{ - model: Recipient, - as: 'recipient', - }, + include: [ { - model: Program, - as: 'programs', - attributes: ['programType'], + model: Grant, + as: 'grants', + attributes: ['number', ['id', 'activityRecipientId'], 'name'], + required: true, + include: [ + { + model: Program, + as: 'programs', + attributes: ['programType'], + required: true, + }, + { + model: Recipient, + as: 'recipient', + required: true, + }, + { + model: ActivityRecipient, + as: 'activityRecipients', + attributes: [], + required: false, + }, + ], }, + ], + where: { + '$grants.regionId$': regionId, + [Op.or]: [ + { '$grants.status$': 'Active' }, + { '$grants->activityRecipients.activityReportId$': activityReportId }, ], - }], + }, }); + const otherEntities = await OtherEntity.findAll({ raw: true, attributes: [['id', 'activityRecipientId'], 'name'], }); + return { grants, otherEntities }; } From 5b4dfbf58f1104bd1a1311fe55ad2e042067477a Mon Sep 17 00:00:00 2001 From: nvms Date: Thu, 11 Jul 2024 15:27:49 -0400 Subject: [PATCH 02/11] different call when new vs. not-new --- frontend/src/fetchers/activityReports.js | 2 +- frontend/src/pages/ActivityReport/index.js | 14 ++++++++++++-- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/frontend/src/fetchers/activityReports.js b/frontend/src/fetchers/activityReports.js index 392899455b..c8445237d3 100644 --- a/frontend/src/fetchers/activityReports.js +++ b/frontend/src/fetchers/activityReports.js @@ -102,7 +102,7 @@ export const getRecipients = async (region) => { return recipients.json(); }; -export const getRecipientsForAR = async (region, reportId) => { +export const getRecipientsForExistingAR = async (region, reportId) => { const recipients = await get(join(activityReportUrl, 'activity-recipients/', reportId, '/', `?region=${region}`)); return recipients.json(); }; diff --git a/frontend/src/pages/ActivityReport/index.js b/frontend/src/pages/ActivityReport/index.js index efac0b8777..3d18d855b3 100644 --- a/frontend/src/pages/ActivityReport/index.js +++ b/frontend/src/pages/ActivityReport/index.js @@ -34,13 +34,14 @@ import { submitReport, saveReport, getReport, - getRecipientsForAR, + getRecipientsForExistingAR, createReport, getCollaborators, getApprovers, reviewReport, resetToDraft, getGroupsForActivityReport, + getRecipients, } from '../../fetchers/activityReports'; import useLocalStorage, { setConnectionActiveWithError } from '../../hooks/useLocalStorage'; import NetworkContext, { isOnlineMode } from '../../NetworkContext'; @@ -277,8 +278,17 @@ function ActivityReport({ }; } + const getRecips = async () => { + if (reportId.current && reportId.current !== 'new') { + return getRecipientsForExistingAR(report.regionId, reportId.current); + } + + return getRecipients(report.regionId); + }; + const apiCalls = [ - getRecipientsForAR(report.regionId, reportId.current), + getRecips(), + // getRecipientsForAR(report.regionId, reportId.current), getCollaborators(report.regionId), getApprovers(report.regionId), getGroupsForActivityReport(report.regionId), From aab53502ec6b2146f25da7f38fb8008c9ef34845 Mon Sep 17 00:00:00 2001 From: nvms Date: Thu, 11 Jul 2024 16:10:15 -0400 Subject: [PATCH 03/11] fix AR tests --- frontend/src/fetchers/activityReports.js | 3 ++- frontend/src/pages/ActivityReport/__tests__/index.js | 4 ++++ frontend/src/pages/ActivityReport/index.js | 1 - src/routes/activityReports/handlers.js | 2 +- src/routes/activityReports/index.js | 4 ++-- 5 files changed, 9 insertions(+), 5 deletions(-) diff --git a/frontend/src/fetchers/activityReports.js b/frontend/src/fetchers/activityReports.js index c8445237d3..fa859fe8aa 100644 --- a/frontend/src/fetchers/activityReports.js +++ b/frontend/src/fetchers/activityReports.js @@ -103,7 +103,8 @@ export const getRecipients = async (region) => { }; export const getRecipientsForExistingAR = async (region, reportId) => { - const recipients = await get(join(activityReportUrl, 'activity-recipients/', reportId, '/', `?region=${region}`)); + const url = join(activityReportUrl, 'activity-recipients/', `${reportId}`, '/', `?region=${region}`); + const recipients = await get(url); return recipients.json(); }; diff --git a/frontend/src/pages/ActivityReport/__tests__/index.js b/frontend/src/pages/ActivityReport/__tests__/index.js index 017b0ca7f4..9a2d88f0ea 100644 --- a/frontend/src/pages/ActivityReport/__tests__/index.js +++ b/frontend/src/pages/ActivityReport/__tests__/index.js @@ -42,6 +42,7 @@ describe('ActivityReport', () => { beforeEach(() => { fetchMock.get('/api/activity-reports/activity-recipients?region=1', recipients); + fetchMock.get('/api/activity-reports/activity-recipients/1/?region=1', recipients); fetchMock.get('/api/activity-reports/groups?region=1', [{ id: 110, name: 'Group 1', @@ -155,6 +156,7 @@ describe('ActivityReport', () => { }; fetchMock.get('/api/activity-reports/activity-recipients?region=1', groupRecipients, { overwriteRoutes: true }); + fetchMock.get('/api/activity-reports/activity-recipients/1/?region=1', groupRecipients, { overwriteRoutes: true }); const data = formData(); fetchMock.get('/api/activity-reports/1', { ...data, activityRecipients: [] }); @@ -226,6 +228,7 @@ describe('ActivityReport', () => { }; fetchMock.get('/api/activity-reports/activity-recipients?region=1', groupRecipients, { overwriteRoutes: true }); + fetchMock.get('/api/activity-reports/activity-recipients/1/?region=1', groupRecipients, { overwriteRoutes: true }); const data = formData(); fetchMock.get('/api/activity-reports/1', { ...data, activityRecipients: [] }); @@ -363,6 +366,7 @@ describe('ActivityReport', () => { describe('resetToDraft', () => { it('navigates to the correct page', async () => { + fetchMock.get('/api/activity-reports/activity-recipients/3/?region=1', recipients); const data = formData(); // load the report fetchMock.get('/api/activity-reports/3', { diff --git a/frontend/src/pages/ActivityReport/index.js b/frontend/src/pages/ActivityReport/index.js index 3d18d855b3..7dda972b68 100644 --- a/frontend/src/pages/ActivityReport/index.js +++ b/frontend/src/pages/ActivityReport/index.js @@ -288,7 +288,6 @@ function ActivityReport({ const apiCalls = [ getRecips(), - // getRecipientsForAR(report.regionId, reportId.current), getCollaborators(report.regionId), getApprovers(report.regionId), getGroupsForActivityReport(report.regionId), diff --git a/src/routes/activityReports/handlers.js b/src/routes/activityReports/handlers.js index e2aeba2640..bc3a94f5d0 100644 --- a/src/routes/activityReports/handlers.js +++ b/src/routes/activityReports/handlers.js @@ -722,7 +722,7 @@ export async function getActivityRecipients(req, res) { res.json(activityRecipients); } -export async function getActivityRecipientsReportId(req, res) { +export async function getActivityRecipientsForExistingReport(req, res) { const { region } = req.query; const { reportId } = req.params; const targetRegion = parseInt(region, DECIMAL_BASE); diff --git a/src/routes/activityReports/index.js b/src/routes/activityReports/index.js index 93f74a0ba9..a1fb297327 100644 --- a/src/routes/activityReports/index.js +++ b/src/routes/activityReports/index.js @@ -9,7 +9,7 @@ import { getReports, getReportAlerts, getActivityRecipients, - getActivityRecipientsReportId, + getActivityRecipientsForExistingReport, getGoals, reviewReport, resetToDraft, @@ -41,7 +41,7 @@ router.post('/', transactionWrapper(createReport)); router.get('/approvers', transactionWrapper(getApprovers)); router.get('/groups', transactionWrapper(getGroups)); router.get('/activity-recipients', transactionWrapper(getActivityRecipients)); -router.get('/activity-recipients/:reportId', transactionWrapper(getActivityRecipientsReportId)); +router.get('/activity-recipients/:reportId', transactionWrapper(getActivityRecipientsForExistingReport)); router.get('/goals', transactionWrapper(getGoals)); router.post('/goals', transactionWrapper(createGoalsForReport)); router.post('/objectives', transactionWrapper(saveOtherEntityObjectivesForReport)); From 2c10411678d789e870e8ac3ac66039bac28075e6 Mon Sep 17 00:00:00 2001 From: nvms Date: Thu, 11 Jul 2024 16:11:12 -0400 Subject: [PATCH 04/11] fix localStorage tests --- frontend/src/pages/ActivityReport/__tests__/localStorage.js | 1 + 1 file changed, 1 insertion(+) diff --git a/frontend/src/pages/ActivityReport/__tests__/localStorage.js b/frontend/src/pages/ActivityReport/__tests__/localStorage.js index 206e22e88d..07bb018c43 100644 --- a/frontend/src/pages/ActivityReport/__tests__/localStorage.js +++ b/frontend/src/pages/ActivityReport/__tests__/localStorage.js @@ -37,6 +37,7 @@ describe('Local storage fallbacks', () => { beforeEach(() => { fetchMock.get('/api/activity-reports/activity-recipients?region=1', recipients); + fetchMock.get('/api/activity-reports/activity-recipients/1/?region=1', recipients); fetchMock.get('/api/activity-reports/groups?region=1', []); fetchMock.get('/api/users/collaborators?region=1', []); fetchMock.get('/api/activity-reports/approvers?region=1', []); From 8c2a5e05d593c865b12871fda57e7f1be94fb9ee Mon Sep 17 00:00:00 2001 From: nvms Date: Thu, 11 Jul 2024 16:51:47 -0400 Subject: [PATCH 05/11] don't force programType --- src/services/activityReports.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/services/activityReports.js b/src/services/activityReports.js index 3edd6432ee..6d35b1365b 100644 --- a/src/services/activityReports.js +++ b/src/services/activityReports.js @@ -1144,7 +1144,7 @@ export async function possibleRecipients(regionId, activityReportId = null) { model: Program, as: 'programs', attributes: ['programType'], - required: true, + required: false, }, { model: Recipient, From fd1a662526b188d31493b9415d4e1594612d0ab9 Mon Sep 17 00:00:00 2001 From: nvms Date: Fri, 12 Jul 2024 14:10:41 -0400 Subject: [PATCH 06/11] endpoint path change --- frontend/src/fetchers/activityReports.js | 2 +- frontend/src/pages/ActivityReport/__tests__/index.js | 8 ++++---- .../src/pages/ActivityReport/__tests__/localStorage.js | 2 +- src/routes/activityReports/handlers.js | 4 ++-- src/routes/activityReports/index.js | 1 + 5 files changed, 9 insertions(+), 8 deletions(-) diff --git a/frontend/src/fetchers/activityReports.js b/frontend/src/fetchers/activityReports.js index fa859fe8aa..7340017431 100644 --- a/frontend/src/fetchers/activityReports.js +++ b/frontend/src/fetchers/activityReports.js @@ -103,7 +103,7 @@ export const getRecipients = async (region) => { }; export const getRecipientsForExistingAR = async (region, reportId) => { - const url = join(activityReportUrl, 'activity-recipients/', `${reportId}`, '/', `?region=${region}`); + const url = join(activityReportUrl, `${reportId}`, 'activity-recipients', `?region=${region}`); const recipients = await get(url); return recipients.json(); }; diff --git a/frontend/src/pages/ActivityReport/__tests__/index.js b/frontend/src/pages/ActivityReport/__tests__/index.js index 9a2d88f0ea..0dad5cda20 100644 --- a/frontend/src/pages/ActivityReport/__tests__/index.js +++ b/frontend/src/pages/ActivityReport/__tests__/index.js @@ -42,7 +42,7 @@ describe('ActivityReport', () => { beforeEach(() => { fetchMock.get('/api/activity-reports/activity-recipients?region=1', recipients); - fetchMock.get('/api/activity-reports/activity-recipients/1/?region=1', recipients); + fetchMock.get('/api/activity-reports/1/activity-recipients/?region=1', recipients); fetchMock.get('/api/activity-reports/groups?region=1', [{ id: 110, name: 'Group 1', @@ -156,7 +156,7 @@ describe('ActivityReport', () => { }; fetchMock.get('/api/activity-reports/activity-recipients?region=1', groupRecipients, { overwriteRoutes: true }); - fetchMock.get('/api/activity-reports/activity-recipients/1/?region=1', groupRecipients, { overwriteRoutes: true }); + fetchMock.get('/api/activity-reports/1/activity-recipients/?region=1', groupRecipients, { overwriteRoutes: true }); const data = formData(); fetchMock.get('/api/activity-reports/1', { ...data, activityRecipients: [] }); @@ -228,7 +228,7 @@ describe('ActivityReport', () => { }; fetchMock.get('/api/activity-reports/activity-recipients?region=1', groupRecipients, { overwriteRoutes: true }); - fetchMock.get('/api/activity-reports/activity-recipients/1/?region=1', groupRecipients, { overwriteRoutes: true }); + fetchMock.get('/api/activity-reports/1/activity-recipients/?region=1', groupRecipients, { overwriteRoutes: true }); const data = formData(); fetchMock.get('/api/activity-reports/1', { ...data, activityRecipients: [] }); @@ -366,7 +366,7 @@ describe('ActivityReport', () => { describe('resetToDraft', () => { it('navigates to the correct page', async () => { - fetchMock.get('/api/activity-reports/activity-recipients/3/?region=1', recipients); + fetchMock.get('/api/activity-reports/3/activity-recipients/?region=1', recipients); const data = formData(); // load the report fetchMock.get('/api/activity-reports/3', { diff --git a/frontend/src/pages/ActivityReport/__tests__/localStorage.js b/frontend/src/pages/ActivityReport/__tests__/localStorage.js index 07bb018c43..7ed0e8eb55 100644 --- a/frontend/src/pages/ActivityReport/__tests__/localStorage.js +++ b/frontend/src/pages/ActivityReport/__tests__/localStorage.js @@ -37,7 +37,7 @@ describe('Local storage fallbacks', () => { beforeEach(() => { fetchMock.get('/api/activity-reports/activity-recipients?region=1', recipients); - fetchMock.get('/api/activity-reports/activity-recipients/1/?region=1', recipients); + fetchMock.get('/api/activity-reports/1/activity-recipients/?region=1', recipients); fetchMock.get('/api/activity-reports/groups?region=1', []); fetchMock.get('/api/users/collaborators?region=1', []); fetchMock.get('/api/activity-reports/approvers?region=1', []); diff --git a/src/routes/activityReports/handlers.js b/src/routes/activityReports/handlers.js index bc3a94f5d0..8ace5b3869 100644 --- a/src/routes/activityReports/handlers.js +++ b/src/routes/activityReports/handlers.js @@ -724,9 +724,9 @@ export async function getActivityRecipients(req, res) { export async function getActivityRecipientsForExistingReport(req, res) { const { region } = req.query; - const { reportId } = req.params; + const { activityReportId } = req.params; const targetRegion = parseInt(region, DECIMAL_BASE); - const activityRecipients = await possibleRecipients(targetRegion, reportId); + const activityRecipients = await possibleRecipients(targetRegion, activityReportId); res.json(activityRecipients); } diff --git a/src/routes/activityReports/index.js b/src/routes/activityReports/index.js index a1fb297327..24329cbc91 100644 --- a/src/routes/activityReports/index.js +++ b/src/routes/activityReports/index.js @@ -62,5 +62,6 @@ router.put('/:activityReportId/review', checkActivityReportIdParam, transactionW router.put('/:activityReportId/submit', checkActivityReportIdParam, transactionWrapper(submitReport)); router.put('/:activityReportId/unlock', checkActivityReportIdParam, transactionWrapper(unlockReport)); router.put('/:activityReportId/goals/edit', checkActivityReportIdParam, transactionWrapper(setGoalAsActivelyEdited)); +router.get('/:activityReportId/activity-recipients', transactionWrapper(getActivityRecipientsForExistingReport)); export default router; From 0ef613c0cf1a87cf4e4eaf5b908d5caf917bde88 Mon Sep 17 00:00:00 2001 From: nvms Date: Mon, 15 Jul 2024 08:24:05 -0400 Subject: [PATCH 07/11] update test --- frontend/src/pages/ActivityReport/__tests__/index.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/frontend/src/pages/ActivityReport/__tests__/index.js b/frontend/src/pages/ActivityReport/__tests__/index.js index 0dad5cda20..1164d5b731 100644 --- a/frontend/src/pages/ActivityReport/__tests__/index.js +++ b/frontend/src/pages/ActivityReport/__tests__/index.js @@ -42,7 +42,7 @@ describe('ActivityReport', () => { beforeEach(() => { fetchMock.get('/api/activity-reports/activity-recipients?region=1', recipients); - fetchMock.get('/api/activity-reports/1/activity-recipients/?region=1', recipients); + fetchMock.get('/api/activity-reports/1/activity-recipients?region=1', recipients); fetchMock.get('/api/activity-reports/groups?region=1', [{ id: 110, name: 'Group 1', @@ -156,7 +156,7 @@ describe('ActivityReport', () => { }; fetchMock.get('/api/activity-reports/activity-recipients?region=1', groupRecipients, { overwriteRoutes: true }); - fetchMock.get('/api/activity-reports/1/activity-recipients/?region=1', groupRecipients, { overwriteRoutes: true }); + fetchMock.get('/api/activity-reports/1/activity-recipients?region=1', groupRecipients, { overwriteRoutes: true }); const data = formData(); fetchMock.get('/api/activity-reports/1', { ...data, activityRecipients: [] }); @@ -228,7 +228,7 @@ describe('ActivityReport', () => { }; fetchMock.get('/api/activity-reports/activity-recipients?region=1', groupRecipients, { overwriteRoutes: true }); - fetchMock.get('/api/activity-reports/1/activity-recipients/?region=1', groupRecipients, { overwriteRoutes: true }); + fetchMock.get('/api/activity-reports/1/activity-recipients?region=1', groupRecipients, { overwriteRoutes: true }); const data = formData(); fetchMock.get('/api/activity-reports/1', { ...data, activityRecipients: [] }); @@ -366,7 +366,7 @@ describe('ActivityReport', () => { describe('resetToDraft', () => { it('navigates to the correct page', async () => { - fetchMock.get('/api/activity-reports/3/activity-recipients/?region=1', recipients); + fetchMock.get('/api/activity-reports/3/activity-recipients?region=1', recipients); const data = formData(); // load the report fetchMock.get('/api/activity-reports/3', { From 440a55ac7d9f6b35f69259f9e492b63eabe34f3b Mon Sep 17 00:00:00 2001 From: nvms Date: Mon, 15 Jul 2024 08:30:57 -0400 Subject: [PATCH 08/11] put behind read permissions --- src/routes/activityReports/handlers.js | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/routes/activityReports/handlers.js b/src/routes/activityReports/handlers.js index 8ace5b3869..94048d25d9 100644 --- a/src/routes/activityReports/handlers.js +++ b/src/routes/activityReports/handlers.js @@ -725,6 +725,17 @@ export async function getActivityRecipients(req, res) { export async function getActivityRecipientsForExistingReport(req, res) { const { region } = req.query; const { activityReportId } = req.params; + + const [report] = await activityReportAndRecipientsById(req.params.activityReportId); + const userId = await currentUserId(req, res); + const user = await userById(userId); + const authorization = new ActivityReport(user, report); + + if (!authorization.canGet()) { + res.sendStatus(403); + return; + } + const targetRegion = parseInt(region, DECIMAL_BASE); const activityRecipients = await possibleRecipients(targetRegion, activityReportId); res.json(activityRecipients); From c678a4c38236288ebb435cb3fb57746a51990656 Mon Sep 17 00:00:00 2001 From: nvms Date: Mon, 15 Jul 2024 08:43:52 -0400 Subject: [PATCH 09/11] update test --- frontend/src/pages/ActivityReport/__tests__/localStorage.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontend/src/pages/ActivityReport/__tests__/localStorage.js b/frontend/src/pages/ActivityReport/__tests__/localStorage.js index 7ed0e8eb55..3ab0cc4303 100644 --- a/frontend/src/pages/ActivityReport/__tests__/localStorage.js +++ b/frontend/src/pages/ActivityReport/__tests__/localStorage.js @@ -37,7 +37,7 @@ describe('Local storage fallbacks', () => { beforeEach(() => { fetchMock.get('/api/activity-reports/activity-recipients?region=1', recipients); - fetchMock.get('/api/activity-reports/1/activity-recipients/?region=1', recipients); + fetchMock.get('/api/activity-reports/1/activity-recipients?region=1', recipients); fetchMock.get('/api/activity-reports/groups?region=1', []); fetchMock.get('/api/users/collaborators?region=1', []); fetchMock.get('/api/activity-reports/approvers?region=1', []); From 3a7937465d8c94f5f1d7ca30e0aa2418ac1c2dbc Mon Sep 17 00:00:00 2001 From: nvms Date: Mon, 15 Jul 2024 09:07:41 -0400 Subject: [PATCH 10/11] get region id from the report --- frontend/src/fetchers/activityReports.js | 2 +- frontend/src/pages/ActivityReport/__tests__/index.js | 8 ++++---- .../src/pages/ActivityReport/__tests__/localStorage.js | 2 +- src/routes/activityReports/handlers.js | 5 ++--- 4 files changed, 8 insertions(+), 9 deletions(-) diff --git a/frontend/src/fetchers/activityReports.js b/frontend/src/fetchers/activityReports.js index 7340017431..4cb30d04ea 100644 --- a/frontend/src/fetchers/activityReports.js +++ b/frontend/src/fetchers/activityReports.js @@ -103,7 +103,7 @@ export const getRecipients = async (region) => { }; export const getRecipientsForExistingAR = async (region, reportId) => { - const url = join(activityReportUrl, `${reportId}`, 'activity-recipients', `?region=${region}`); + const url = join(activityReportUrl, `${reportId}`, 'activity-recipients'); const recipients = await get(url); return recipients.json(); }; diff --git a/frontend/src/pages/ActivityReport/__tests__/index.js b/frontend/src/pages/ActivityReport/__tests__/index.js index 1164d5b731..79a2da463d 100644 --- a/frontend/src/pages/ActivityReport/__tests__/index.js +++ b/frontend/src/pages/ActivityReport/__tests__/index.js @@ -42,7 +42,7 @@ describe('ActivityReport', () => { beforeEach(() => { fetchMock.get('/api/activity-reports/activity-recipients?region=1', recipients); - fetchMock.get('/api/activity-reports/1/activity-recipients?region=1', recipients); + fetchMock.get('/api/activity-reports/1/activity-recipients', recipients); fetchMock.get('/api/activity-reports/groups?region=1', [{ id: 110, name: 'Group 1', @@ -156,7 +156,7 @@ describe('ActivityReport', () => { }; fetchMock.get('/api/activity-reports/activity-recipients?region=1', groupRecipients, { overwriteRoutes: true }); - fetchMock.get('/api/activity-reports/1/activity-recipients?region=1', groupRecipients, { overwriteRoutes: true }); + fetchMock.get('/api/activity-reports/1/activity-recipients', groupRecipients, { overwriteRoutes: true }); const data = formData(); fetchMock.get('/api/activity-reports/1', { ...data, activityRecipients: [] }); @@ -228,7 +228,7 @@ describe('ActivityReport', () => { }; fetchMock.get('/api/activity-reports/activity-recipients?region=1', groupRecipients, { overwriteRoutes: true }); - fetchMock.get('/api/activity-reports/1/activity-recipients?region=1', groupRecipients, { overwriteRoutes: true }); + fetchMock.get('/api/activity-reports/1/activity-recipients', groupRecipients, { overwriteRoutes: true }); const data = formData(); fetchMock.get('/api/activity-reports/1', { ...data, activityRecipients: [] }); @@ -366,7 +366,7 @@ describe('ActivityReport', () => { describe('resetToDraft', () => { it('navigates to the correct page', async () => { - fetchMock.get('/api/activity-reports/3/activity-recipients?region=1', recipients); + fetchMock.get('/api/activity-reports/3/activity-recipients', recipients); const data = formData(); // load the report fetchMock.get('/api/activity-reports/3', { diff --git a/frontend/src/pages/ActivityReport/__tests__/localStorage.js b/frontend/src/pages/ActivityReport/__tests__/localStorage.js index 3ab0cc4303..dac60ae551 100644 --- a/frontend/src/pages/ActivityReport/__tests__/localStorage.js +++ b/frontend/src/pages/ActivityReport/__tests__/localStorage.js @@ -37,7 +37,7 @@ describe('Local storage fallbacks', () => { beforeEach(() => { fetchMock.get('/api/activity-reports/activity-recipients?region=1', recipients); - fetchMock.get('/api/activity-reports/1/activity-recipients?region=1', recipients); + fetchMock.get('/api/activity-reports/1/activity-recipients', recipients); fetchMock.get('/api/activity-reports/groups?region=1', []); fetchMock.get('/api/users/collaborators?region=1', []); fetchMock.get('/api/activity-reports/approvers?region=1', []); diff --git a/src/routes/activityReports/handlers.js b/src/routes/activityReports/handlers.js index 94048d25d9..7b6189879d 100644 --- a/src/routes/activityReports/handlers.js +++ b/src/routes/activityReports/handlers.js @@ -723,10 +723,9 @@ export async function getActivityRecipients(req, res) { } export async function getActivityRecipientsForExistingReport(req, res) { - const { region } = req.query; const { activityReportId } = req.params; - const [report] = await activityReportAndRecipientsById(req.params.activityReportId); + const [report] = await activityReportAndRecipientsById(activityReportId); const userId = await currentUserId(req, res); const user = await userById(userId); const authorization = new ActivityReport(user, report); @@ -736,7 +735,7 @@ export async function getActivityRecipientsForExistingReport(req, res) { return; } - const targetRegion = parseInt(region, DECIMAL_BASE); + const targetRegion = parseInt(report.regionId, DECIMAL_BASE); const activityRecipients = await possibleRecipients(targetRegion, activityReportId); res.json(activityRecipients); } From 7cd85f703eefdf68f8e00850bc8f789b0ff14ba7 Mon Sep 17 00:00:00 2001 From: nvms Date: Mon, 15 Jul 2024 09:11:47 -0400 Subject: [PATCH 11/11] dont pass region id --- frontend/src/fetchers/activityReports.js | 2 +- frontend/src/pages/ActivityReport/index.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/frontend/src/fetchers/activityReports.js b/frontend/src/fetchers/activityReports.js index 4cb30d04ea..6f98a9dcd8 100644 --- a/frontend/src/fetchers/activityReports.js +++ b/frontend/src/fetchers/activityReports.js @@ -102,7 +102,7 @@ export const getRecipients = async (region) => { return recipients.json(); }; -export const getRecipientsForExistingAR = async (region, reportId) => { +export const getRecipientsForExistingAR = async (reportId) => { const url = join(activityReportUrl, `${reportId}`, 'activity-recipients'); const recipients = await get(url); return recipients.json(); diff --git a/frontend/src/pages/ActivityReport/index.js b/frontend/src/pages/ActivityReport/index.js index 7dda972b68..323bb0f5d8 100644 --- a/frontend/src/pages/ActivityReport/index.js +++ b/frontend/src/pages/ActivityReport/index.js @@ -280,7 +280,7 @@ function ActivityReport({ const getRecips = async () => { if (reportId.current && reportId.current !== 'new') { - return getRecipientsForExistingAR(report.regionId, reportId.current); + return getRecipientsForExistingAR(reportId.current); } return getRecipients(report.regionId);