Skip to content

Commit

Permalink
Merge branch 'main' into configurable-app
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathanbataire authored Feb 17, 2025
2 parents 25dea73 + 926bc35 commit 99bcddc
Show file tree
Hide file tree
Showing 13 changed files with 147 additions and 32 deletions.
69 changes: 69 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
name: Deploy

on:
workflow_run:
workflows: [Docker build and publish]
types:
- completed

jobs:
deploy:
runs-on: ubuntu-latest
if: ${{ github.event.workflow_run.conclusion == 'success' }}
steps:
- name: "Configure"
uses: aws-actions/configure-aws-credentials@v4
with:
aws-region: ${{vars.AWS_REGION}}
aws-access-key-id: ${{ secrets.DEPLOY_KEY_ID }}
aws-secret-access-key: ${{ secrets.DEPLOY_ACCESS_KEY }}

- name: install oathtool
run: sudo apt-get install -y oathtool jq

- id: auth
name: Authenticate to STS
run: |
mfa_serial="arn:aws:iam::${{vars.AWS_ACCOUNT_NUMBER}}:mfa/${{vars.MFA_ID}}"
mfa_code=$(oathtool -b --totp ${{secrets.MFA_KEY}})
STS=$(aws sts get-session-token --region "${{vars.AWS_REGION}}" --serial-number "$mfa_serial" --token-code "$mfa_code")
aws_access_key_id=$(echo "$STS" | jq -r '.Credentials.AccessKeyId')
echo "::add-mask::$aws_access_key_id"
aws_secret_access_key=$(echo "$STS" | jq -r '.Credentials.SecretAccessKey')
echo "::add-mask::$aws_secret_access_key"
aws_session_token=$(echo "$STS" | jq -r '.Credentials.SessionToken')
echo "::add-mask::$aws_session_token"
echo "AWS_ACCESS_KEY_ID=$aws_access_key_id" >> "$GITHUB_OUTPUT"
echo "AWS_SECRET_ACCESS_KEY=$aws_secret_access_key" >> "$GITHUB_OUTPUT"
echo "AWS_SESSION_TOKEN=$aws_session_token" >> "$GITHUB_OUTPUT"
- name: Assume role
uses: aws-actions/configure-aws-credentials@v4
with:
aws-region: ${{vars.AWS_REGION}}
aws-access-key-id: ${{ steps.auth.outputs.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ steps.auth.outputs.AWS_SECRET_ACCESS_KEY }}
aws-session-token: ${{ steps.auth.outputs.AWS_SESSION_TOKEN }}
role-skip-session-tagging: true
role-to-assume: "arn:aws:iam::${{vars.AWS_ACCOUNT_NUMBER}}:role/eks-${{vars.AWS_USER}}"

- uses: actions/checkout@v2

