Skip to content

Commit

Permalink
Merge branch 'main' into ETL-Branch
Browse files Browse the repository at this point in the history
  • Loading branch information
dbarkowsky authored Aug 2, 2024
2 parents 8ab32c7 + f37b7a9 commit 93db4e5
Show file tree
Hide file tree
Showing 91 changed files with 1,650 additions and 2,266 deletions.
4 changes: 2 additions & 2 deletions .env-template
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ CSS_API_CLIENT_SECRET= # Keycloak CSS API Service Account client_secret
# BC Geocoder
GEOCODER_KEY=

# Error Report
ERROR_REPORT_TO=
# Contact
CONTACT_EMAIL=

# CHES Settings
CHES_USERNAME=
Expand Down
2 changes: 1 addition & 1 deletion express-api/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ Recommended values used with this API that match with the current API and Docker
|SSO_INTEGRATION_ID|1234|See Keycloak integration. Used for CSS API.|
|SSO_ENVIRONMENT|dev|Target environment of Keycloak integration. Used for CSS API.|
|GEOCODER_KEY|abc123|API key for BC Geocoder use.|
|ERROR_REPORT_TO|<[email protected]>|Destination email for frontend error reporting.|
|CONTACT_EMAIL|<[email protected]>|Destination email for frontend error reporting and help.|
|CHES_USERNAME|abc123|Username for CHES service.|
|CHES_PASSWORD|def456|Password for CHES service.|
|CHES_AUTH_URL|https://...|URL where authorization tokens for CHES are obtained.|
Expand Down
6 changes: 4 additions & 2 deletions express-api/src/constants/config.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
const config = {
ches: {
username: process.env.CHES_USERNAME,
password: process.env.CHES_PASSWORD,
usersToBcc: process.env.CHES_ALWAYS_BCC, // Semi-colon separated list of emails to include in the BCC
defaultFrom: process.env.CHES_DEFAULT_FROM, // Default to this for the from field if email does not supply it.
overrideTo: process.env.CHES_OVERRIDE_TO, // Override the to field to this every time, useful for testing.
Expand All @@ -23,8 +25,8 @@ const config = {
notificationTemplate: 15,
notificationTemplateRPD: 17,
},
errorReport: {
toEmail: process.env.ERROR_REPORT_TO,
contact: {
toEmail: process.env.CONTACT_EMAIL,
},
notificationTemplate: {
title: 'PIMS',
Expand Down
10 changes: 0 additions & 10 deletions express-api/src/constants/credentials.ts

This file was deleted.

2 changes: 1 addition & 1 deletion express-api/src/constants/networking.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ let backendUrl = BACKEND_URL ?? '';
const apiPort = +(API_HTTP_PORT ?? 5000);
const frontendPort = +(APP_HTTP_PORT ?? 3000);

// Use production urls unless CONTAINERIZED.
// Use URLs from ENV when CONTAINERIZED.
if (!CONTAINERIZED) {
frontendUrl = `http://localhost:${frontendPort}`;
backendUrl = `http://localhost:${apiPort}`;
Expand Down
4 changes: 4 additions & 0 deletions express-api/src/constants/projectRisk.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
/**
* @enum
* Enum corresponding to the ID in project_risk table
*/
export enum ProjectRisk {
GREEN = 1,
YELLOW = 2,
Expand Down
25 changes: 13 additions & 12 deletions express-api/src/constants/projectStatus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,31 @@
* Contains past and current project statuses and their IDs.
*/
export enum ProjectStatus {
DRAFT = 1,
SELECT_PROPERTIES = 2,
UPDATE_INFORMATION = 3,
// DRAFT = 1, // Disabled
// SELECT_PROPERTIES = 2, // Disabled
// UPDATE_INFORMATION = 3, // Disabled
REQUIRED_DOCUMENTATION = 4,
APPROVAL = 5,
REVIEW = 6,
// APPROVAL = 5, // Disabled
// REVIEW = 6, // Disabled
SUBMITTED = 7,
SUBMITTED_EXEMPTION = 8,
DOCUMENT_REVIEW = 10,
APPRAISAL_REVIEW = 11,
FIRST_NATION_CONSULTATION = 12,
EXEMPTION_REVIEW = 13,
// DOCUMENT_REVIEW = 10, // Disabled
// APPRAISAL_REVIEW = 11, // Disabled
// FIRST_NATION_CONSULTATION = 12, // Disabled
// EXEMPTION_REVIEW = 13, // Disabled
APPROVED_FOR_ERP = 14,
APPROVED_FOR_EXEMPTION = 15,
DENIED = 16,
TRANSFERRED_WITHIN_GRE = 20,
APPROVED_FOR_SPL = 21,
NOT_IN_SPL = 22,
CANCELLED = 23,
IN_ERP = 30,
// IN_ERP = 30, // Disabled
ON_HOLD = 31,
DISPOSED = 32,
PRE_MARKETING = 40,
ON_MARKET = 41,
CONTRACT_IN_PLACE_CONDITIONAL = 42,
CONTRACT_IN_PLACE_UNCONDITIONAL = 43,
CONTRACT_IN_PLACE = 42, // Previously CONTRACT_IN_PLACE_CONDITIONAL
// CONTRACT_IN_PLACE_UNCONDITIONAL = 43, // Disabled
CLOSE_OUT = 44,
}
18 changes: 16 additions & 2 deletions express-api/src/constants/projectTask.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
/**
* @enum
* Enum corresponding to the ID in task table
*/
export enum ProjectTask {
SURPLUS_DECLARATION_READINESS = 1,
TRIPLE_BOTTOM_LINE = 2,
Expand All @@ -12,6 +16,16 @@ export enum ProjectTask {
FN_CONSULTATION_COMPLETE = 11,
NOTIFICATION_EXEMPTION_TO_ADM = 12,
CONFIRMATION_RECEIVED_FROM_ADM = 13,
APPRAISAL_ORDERED_DUPLICATE = 14, // DUPLICATE - DO NOT USE
APPRAISAL_RECEIVED_DUPLICATE = 15, // DUPLICATE - DO NOT USE
// 14 & 15 removed with new PIMS
EXEMPTION_REQUESTED = 16,
PRIOR_YEAR_ADJUSTMENT = 17,
// These are duplicates to handle Approved for Exemption status
DOCUMENTS_RECEIVED_REVIEW_COMPLETED_EXEMPT = 18,
PREPARATION_DUE_DILIGENCE_EXEMPT = 19,
FN_CONSULTATION_UNDERWAY_EXEMPT = 20,
FN_CONSULTATION_COMPLETE_EXEMPT = 21,
APPRAISAL_ORDERED_EXEMPT = 22,
APPRAISAL_RECEIVED_EXEMPT = 23,
// End of intentional duplicates
CONTRACT_IS_CONDITIONAL = 24,
}
4 changes: 4 additions & 0 deletions express-api/src/constants/projectType.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
/**
* @enum
* Currently only one Project Type
*/
export enum ProjectType {
DISPOSAL = 1,
}
4 changes: 4 additions & 0 deletions express-api/src/constants/projectWorkflow.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
/**
* @enum
* Workflow model was partially replaced in new PIMS. ERP and SPL workflows are not currently assigned.
*/
export enum ProjectWorkflow {
SUBMIT_DISPOSAL = 1,
ERP = 5,
Expand Down
6 changes: 5 additions & 1 deletion express-api/src/constants/propertyType.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
/**
* @enum
* Defines type of property
*/
export enum PropertyType {
LAND = 0,
BUILDING = 1,
SUBDIVISION = 2,
SUBDIVISION = 2, // Possible in original PIMS only.
}
4 changes: 4 additions & 0 deletions express-api/src/constants/roles.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
/**
* @enum
* The values in this enum must exactly mirror the names of the Keycloak roles.
*/
export enum Roles {
ADMIN = 'Administrator',
GENERAL_USER = 'General User',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { Request, Response } from 'express';
import { stubResponse } from '@/utilities/stubResponse';
import { SSOUser } from '@bcgov/citz-imb-sso-express';
import {
AdministrativeAreaFilterSchema,
Expand Down Expand Up @@ -60,23 +59,6 @@ export const addAdministrativeArea = async (req: Request, res: Response) => {
return res.status(201).send(response);
};

/**
* @description Gets a list of administrative areas based on a filter.
* @param {Request} req Incoming request
* @param {Response} res Outgoing response
* @returns {Response} A 200 status with a list of administrative areas.
*/
export const getAdministrativeAreasFiltered = async (req: Request, res: Response) => {
/**
* #swagger.tags = ['Administrative Areas - Admin']
* #swagger.description = 'Returns a paged list of administrative areas from the datasource based on a supplied filter.'
* #swagger.security = [{
"bearerAuth": []
}]
*/
return stubResponse(res);
};

/**
* @description Gets a single administrative area that matches an ID.
* @param {Request} req Incoming request
Expand Down Expand Up @@ -119,22 +101,3 @@ export const updateAdministrativeAreaById = async (req: Request, res: Response)
const update = await administrativeAreasServices.updateAdministrativeArea(req.body);
return res.status(200).send(update);
};

/**
* @description Deletes a single administrative area that matches an ID.
* @param {Request} req Incoming request
* @param {Response} res Outgoing response
* @returns {Response} A 204 status indicating successful deletion.
*/
export const deleteAdministrativeAreaById = async (req: Request, res: Response) => {
/**
* #swagger.tags = ['Administrative Areas - Admin']
* #swagger.description = 'Deletes an administrative area that matches the supplied ID.'
* #swagger.security = [{
"bearerAuth": []
}]
*/

// TODO: Replace stub response with controller logic
return stubResponse(res);
};
7 changes: 5 additions & 2 deletions express-api/src/controllers/buildings/buildingsController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import userServices from '@/services/users/usersServices';
import { SSOUser } from '@bcgov/citz-imb-sso-express';
import { Building } from '@/typeorm/Entities/Building';
import { checkUserAgencyPermission, isAdmin, isAuditor } from '@/utilities/authorizationChecks';
import { Roles } from '@/constants/roles';

/**
* @description Gets all buildings satisfying the filter parameters.
Expand Down Expand Up @@ -52,12 +53,14 @@ export const getBuilding = async (req: Request, res: Response) => {
return res.status(400).send('Building Id is invalid.');
}

// admin and auditors are permitted to see any building
const permittedRoles = [Roles.ADMIN, Roles.AUDITOR];
const kcUser = req.user as unknown as SSOUser;
const building = await buildingService.getBuildingById(buildingId);

if (!building) {
return res.status(404).send('Building matching this ID was not found.');
} else if (!(await checkUserAgencyPermission(kcUser, [building.AgencyId]))) {
} else if (!(await checkUserAgencyPermission(kcUser, [building.AgencyId], permittedRoles))) {
return res.status(403).send('You are not authorized to view this building.');
}
return res.status(200).send(building);
Expand All @@ -83,7 +86,7 @@ export const updateBuilding = async (req: Request, res: Response) => {
}
const user = await userServices.getUser((req.user as SSOUser).preferred_username);
const updateBody = { ...req.body, UpdatedById: user.Id };
const building = await buildingService.updateBuildingById(updateBody);
const building = await buildingService.updateBuildingById(updateBody, req.user);
return res.status(200).send(building);
};

Expand Down
81 changes: 20 additions & 61 deletions express-api/src/controllers/lookup/lookupController.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { AppDataSource } from '@/appDataSource';
import { PropertyClassification } from '@/typeorm/Entities/PropertyClassification';
import { stubResponse } from '@/utilities/stubResponse';
import { Request, Response } from 'express';
import {
BuildingConstructionPublicResponseSchema,
Expand All @@ -27,46 +26,7 @@ import { Role } from '@/typeorm/Entities/Role';
import { Agency } from '@/typeorm/Entities/Agency';
import { AdministrativeArea } from '@/typeorm/Entities/AdministrativeArea';
import { Workflow } from '@/typeorm/Entities/Workflow';

// TODO: What controllers here could just be replaced by existing GET requests?

/**
* @description Get all agency entries.
* @param {Request} req Incoming request
* @param {Response} res Outgoing response
* @returns {Response} A 200 status and a list of agencies.
*/
export const lookupAgencies = async (req: Request, res: Response) => {
/**
* #swagger.tags = ['Lookup']
* #swagger.description = 'Get all agency entries.'
* #swagger.security = [{
"bearerAuth": []
}]
*/

// TODO: Replace stub response with controller logic
return stubResponse(res);
};

/**
* @description Get all role entries.
* @param {Request} req Incoming request
* @param {Response} res Outgoing response
* @returns {Response} A 200 status and a list of roles.
*/
export const lookupRoles = async (req: Request, res: Response) => {
/**
* #swagger.tags = ['Lookup']
* #swagger.description = 'Get all role entries.'
* #swagger.security = [{
"bearerAuth": []
}]
*/

// TODO: Replace stub response with controller logic
return stubResponse(res);
};
import getConfig from '@/constants/config';

/**
* @description Get all property classification entries.
Expand Down Expand Up @@ -229,6 +189,12 @@ export const lookupNoteTypes = async (req: Request, res: Response) => {
}
};

/**
* Retrieves all monetary types from the database. Optionally filter by status.
* @param req - Request object.
* @param res - Response object.
* @returns A response with monetary types and status code 200.
*/
export const lookupMonetaryTypes = async (req: Request, res: Response) => {
const statusId = req.query.statusId ? parseInt(req.query.statusId.toString()) : undefined;
const types = (
Expand All @@ -242,6 +208,12 @@ export const lookupMonetaryTypes = async (req: Request, res: Response) => {
}
};

/**
* Retrieves all timestamp types from the database. Optionally filter by status.
* @param req - Request object.
* @param res - Response object.
* @returns A response with timestamp types and status code 200.
*/
export const lookupTimestampTypes = async (req: Request, res: Response) => {
const statusId = req.query.statusId ? parseInt(req.query.statusId.toString()) : undefined;
const types = (
Expand All @@ -255,32 +227,14 @@ export const lookupTimestampTypes = async (req: Request, res: Response) => {
}
};

/**
* @description Get all project risk entries.
* @param {Request} req Incoming request
* @param {Response} res Outgoing response
* @returns {Response} A 200 status and a list of project risks.
*/
export const lookupProjectRisks = async (req: Request, res: Response) => {
/**
* #swagger.tags = ['Lookup']
* #swagger.description = 'Get all project risk entries.'
* #swagger.security = [{
"bearerAuth": []
}]
*/

// TODO: Replace stub response with controller logic
return stubResponse(res);
};

/**
* @description Get all entries for frontend lookup context.
* @param {Request} req Incoming request
* @param {Response} res Outgoing response
* @returns {Response} A 200 status and a list entries.
*/
export const lookupAll = async (req: Request, res: Response) => {
const cfg = getConfig();
const Risks = await AppDataSource.getRepository(ProjectRisk).find({
select: {
Id: true,
Expand Down Expand Up @@ -447,12 +401,17 @@ export const lookupAll = async (req: Request, res: Response) => {
PredominateUses,
Classifications,
Roles,
Agencies,
Agencies: (await Agencies).sort((a, b) =>
a.Name.toLowerCase().localeCompare(b.Name.toLowerCase(), undefined, { numeric: true }),
),
AdministrativeAreas,
RegionalDistricts: (await RegionalDistricts).sort((a, b) =>
a.Name.toLowerCase().localeCompare(b.Name.toLowerCase()),
),
Workflows,
Config: {
contactEmail: cfg.contact.toEmail,
},
};
return res.status(200).send(returnObj);
};
Loading

0 comments on commit 93db4e5

Please sign in to comment.