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

feat: ccbc er rd job #3542

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
af09e2f
feat: ccbc er rd job
rafasdc Sep 10, 2024
8ec180d
chore: add helm for import cronjob
rafasdc Sep 10, 2024
47c1259
chore: update dockerfile copy command
rafasdc Sep 10, 2024
e951b35
chore: temp enable deploy
rafasdc Sep 10, 2024
ad110eb
chore: temp deploy shp import cronjob
rafasdc Sep 10, 2024
e5a6c24
chore: temp cronshp tag
rafasdc Sep 10, 2024
c986c44
chore: update permission on data folder
rafasdc Sep 10, 2024
eb2fe69
chore: create dummy tables
rafasdc Sep 11, 2024
93a0c4b
chore: fix syntax
rafasdc Sep 11, 2024
d0988ec
chore: add missing values
rafasdc Sep 11, 2024
9b5e32a
chore: add missing secrets on main
rafasdc Sep 11, 2024
40f3486
chore: correct type
rafasdc Sep 11, 2024
bb8558e
chore: add debug echo
rafasdc Sep 11, 2024
24db654
chore: add missing schema name to shp cron
rafasdc Sep 11, 2024
f7a9ab6
chore: correct image values ref
rafasdc Sep 11, 2024
f0d0226
chore: add permissions, update schema
rafasdc Sep 11, 2024
ec58831
chore: add er rd tables for consistency
rafasdc Sep 11, 2024
af28ffb
feat: add er and rd to ccbc summary page
rafasdc Sep 11, 2024
c64d643
feat: add application coverages upload
rafasdc Sep 12, 2024
4cf3640
chore: add missing grant statements
rafasdc Sep 16, 2024
00f55f4
test: coverages page
rafasdc Sep 16, 2024
2f19901
chore: add limiter
rafasdc Sep 16, 2024
076b075
chore: revert
rafasdc Sep 16, 2024
4384a9b
chore: add limiter to correct function
rafasdc Sep 16, 2024
8bed7d2
test: basic s3 upload tests
rafasdc Sep 16, 2024
cc5b202
chore: sonarcloud
rafasdc Sep 16, 2024
1ae6f98
chore: merge conflict
rafasdc Sep 17, 2024
4bf8a39
chore: remove tables created by postgis
rafasdc Sep 17, 2024
a2cfd98
chore: recreate schema
rafasdc Sep 17, 2024
0507bb1
chore: treat file as binary, proper disable upload
rafasdc Sep 25, 2024
be1fd9a
chore: release v1.196.0
ccbc-service-account Oct 4, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions .github/actions/app/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,15 @@ inputs:
pgbackrest_s3_bucket:
description: 'PGBackRest S3 Bucket'
required: true
er_file:
description: 'ER file'
required: true
rd_file:
description: 'RD file'
required: true
coverages_file:
description: 'Coverages file'
required: true

runs:
using: composite
Expand Down Expand Up @@ -148,6 +157,7 @@ runs:
--set image.app.tag=${{ inputs.tag }} \
--set image.db.tag=${{ inputs.tag }} \
--set image.cronsp.tag=${{ inputs.tag }} \
--set image.cronshp.tag=${{ inputs.tag }} \
--set image.app.clientSecret=${{ inputs.client_secret }} \
--set secureRoute.host=${{ inputs.secure_route }} \
--set growthbook.key=${{ inputs.next_public_growthbook_api_key }} \
Expand Down Expand Up @@ -178,6 +188,9 @@ runs:
--set ches.clientSecret="${{ inputs.ches_client_secret }}" \
--set ches.to="${{ inputs.ches_to }}" \
--set ches.keycloakHost="${{ inputs.ches_keycloak_host }}" \
--set cronshp.erFile="${{ inputs.er_file }}" \
--set cronshp.rdFile="${{ inputs.rd_file }}" \
--set cronshp.coveragesFile="${{ inputs.coverages_file }}" \
--values values-${{ inputs.environment }}.yaml