- name: Update kubeconfig
run: |
aws eks update-kubeconfig --name ${{vars.CLUSTER}} --region ${{vars.AWS_REGION}}
helm repo add medic https://docs.communityhealthtoolkit.org/helm-charts
- name: Upgrade users-chis-civ
run: |
helm upgrade --namespace ${{vars.NAMESPACE}} --values scripts/deploy/values/users-chis-civ.yaml users-chis-civ medic/cht-user-management
- name: Upgrade users-chis-tg
run: |
helm upgrade --namespace ${{vars.NAMESPACE}} --values scripts/deploy/values/users-chis-tg.yaml users-chis-tg medic/cht-user-management
- name: Upgrade users-chis-ke
run: |
helm upgrade --namespace ${{vars.NAMESPACE}} --values scripts/deploy/values/users-chis-ke.yaml users-chis-ke medic/cht-user-management
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "cht-user-management",
"version": "2.1.0",
"version": "2.1.2",
"main": "dist/index.js",
"dependencies": {
"@bull-board/api": "^5.17.0",
Expand Down
6 changes: 3 additions & 3 deletions scripts/deploy/values/users-chis-civ.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ cht-user-management:
enabled: true
image:
repository: public.ecr.aws/medic/cht-user-management
tag: "1.4.2" # Set this to the version of the docker image
tag: "2.1.2" # Set this to the version of the docker image

# Environment variablues to set in the pod, for example:
# env:
Expand Down Expand Up @@ -51,7 +51,7 @@ cht-user-management-worker:
replicaCount: 1
image:
repository: public.ecr.aws/medic/cht-user-management-worker
tag: "1.4.2"
tag: "2.1.2"
env:
NODE_ENV: production
REDIS_HOST: users-chis-civ-redis-master.users-chis-prod.svc.cluster.local
Expand All @@ -70,4 +70,4 @@ redis:
storageClass: ebs-gp2
size: 8Gi
auth:
enabled: false
enabled: false
6 changes: 3 additions & 3 deletions scripts/deploy/values/users-chis-ke.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ cht-user-management:
enabled: true
image:
repository: public.ecr.aws/medic/cht-user-management
tag: "1.4.2" # Set this to the version of the docker image
tag: "2.1.2" # Set this to the version of the docker image

# Environment variablues to set in the pod, for example:
# env:
Expand Down Expand Up @@ -51,7 +51,7 @@ cht-user-management-worker:
replicaCount: 1
image:
repository: public.ecr.aws/medic/cht-user-management-worker
tag: "1.4.2"
tag: "2.1.2"
env:
NODE_ENV: production
REDIS_HOST: users-chis-ke-redis-master.users-chis-prod.svc.cluster.local
Expand All @@ -70,4 +70,4 @@ redis:
storageClass: ebs-gp2
size: 8Gi
auth:
enabled: false
enabled: false
6 changes: 3 additions & 3 deletions scripts/deploy/values/users-chis-tg.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ cht-user-management:
enabled: true
image:
repository: public.ecr.aws/medic/cht-user-management
tag: "1.4.2" # Set this to the version of the docker image
tag: "2.1.2" # Set this to the version of the docker image

# Environment variablues to set in the pod, for example:
# env:
Expand Down Expand Up @@ -51,7 +51,7 @@ cht-user-management-worker:
replicaCount: 1
image:
repository: public.ecr.aws/medic/cht-user-management-worker
tag: "1.4.2"
tag: "2.1.2"
env:
NODE_ENV: production
REDIS_HOST: users-chis-tg-redis-master.users-chis-prod.svc.cluster.local
Expand All @@ -70,4 +70,4 @@ redis:
storageClass: ebs-gp2
size: 8Gi
auth:
enabled: false
enabled: false
4 changes: 2 additions & 2 deletions src/lib/remote-place-cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,15 +95,15 @@ export default class RemotePlaceCache {
private static convertContactToRemotePlace(doc: any, uniqueKeyProperties: ContactProperty[], hierarchyLevel: HierarchyConstraint): RemotePlace {
const uniqueKeyStringValues: FormattedPropertyCollection = {};
for (const property of uniqueKeyProperties) {
const value = doc[property.property_name];
const value = doc[property.property_name]?.toString();
if (value) {
uniqueKeyStringValues[property.property_name] = new RemotePlacePropertyValue(value, property);
}
}

return {
id: doc._id,
name: new RemotePlacePropertyValue(doc.name, hierarchyLevel),
name: new RemotePlacePropertyValue(doc.name?.toString(), hierarchyLevel),
placeType: hierarchyLevel.contact_type,
lineage: this.extractLineage(doc),
uniquePlaceValues: uniqueKeyStringValues,
Expand Down
12 changes: 7 additions & 5 deletions src/liquid/place/create_form.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,13 @@
{% endif %}
{% endfor %}

{% for prop in contactType.place_properties %}
{%
include "components/contact_type_property.html" prefix="place_" prop=prop place_type=contactType.name
%}
{% endfor %}
{%if op != 'replace'%}
{% for prop in contactType.place_properties %}
{%
include "components/contact_type_property.html" prefix="place_" prop=prop place_type=contactType.name
%}
{% endfor %}
{%endif%}
</section>
<section class="section is-small">
{% for prop in contactType.contact_properties %}
Expand Down
34 changes: 28 additions & 6 deletions src/validation/validator-name.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,34 @@ export default class ValidatorName implements IValidator {
}

private titleCase(value: string): string {
const words = value.toLowerCase().split(' ');
const titleCase = (word: string) => word[0].toUpperCase() + word.slice(1);
const isRomanNumeral = /^[ivx]+$/ig;
const titleCased = words
if (!value) {
return '';
}

const titleCase = (word: string) => word[0]?.toUpperCase() + word.slice(1);

const isRomanNumeral = /^[ivx]+$/i;
const hasForwardSlash = /\//g;
const hasApostrophe = /\s*'\s*/g;
const hasParentheses = /\(([^)]+)\)/g;
const hasExtraSpaces = /\s+/g;

const splitAndProcess = (value: string, delimiter: string) => {
return value
.split(delimiter)
.map(word => word.match(isRomanNumeral) ? word.toUpperCase() : titleCase(word))
.join(delimiter);
};

return value.toLowerCase()
.replace(hasForwardSlash, ' / ')
.replace(hasApostrophe, '\'')
.replace(hasParentheses, match => `(${titleCase(match.slice(1, -1))})`)
.split(' ')
.filter(Boolean)
.map(word => word.match(isRomanNumeral) ? word.toUpperCase() : titleCase(word)).join(' ');
return titleCased.replace(/ '/g, '\'');
.map(word => splitAndProcess(word, '-'))
.join(' ')
.replace(hasExtraSpaces, ' ')
.trim();
}
}
4 changes: 2 additions & 2 deletions test/lib/credentials-file.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ describe('lib/credentials-file.ts', () => {
expect(actual).to.deep.eq([{
filename: 'contacttype-name.csv',
content: `friendly replacement,friendly PARENT,friendly GRANDPARENT,friendly,name,phone,role,username,password
,Parent-name,,Place,contact,0712 344321,role,,
,Parent-Name,,Place,contact,0712 344321,role,,
`
}]);
});
Expand All @@ -61,7 +61,7 @@ describe('lib/credentials-file.ts', () => {
expect(actual).to.deep.eq([{
filename: 'contacttype-name.csv',
content: `friendly replacement,friendly PARENT,friendly GRANDPARENT,friendly,name,phone,role,username,password
,Parent-name,,Place,contact,,role,,
,Parent-Name,,Place,contact,,role,,
`
}]);
});
Expand Down
6 changes: 3 additions & 3 deletions test/lib/manage-hierarchy.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ describe('lib/manage-hierarchy.ts', () => {
const sessionCache = new SessionCache();

const jobParams = await ManageHierarchyLib.getJobDetails(formData, contactType, sessionCache, chtApiWithDocs());
expect(jobParams).to.have.property('jobName').that.equals('move_[From Sub.C-h-u]_to_[To Sub]');
expect(jobParams).to.have.property('jobName').that.equals('move_[From Sub.C-H-U]_to_[To Sub]');
expect(jobParams).to.have.property('jobData').that.deep.include({
action: 'move',
sourceId: 'from-chu-id',
Expand Down Expand Up @@ -113,7 +113,7 @@ describe('lib/manage-hierarchy.ts', () => {
const sessionCache = new SessionCache();

const jobParams = await ManageHierarchyLib.getJobDetails(formData, contactType, sessionCache, chtApiWithDocs());
expect(jobParams).to.have.property('jobName').that.equals('merge_[From Sub.C-h-u]_to_[To Sub.Destination]');
expect(jobParams).to.have.property('jobName').that.equals('merge_[From Sub.C-H-U]_to_[To Sub.Destination]');
expect(jobParams).to.have.property('jobData').that.deep.include({
action: 'merge',
sourceId: 'from-chu-id',
Expand All @@ -135,7 +135,7 @@ describe('lib/manage-hierarchy.ts', () => {
const sessionCache = new SessionCache();

const jobParams = await ManageHierarchyLib.getJobDetails(formData, contactType, sessionCache, chtApiWithDocs());
expect(jobParams).to.have.property('jobName').that.equals('delete_[From Sub.C-h-u]');
expect(jobParams).to.have.property('jobName').that.equals('delete_[From Sub.C-H-U]');
expect(jobParams).to.have.property('jobData').that.deep.include({
action: 'delete',
sourceId: 'from-chu-id',
Expand Down
19 changes: 19 additions & 0 deletions test/lib/remote-place-cache.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,4 +81,23 @@ describe('lib/remote-place-cache.ts', () => {
chtApi.chtSession.authInfo.domain = 'http://other';
RemotePlaceCache.clear(chtApi, 'other');
});

it('unique key properties', async () => {
const chtApi = mockChtApi([{_id: 'id', name: 1 }]);
const contactType = mockSimpleContactType('string', undefined);
contactType.place_properties.find(p => p.property_name === 'name').unique = 'all';
const contactTypeAsHierarchyLevel: HierarchyConstraint = {
contact_type: contactType.name,
property_name: 'level',
friendly_name: 'pretend another ContactType needs this',
type: 'name',
required: true,
level: 0,
};
try {
await RemotePlaceCache.getRemotePlaces(chtApi, contactType, contactTypeAsHierarchyLevel);
} catch (e) {
expect(e).to.be.undefined;
}
});
});
7 changes: 5 additions & 2 deletions test/validation.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,12 @@ const scenarios: Scenario[] = [
{ type: 'name', prop: undefined, isValid: false, error: 'Required' },
{ type: 'name', prop: 'abc', isValid: true, formatted: 'Abc' },
{ type: 'name', prop: 'a b c', isValid: true, formatted: 'A B C' },
{ type: 'name', prop: 'Mr. Sand(m-a-n)', isValid: true, formatted: 'Mr Sand(m-a-n)' },
{ type: 'name', prop: 'WELDON KO(E)CH \n', isValid: true, formatted: 'Weldon Ko(e)ch' },
{ type: 'name', prop: 'Mr. Sand(m-a-n)', isValid: true, formatted: 'Mr Sand(M-A-N)' },
{ type: 'name', prop: 'WELDON KO(E)CH \n', isValid: true, formatted: 'Weldon Ko(E)ch' },
{ type: 'name', prop: 'S \'am \'s', isValid: true, formatted: 'S\'am\'s' },
{ type: 'name', prop: 'this-is-(a-place)', isValid: true, formatted: 'This-Is-(A-Place)' },
{ type: 'name', prop: 'mr. chp-(per-son)', isValid: true, formatted: 'Mr Chp-(Per-Son)' },
{ type: 'name', prop: 'ma-#ma-(pa-pa)', isValid: true, formatted: 'Ma-Ma-(Pa-Pa)' },
{ type: 'name', prop: 'KYAMBOO/KALILUNI', isValid: true, formatted: 'Kyamboo / Kaliluni' },
{ type: 'name', prop: 'NZATANI / ILALAMBYU', isValid: true, formatted: 'Nzatani / Ilalambyu' },
{ type: 'name', prop: 'Sam\'s CHU', propertyParameter: ['CHU', 'Comm Unit'], isValid: true, formatted: 'Sam\'s' },
Expand Down

0 comments on commit 99bcddc

Please sign in to comment.