Skip to content

Commit

Permalink
hide projects with malformed grid data
Browse files Browse the repository at this point in the history
  • Loading branch information
hotzevzl committed Oct 12, 2023
1 parent cc69aa1 commit dee0d41
Showing 1 changed file with 34 additions and 5 deletions.
39 changes: 34 additions & 5 deletions api/apps/api/src/modules/projects/projects-crud.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ import { ProjectId, SetProjectGridFromShapefile } from './planning-unit-grid';
import { ProjectRoles } from '@marxan-api/modules/access-control/projects-acl/dto/user-role-project.dto';
import { Roles } from '@marxan-api/modules/access-control/role.api.entity';
import { PlanningUnitGridShape } from '@marxan/scenarios-planning-unit';
import { PublishedProject } from '../published-project/entities/published-project.api.entity';
import { CostSurfaceId } from '@marxan-api/modules/projects/planning-unit-grid/project.id';
import { getDefaultCostSurfaceIdFromProject } from '@marxan-api/modules/projects/get-default-project-cost-surface';

Expand Down Expand Up @@ -61,8 +60,6 @@ export class ProjectsCrudService extends AppBaseService<
private readonly userProjects: Repository<UsersProjectsApiEntity>,
@InjectRepository(ProtectedArea, DbConnections.geoprocessingDB)
private readonly protectedAreas: Repository<ProtectedArea>,
@InjectRepository(PublishedProject)
private readonly publishedProjects: Repository<PublishedProject>,
private readonly commandBus: CommandBus,
) {
super(repository, 'project', 'projects', {
Expand Down Expand Up @@ -128,6 +125,34 @@ export class ProjectsCrudService extends AppBaseService<
return query;
}

/**
* In some cases, newly-created projects may not have any of the grid-related
* data: either a GADM id (if the project was created using a GADM area as
* planning area) or a planning area geometry id (if the user uploaded a
* shapefile with the project's planning area or planning grid).
*
* This could either be a temporary state (while the planning grid is being
* created in geodb) or an error situation. Either way, allowing users to
* "discover" such projects (e.g. when requesting a list of projects they
* have access to) is not desirable, as no meaningful work can be done when
* a project is in a state like this. Therefore, we hide such projects from
* the results of `findAll()` and `getById()` queries.
*/
private async hideProjectsWithIncompleteGridData(
query: SelectQueryBuilder<Project>,
): Promise<SelectQueryBuilder<Project>> {
query.andWhere(`NOT(
${this.alias}.country_id IS NULL
AND
${this.alias}.admin_area_l1_id IS NULL
AND
${this.alias}.admin_area_l2_id IS NULL
AND
${this.alias}.planning_area_geometry_id IS NULL
)`);
return query;
}

async setDataCreate(
create: CreateProjectDTO,
info?: ProjectsRequest,
Expand Down Expand Up @@ -264,8 +289,8 @@ export class ProjectsCrudService extends AppBaseService<

async extendGetByIdQuery(
query: SelectQueryBuilder<Project>,
fetchSpecification?: FetchSpecification,
info?: ProjectsRequest,
_fetchSpecification?: FetchSpecification,
_info?: ProjectsRequest,
): Promise<SelectQueryBuilder<Project>> {
/**
* Bring in publicMetadata (if the project has been made public). This is
Expand All @@ -274,6 +299,8 @@ export class ProjectsCrudService extends AppBaseService<
*/
query.leftJoinAndSelect('project.publicMetadata', 'publicMetadata');

this.hideProjectsWithIncompleteGridData(query);

return query;
}

Expand Down Expand Up @@ -318,6 +345,8 @@ export class ProjectsCrudService extends AppBaseService<
);
}

this.hideProjectsWithIncompleteGridData(query);

if (loggedUser) {
query
.andWhere(`acl.user_id = :userId`, {
Expand Down

0 comments on commit dee0d41

Please sign in to comment.