Skip to content

Commit

Permalink
feat: adds decorator to ACL-ready endpoints in projects
Browse files Browse the repository at this point in the history
  • Loading branch information
rubvalave authored and hotzevzl committed Jan 10, 2022
1 parent 68b6a17 commit f663867
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ import {
UsersInProjectResult,
} from '@marxan-api/modules/access-control/projects-acl/dto/user-role-project.dto';
import { aclErrorHandler } from '@marxan-api/utils/acl.utils';
import { IsMissingAclImplementation } from '@marxan-api/decorators/acl.decorator';
import { ImplementsAcl } from '@marxan-api/decorators/acl.decorator';

@IsMissingAclImplementation()
@ImplementsAcl()
@UseGuards(JwtAuthGuard)
@ApiBearerAuth()
@ApiTags('Projects-Users Roles')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ import {
UsersInScenarioResult,
} from '@marxan-api/modules/access-control/scenarios-acl/dto/user-role-scenario.dto';
import { aclErrorHandler } from '@marxan-api/utils/acl.utils';
import { IsMissingAclImplementation } from '@marxan-api/decorators/acl.decorator';
import { ImplementsAcl } from '@marxan-api/decorators/acl.decorator';

@IsMissingAclImplementation()
@ImplementsAcl()
@UseGuards(JwtAuthGuard)
@ApiBearerAuth()
@ApiTags('Scenarios-Users Roles')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import { notFound, ProjectsService } from './projects.service';
import { ProjectSerializer } from './dto/project.serializer';
import { isLeft } from 'fp-ts/lib/Either';
import { forbiddenError } from '../access-control';
import { IsMissingAclImplementation } from '@marxan-api/decorators/acl.decorator';
import { ImplementsAcl } from '@marxan-api/decorators/acl.decorator';

@ApiTags(projectResource.className)
@Controller(`${apiGlobalPrefixes.v1}/projects`)
Expand All @@ -37,7 +37,7 @@ export class ProjectDetailsController {
) {}

@ApiBearerAuth()
@IsMissingAclImplementation()
@ImplementsAcl()
@UseGuards(JwtAuthGuard)
@SingleProject()
@Get(':id')
Expand Down
26 changes: 19 additions & 7 deletions api/apps/api/src/modules/projects/projects.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,11 @@ import {
import { forbiddenError } from '../access-control/access-control.types';
import { projectNotFound, unknownError } from '../blm';
import { Response } from 'express';
import { IsMissingAclImplementation } from '@marxan-api/decorators/acl.decorator';
import {
ImplementsAcl,
IsMissingAclImplementation,
} from '@marxan-api/decorators/acl.decorator';

@IsMissingAclImplementation()
@UseGuards(JwtAuthGuard)
@ApiBearerAuth()
@ApiTags(projectResource.className)
Expand All @@ -91,10 +93,11 @@ export class ProjectsController {
private readonly geoFeatureSerializer: GeoFeatureSerializer,
private readonly geoFeatureService: GeoFeaturesService,
private readonly projectSerializer: ProjectSerializer,
private readonly jobsStatusSerizalizer: JobStatusSerializer,
private readonly jobsStatusSerializer: JobStatusSerializer,
private readonly shapefileService: ShapefileService,
) {}

@IsMissingAclImplementation()
@ApiOperation({
description: 'Find all geo features',
})
Expand Down Expand Up @@ -136,6 +139,7 @@ export class ProjectsController {
*
* @debt We may want to use a custom interceptor to process import files
*/
@ImplementsAcl()
@ApiOperation({
description: 'Import a Marxan project via file upload',
summary: 'Import a Marxan project',
Expand All @@ -158,6 +162,7 @@ export class ProjectsController {
return result.right;
}

@ImplementsAcl()
@ApiOperation({ description: 'Create project' })
@ApiOkResponse({ type: ProjectResultSingular })
@ApiTags(asyncJobTag)
Expand All @@ -181,6 +186,7 @@ export class ProjectsController {
);
}

@ImplementsAcl()
@ApiOperation({ description: 'Update project' })
@ApiOkResponse({ type: ProjectResultSingular })
@ApiTags(asyncJobTag)
Expand All @@ -202,6 +208,7 @@ export class ProjectsController {
);
}

@ImplementsAcl()
@ApiOperation({ description: 'Delete project' })
@ApiOkResponse()
@Delete(':id')
Expand All @@ -217,6 +224,7 @@ export class ProjectsController {
return result.right;
}

@IsMissingAclImplementation()
@ApiConsumesShapefile({ withGeoJsonResponse: false })
@ApiOperation({
description: 'Upload shapefile for project-specific planning unit grid',
Expand All @@ -238,6 +246,7 @@ export class ProjectsController {
return result.right;
}

@IsMissingAclImplementation()
@ApiOperation({
description: `Find running jobs for each scenario under given project`,
})
Expand All @@ -253,12 +262,10 @@ export class ProjectsController {
authenticatedUser: req.user,
},
);
return this.jobsStatusSerizalizer.serialize(
projectId,
projectWithScenarios,
);
return this.jobsStatusSerializer.serialize(projectId, projectWithScenarios);
}

@IsMissingAclImplementation()
@ApiConsumesShapefile({
withGeoJsonResponse: true,
type: PlanningAreaResponseDto,
Expand Down Expand Up @@ -286,6 +293,7 @@ export class ProjectsController {
return result.right;
}

@IsMissingAclImplementation()
@ApiConsumesShapefile({ withGeoJsonResponse: false })
@ApiOperation({
description: `Upload shapefiles of species or bioregional features.`,
Expand Down Expand Up @@ -314,6 +322,7 @@ export class ProjectsController {
return { success: true };
}

@ImplementsAcl()
@ApiOperation({
description: 'Updates the project BLM range and calculate its values',
})
Expand Down Expand Up @@ -357,6 +366,7 @@ export class ProjectsController {
return result.right;
}

@ImplementsAcl()
@ApiOperation({
description: 'Shows the project BLM values of a project',
})
Expand Down Expand Up @@ -390,13 +400,15 @@ export class ProjectsController {
return result.right;
}

@IsMissingAclImplementation()
@Post(`:id/export`)
async requestProjectExport(@Param('id') id: string) {
return {
id: await this.projectsService.requestExport(id),
};
}

@IsMissingAclImplementation()
@Get(`:id/export/:exportId`)
@Header(`Content-Type`, `application/zip`)
@Header('Content-Disposition', 'attachment; filename="export.zip"')
Expand Down

0 comments on commit f663867

Please sign in to comment.