From 1f1a1882526f9c6a2275ae3521bcd8f1f400c372 Mon Sep 17 00:00:00 2001 From: Jamie Popkin Date: Fri, 4 Oct 2024 14:50:14 -0700 Subject: [PATCH] Nert 689 - Downloading masks from all list exports (#251) --- api/src/paths/plan/list.ts | 12 +++++++++++- api/src/paths/project/list.ts | 10 ++++++++++ api/src/paths/public/plans.ts | 11 +++++++++++ api/src/paths/public/projects.ts | 12 ++++++++++++ app/src/components/map/MapContainer.tsx | 2 ++ app/src/components/map/components/Popup.tsx | 7 +++++++ 6 files changed, 53 insertions(+), 1 deletion(-) diff --git a/api/src/paths/plan/list.ts b/api/src/paths/plan/list.ts index 19e2e040..ecbd9f37 100644 --- a/api/src/paths/plan/list.ts +++ b/api/src/paths/plan/list.ts @@ -6,6 +6,7 @@ import { authorizeRequestHandler } from '../../request-handlers/security/authori import { PlanService } from '../../services/plan-service'; import { PlanSearchCriteria, ProjectSearchCriteria, SearchService } from '../../services/search-service'; import { getLogger } from '../../utils/logger'; +import { maskGateKeeper } from '../../utils/spatial-utils'; const defaultLog = getLogger('paths/plan/list'); @@ -362,7 +363,6 @@ export function getPlansList(): RequestHandler { ha_from: searchCriteria.plan_ha_from }; - console.log('projectSearchCriteria', projectSearchCriteria); // Fetch all planIds that match the search criteria const planIdsResponse = await searchService.findProjectIdsByCriteria(projectSearchCriteria); @@ -373,6 +373,16 @@ export function getPlansList(): RequestHandler { // Get all plans data for the planIds const plans = await planService.getPlansByIds(planIds); + // Mask private geometries + plans.forEach((plan) => { + if (!plan.location?.geometry) return; // Skip if no geometry + + const maskFilter = plan.location.geometry?.map((feature) => { + return maskGateKeeper(feature); + }); + plan.location.geometry = maskFilter; + }); + await connection.commit(); return res.status(200).json(plans); diff --git a/api/src/paths/project/list.ts b/api/src/paths/project/list.ts index d5718df3..75201f1c 100644 --- a/api/src/paths/project/list.ts +++ b/api/src/paths/project/list.ts @@ -6,6 +6,7 @@ import { authorizeRequestHandler } from '../../request-handlers/security/authori import { ProjectService } from '../../services/project-service'; import { ProjectSearchCriteria, SearchService } from '../../services/search-service'; import { getLogger } from '../../utils/logger'; +import { maskGateKeeper } from '../../utils/spatial-utils'; const defaultLog = getLogger('paths/projects/list'); @@ -574,6 +575,15 @@ export function getProjectsPlansList(): RequestHandler { // Get all projects data for the projectIds const projects = await projectService.getProjectsByIds(projectIds); + // Mask private geometries + projects.forEach((project) => { + if (!project.location?.geometry) return; // Skip if no geometry + const maskFilter = project.location.geometry?.map((feature) => { + return maskGateKeeper(feature); + }); + project.location.geometry = maskFilter; + }); + await connection.commit(); return res.status(200).json(projects); diff --git a/api/src/paths/public/plans.ts b/api/src/paths/public/plans.ts index 5912df27..8706b683 100644 --- a/api/src/paths/public/plans.ts +++ b/api/src/paths/public/plans.ts @@ -5,6 +5,7 @@ import { geoJsonFeature } from '../../openapi/schemas/geoJson'; import { PlanService } from '../../services/plan-service'; import { PlanSearchCriteria, ProjectSearchCriteria, SearchService } from '../../services/search-service'; import { getLogger } from '../../utils/logger'; +import { maskGateKeeper } from '../../utils/spatial-utils'; const defaultLog = getLogger('paths/public/plans'); @@ -354,6 +355,16 @@ export function getPublicPlansList(): RequestHandler { // Get all projects data for the projectIds const projects = await planService.getPlansByIds(projectIds, true); + // Mask geometries that require it + projects.forEach((project) => { + if (!project.location?.geometry) return; // Skip if no geometry + const maskFilter = project.location.geometry?.map((feature) => { + return maskGateKeeper(feature); + }); + + project.location.geometry = maskFilter; + }); + await connection.commit(); return res.status(200).json(projects); diff --git a/api/src/paths/public/projects.ts b/api/src/paths/public/projects.ts index 35191445..da6ae5ac 100644 --- a/api/src/paths/public/projects.ts +++ b/api/src/paths/public/projects.ts @@ -5,6 +5,7 @@ import { geoJsonFeature } from '../../openapi/schemas/geoJson'; import { ProjectService } from '../../services/project-service'; import { ProjectSearchCriteria, SearchService } from '../../services/search-service'; import { getLogger } from '../../utils/logger'; +import { maskGateKeeper } from '../../utils/spatial-utils'; const defaultLog = getLogger('paths/public/projects'); @@ -539,6 +540,17 @@ export function getPublicProjectsPlansList(): RequestHandler { // Get all projects data for the projectIds const projects = await projectService.getProjectsByIds(projectIds, true); + // Mask the geometries for all projects + projects.forEach((project) => { + if (!project.location?.geometry) return; // Skip if no geometry + + const maskFilter = project.location.geometry?.map((feature) => { + return maskGateKeeper(feature); + }); + + project.location.geometry = maskFilter; + }); + await connection.commit(); return res.status(200).json(projects); diff --git a/app/src/components/map/MapContainer.tsx b/app/src/components/map/MapContainer.tsx index df299def..53b5d771 100644 --- a/app/src/components/map/MapContainer.tsx +++ b/app/src/components/map/MapContainer.tsx @@ -1053,6 +1053,7 @@ const initializeMap = ( size_ha={sizeHa} state_code={stateCode} thumbnail={thumbnail} + maskDisclaimer={true} /> ); @@ -1100,6 +1101,7 @@ const initializeMap = ( size_ha={sizeHa} state_code={stateCode} thumbnail={thumbnail} + maskDisclaimer={true} /> ); diff --git a/app/src/components/map/components/Popup.tsx b/app/src/components/map/components/Popup.tsx index 6d9363e8..438d370d 100644 --- a/app/src/components/map/components/Popup.tsx +++ b/app/src/components/map/components/Popup.tsx @@ -11,6 +11,7 @@ export interface MapPopupProps { thumbnail?: string; maskedLocation?: boolean; hideButton?: boolean; + maskDisclaimer?: boolean; } const MapPopup = (props: any) => { @@ -23,6 +24,7 @@ const MapPopup = (props: any) => { const thumbnail = props.thumbnail; const maskedLocation = props.maskedLocation || false; const hideButton = props.hideButton || false; + const maskDisclaimer = props.maskDisclaimer || false; // Project if true, Plan if false, Site if undefined/null const siteType = (isProject && 'Project') || (isProject === false && 'Plan') || 'Site'; @@ -108,6 +110,11 @@ const MapPopup = (props: any) => { {maskedLocation && (
Location sensitive site - see FOIPPA 16, 17, 18 & 18.1.
)} + {maskDisclaimer && ( +
+ Point location is approximate and does not represent the exact location of the site. +
+ )} {!hideButton && (