shell: bash
4 changes: 4 additions & 0 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ jobs:
context: .
dockerfile: cron/sp/Dockerfile
name: cron-sp
- image: ghcr.io/bcgov/conn-ccbc-portal/ccbc-cron-shp
context: .
dockerfile: cron/shp/Dockerfile
name: cron-shp
permissions:
contents: read
packages: write
Expand Down
12 changes: 12 additions & 0 deletions .github/workflows/deploy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ on:
CHES_TO_EMAIL: { required: true }
CHES_KEYCLOAK_HOST: { required: true }
AWS_S3_BACKUPS_BUCKET: { required: true }
ER_FILE: { required: true }
RD_FILE: { required: true }
COVERAGES_FILE: { required: true }

env:
TAG: sha-${{ github.sha }}
Expand Down Expand Up @@ -114,6 +117,9 @@ jobs:
pgbackrest_s3_key: ${{ secrets.AWS_CCBC_IAM_USER_KEY }}
pgbackrest_s3_key_secret: ${{ secrets.AWS_CCBC_IAM_USER_KEY_SECRET }}
pgbackrest_s3_bucket: ${{ secrets.AWS_S3_BACKUPS_BUCKET }}
er_file: ${{ secrets.ER_FILE }}
rd_file: ${{ secrets.RD_FILE }}
coverages_file: ${{ secrets.COVERAGES_FILE }}
environment: dev

ensure-sqitch-plan-ends-with-tag:
Expand Down Expand Up @@ -179,6 +185,9 @@ jobs:
ches_to: ${{ secrets.CHES_TO_EMAIL }}
ches_keycloak_host: ${{ secrets.CHES_KEYCLOAK_HOST }}
pgbackrest_s3_bucket: ${{ secrets.AWS_S3_BACKUPS_BUCKET }}
er_file: ${{ secrets.ER_FILE }}
rd_file: ${{ secrets.RD_FILE }}
coverages_file: ${{ secrets.COVERAGES_FILE }}
environment: test

deploy-to-openshift-production:
Expand Down Expand Up @@ -235,6 +244,9 @@ jobs:
ches_to: ${{ secrets.CHES_TO_EMAIL }}
ches_keycloak_host: ${{ secrets.CHES_KEYCLOAK_HOST }}
pgbackrest_s3_bucket: ${{ secrets.AWS_S3_BACKUPS_BUCKET }}
er_file: ${{ secrets.ER_FILE }}
rd_file: ${{ secrets.RD_FILE }}
coverages_file: ${{ secrets.COVERAGES_FILE }}
environment: prod

backup-secrets-dev:
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,9 @@ jobs:
CHES_TO_EMAIL: ${{ secrets.CHES_TO_EMAIL }}
CHES_KEYCLOAK_HOST: ${{ secrets.CHES_KEYCLOAK_HOST }}
AWS_S3_BACKUPS_BUCKET: ${{ secrets.AWS_S3_BACKUPS_BUCKET }}
ER_FILE: ${{ secrets.ER_FILE }}
RD_FILE: ${{ secrets.RD_FILE }}
COVERAGES_FILE: ${{ secrets.COVERAGES_FILE }}

deploy-feature:
if: github.event_name == 'pull_request' && github.event.pull_request.draft == false
Expand Down
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
# [1.196.0](https://github.com/bcgov/CONN-CCBC-portal/compare/v1.195.4...v1.196.0) (2024-10-04)

### Features

