Skip to content

Commit

Permalink
Nert 689 - Downloading masks from all list exports (#251)
Browse files Browse the repository at this point in the history
  • Loading branch information
popkinj authored Oct 4, 2024
1 parent a26ba99 commit 1f1a188
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 1 deletion.
12 changes: 11 additions & 1 deletion api/src/paths/plan/list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand Down Expand Up @@ -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);

Expand All @@ -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);
Expand Down
10 changes: 10 additions & 0 deletions api/src/paths/project/list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand Down Expand Up @@ -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);
Expand Down
11 changes: 11 additions & 0 deletions api/src/paths/public/plans.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand Down Expand Up @@ -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);
Expand Down
12 changes: 12 additions & 0 deletions api/src/paths/public/projects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand Down Expand Up @@ -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);
Expand Down
2 changes: 2 additions & 0 deletions app/src/components/map/MapContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1053,6 +1053,7 @@ const initializeMap = (
size_ha={sizeHa}
state_code={stateCode}
thumbnail={thumbnail}
maskDisclaimer={true}
/>
);

Expand Down Expand Up @@ -1100,6 +1101,7 @@ const initializeMap = (
size_ha={sizeHa}
state_code={stateCode}
thumbnail={thumbnail}
maskDisclaimer={true}
/>
);

Expand Down
7 changes: 7 additions & 0 deletions app/src/components/map/components/Popup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export interface MapPopupProps {
thumbnail?: string;
maskedLocation?: boolean;
hideButton?: boolean;
maskDisclaimer?: boolean;
}

const MapPopup = (props: any) => {
Expand All @@ -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';
Expand Down Expand Up @@ -108,6 +110,11 @@ const MapPopup = (props: any) => {
{maskedLocation && (
<div style={style.attention}>Location sensitive site - see FOIPPA 16, 17, 18 & 18.1.</div>
)}
{maskDisclaimer && (
<div style={style.attention}>
Point location is approximate and does not represent the exact location of the site.
</div>
)}
{!hideButton && (
<div>
<a href={`/${isProject ? 'projects' : 'plans'}/${id}`}>
Expand Down

0 comments on commit 1f1a188

Please sign in to comment.