Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nert 689 - Downloading masks from all list exports #251

Merged
merged 11 commits into from
Oct 4, 2024
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 { 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 @@
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 @@
// 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);

Check warning on line 381 in api/src/paths/plan/list.ts

View check run for this annotation

Codecov / codecov/patch

api/src/paths/plan/list.ts#L381

Added line #L381 was not covered by tests
});
plan.location.geometry = maskFilter;

Check warning on line 383 in api/src/paths/plan/list.ts

View check run for this annotation

Codecov / codecov/patch

api/src/paths/plan/list.ts#L383

Added line #L383 was not covered by tests
});

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 { 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 @@
// 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);

Check warning on line 582 in api/src/paths/project/list.ts

View check run for this annotation

Codecov / codecov/patch

api/src/paths/project/list.ts#L582

Added line #L582 was not covered by tests
});
project.location.geometry = maskFilter;

Check warning on line 584 in api/src/paths/project/list.ts

View check run for this annotation

Codecov / codecov/patch

api/src/paths/project/list.ts#L584

Added line #L584 was not covered by tests
});

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 { 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 @@
// Get all projects data for the projectIds
const projects = await planService.getPlansByIds(projectIds, true);

// Mask geometries that require it
projects.forEach((project) => {
popkinj marked this conversation as resolved.
Show resolved Hide resolved
if (!project.location?.geometry) return; // Skip if no geometry
const maskFilter = project.location.geometry?.map((feature) => {
return maskGateKeeper(feature);

Check warning on line 362 in api/src/paths/public/plans.ts

View check run for this annotation

Codecov / codecov/patch

api/src/paths/public/plans.ts#L362

Added line #L362 was not covered by tests
});

project.location.geometry = maskFilter;

Check warning on line 365 in api/src/paths/public/plans.ts

View check run for this annotation

Codecov / codecov/patch

api/src/paths/public/plans.ts#L365

Added line #L365 was not covered by tests
});

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 { 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 @@
// 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);

Check warning on line 548 in api/src/paths/public/projects.ts

View check run for this annotation

Codecov / codecov/patch

api/src/paths/public/projects.ts#L548

Added line #L548 was not covered by tests
});

project.location.geometry = maskFilter;

Check warning on line 551 in api/src/paths/public/projects.ts

View check run for this annotation

Codecov / codecov/patch

api/src/paths/public/projects.ts#L551

Added line #L551 was not covered by tests
});

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}
popkinj marked this conversation as resolved.
Show resolved Hide resolved
/>
);

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
Loading