- add application coverages upload ([a8d961c](https://github.com/bcgov/CONN-CCBC-portal/commit/a8d961c39e0cf72240d07c0dc90f9cadc0bbc1cf))
- add er and rd to ccbc summary page ([6d3d07d](https://github.com/bcgov/CONN-CCBC-portal/commit/6d3d07d72c5166ced067adc3a0cf005b22b3f338))
- ccbc er rd job ([5bd21ec](https://github.com/bcgov/CONN-CCBC-portal/commit/5bd21ecbeb2e31702c506e4967d67e0523dd1a2b))

## [1.195.5](https://github.com/bcgov/CONN-CCBC-portal/compare/v1.195.4...v1.195.5) (2024-10-04)

### Bug Fixes
Expand Down
60 changes: 60 additions & 0 deletions app/backend/lib/s3upload.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import { Router } from 'express';
import RateLimit from 'express-rate-limit';
import formidable, { File } from 'formidable';
import fs from 'fs';
import config from '../../config';
import getAuthRole from '../../utils/getAuthRole';
import { uploadFileToS3 } from './s3client';
import { commonFormidableConfig, parseForm } from './express-helper';

const AWS_S3_BUCKET = config.get('AWS_S3_BUCKET');

const limiter = RateLimit({
windowMs: 1 * 60 * 1000,
max: 2000,
});

const s3upload = Router();

s3upload.post('/api/s3/upload', limiter, async (req, res) => {
const authRole = getAuthRole(req);
const isRoleAuthorized =
authRole?.pgRole === 'ccbc_admin' ||
authRole?.pgRole === 'ccbc_analyst' ||
authRole?.pgRole === 'ccbc_auth_user' ||
authRole?.pgRole === 'cbc_admin' ||
authRole?.pgRole === 'super_admin';

if (!isRoleAuthorized) {
return res.status(404).end();
}
const form = formidable(commonFormidableConfig);
const files = await parseForm(form, req).catch((err) => {
return res.status(400).json({ error: err }).end();
});

const filename = Object.keys(files)[0];
const originalFilename = files[filename]?.[0].originalFilename;
const uploadedFilesArray = files[filename] as Array<File>;

const uploaded = uploadedFilesArray?.[0];
if (!uploaded) {
return res.status(200).end();
}
const file = fs.readFileSync(uploaded.filepath);

const params = {
Bucket: AWS_S3_BUCKET,
Key: originalFilename,
Body: file,
};

const uploadResult = await uploadFileToS3(params);
if (uploadResult) {
return res.json({ status: 'success' });
}

return res.status(200).end();
});

export default s3upload;
36 changes: 36 additions & 0 deletions app/components/Analyst/GIS/Tabs.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import styled from 'styled-components';
import { useRouter } from 'next/router';
import { StyledTab } from 'components/Admin/AdminTabs';

const StyledNav = styled.nav`
border-bottom: 1px solid #d6d6d6;
margin-bottom: 8px;
`;

const Tabs = () => {
const router = useRouter();
const gisRef = '/analyst/gis';
const coveragesRef = '/analyst/gis/coverages';

return (
<StyledNav>
<StyledTab
href={gisRef}
selected={
router?.pathname.includes(gisRef) &&
!router.pathname.includes(coveragesRef)
}
>
GIS Input
</StyledTab>
<StyledTab
href={coveragesRef}
selected={router?.pathname.includes(coveragesRef)}
>
Application Coverages Upload
</StyledTab>
</StyledNav>
);
};

export default Tabs;
9 changes: 6 additions & 3 deletions app/components/ButtonLink.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,16 @@ type Props = {
children: JSX.Element | JSX.Element[] | string | string[];
href: string;
onClick?: (event: React.MouseEvent<HTMLButtonElement>) => Promise<void>;
disabled?: boolean;
};

const ButtonLink = ({ children, href, onClick }: Props) => (
const ButtonLink = ({ children, href, onClick, disabled = false }: Props) => (
<Link href={href} passHref>
<Button onClick = {onClick} >{children}</Button>
<Button onClick={onClick} disabled={disabled}>
{children}
</Button>
</Link>
);
ButtonLink.defaultProps = {onClick: () => true};
ButtonLink.defaultProps = { onClick: () => true };

export default ButtonLink;
6 changes: 6 additions & 0 deletions app/config/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,12 @@ const config = convict({
default: '',
env: 'CHES_KEYCLOAK_HOST',
},
COVERAGES_FILE_NAME: {
doc: 'Coverages file name',
format: String,
default: 'CCBC_APPLICATION_COVERAGES_AGGREGATED_NoDATA.zip',
env: 'COVERAGES_FILE_NAME',
},
});

// Load environment dependent configuration
Expand Down
11 changes: 1 addition & 10 deletions app/formSchema/analyst/summary/counts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ const counts: RJSFSchema = {
'communities',
'indigenousCommunities',
'nonIndigenousCommunities',
'benefitingCommunities',
'benefitingIndigenousCommunities',

'totalHouseholdsImpacted',
'numberOfIndigenousHouseholds',
],
Expand All @@ -26,14 +25,6 @@ const counts: RJSFSchema = {
type: 'number',
title: 'Number of Non-Indigenous Communities benefitting',
},
benefitingIndigenousCommunities: {
type: 'number',
title: 'List of Indigenous communities benefitting',
},
benefitingCommunities: {
type: 'number',
title: 'List of Non-Indigenous communities benefitting',
},
totalHouseholdsImpacted: {
type: 'number',
title: 'Total Households Impacted',
Expand Down
33 changes: 33 additions & 0 deletions app/formSchema/analyst/summary/locations.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { RJSFSchema } from '@rjsf/utils';

const locations: RJSFSchema = {
title: 'Locations',
description: '',
type: 'object',
required: [
'benefitingCommunities',
'benefitingIndigenousCommunities',
'economicRegions',
'regionalDistricts',
],
properties: {
benefitingIndigenousCommunities: {
type: 'string',
title: 'List of Indigenous communities benefitting',
},
benefitingCommunities: {
type: 'string',
title: 'List of Non-Indigenous communities benefitting',
},
economicRegions: {
type: 'string',
title: 'List of Economic Regions',
},
regionalDistricts: {
type: 'string',
title: 'List of Regional Districts',
},
},
};

export default locations;
8 changes: 8 additions & 0 deletions app/formSchema/analyst/summary/review.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import dependency from './dependency';
import eventsAndDates from './eventsAndDates';
import funding from './funding';
import milestone from './milestone';
import locations from './locations';

const review: RJSFSchema = {
type: 'object',
Expand All @@ -22,6 +23,13 @@ const review: RJSFSchema = {
...counts.properties,
},
},
locations: {
required: locations.required,
title: locations.title,
properties: {
...locations.properties,
},
},
funding: {
required: funding.required,
title: funding.title,
Expand Down
8 changes: 0 additions & 8 deletions app/formSchema/uiSchema/summary/countsUiSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,6 @@ const countsUiSchema = {
'ui:widget': 'NumberWidget',
'ui:label': 'Number of Non-Indigenous Communities benefitting',
},
benefitingIndigenousCommunities: {
'ui:widget': 'LinkArrayWidget',
'ui:label': 'List of Indigenous communities benefitting',
},
benefitingCommunities: {
'ui:widget': 'LinkArrayWidget',
'ui:label': 'List of Non-Indigenous communities benefitting',
},
totalHouseholdsImpacted: {
'ui:widget': 'NumberWidget',
'ui:label': 'Total Households Impacted',
Expand Down
24 changes: 24 additions & 0 deletions app/formSchema/uiSchema/summary/locationsUiSchema.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
const locationsUiSchema = {
'ui:field': 'SectionField',
'ui:options': {
dividers: true,
},
'ui:title': 'Locations',
benefitingIndigenousCommunities: {
'ui:widget': 'LinkArrayWidget',
'ui:label': 'List of Indigenous communities benefitting',
},
benefitingCommunities: {
'ui:widget': 'LinkArrayWidget',
'ui:label': 'List of Non-Indigenous communities benefitting',
},
economicRegions: {
'ui:widget': 'TextWidget',
'ui:label': 'List of Economic Regions',
},
regionalDistricts: {
'ui:widget': 'TextWidget',
'ui:label': 'List of Regional Districts',
},
};
export default locationsUiSchema;
2 changes: 2 additions & 0 deletions app/formSchema/uiSchema/summary/reviewUiSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@ import countsUiSchema from './countsUiSchema';
import fundingUiSchema from './fundingUiSchema';
import eventsAndDatesUiSchema from './eventsAndDatesUiSchema';
import milestoneUiSchema from './milestoneUiSchema';
import locationsUiSchema from './locationsUiSchema';

const reviewUiSchema = {
dependency: dependencyUiSchema,
counts: countsUiSchema,
locations: locationsUiSchema,
funding: fundingUiSchema,
eventsAndDates: eventsAndDatesUiSchema,
milestone: milestoneUiSchema,
Expand Down
Loading
Loading