Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
61 changes: 0 additions & 61 deletions .devops/dev-CD.yml

This file was deleted.

61 changes: 0 additions & 61 deletions .devops/sit-CD.yml

This file was deleted.

59 changes: 58 additions & 1 deletion .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,41 @@ on:
types: [CD]

jobs:
create_deployment:
name: Create Deployment
runs-on: ubuntu-latest
environment: ${{ github.event.client_payload.environment }}

permissions:
deployments: write

outputs:
deployment_id: ${{ steps.deployment.outputs.deployment_id }}
environment_url: ${{ steps.deployment.outputs.environment_url }}

steps:
- name: Checkout
uses: actions/checkout@v4

- uses: chrnorm/deployment-action@v2
name: Create GitHub deployment
id: deployment
with:
initial-status: 'in_progress'
token: '${{ github.token }}'
environment-url: ${{ vars.DEPLOYMENT_URL }}
environment: ${{ github.event.client_payload.environment }}
auto-inactive: false

deploy:
name: Deploy 🚀
runs-on: ubuntu-latest
environment: ${{ github.event.client_payload.environment }}
needs: create_deployment

steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
ref: ${{ github.event.client_payload.ref }}
- name: Setup SSH Keys and known_hosts
Expand All @@ -25,3 +52,33 @@ jobs:
SSH_PASS: ${{ secrets.SSH_PASS }}
CONNECTION: ${{ secrets.CONNECTION }}
REMOTE_PATH: ${{ secrets.REMOTE_PATH }}

update_deployment_status:
name: Update Deployment Status ✅
runs-on: ubuntu-latest
needs:
- create_deployment
- deploy
if: always()

permissions:
deployments: write

steps:
- name: Update deployment status (success)
if: ${{ needs.deploy.result == 'success' }}
uses: chrnorm/deployment-status@v2
with:
token: '${{ github.token }}'
environment-url: ${{ needs.create_deployment.outputs.environment_url }}
deployment-id: ${{ needs.create_deployment.outputs.deployment_id }}
state: 'success'

- name: Update deployment status (failure)
if: ${{ needs.deploy.result != 'success' }}
uses: chrnorm/deployment-status@v2
with:
token: '${{ github.token }}'
environment-url: ${{ needs.create_deployment.outputs.environment_url }}
deployment-id: ${{ needs.create_deployment.outputs.deployment_id }}
state: 'failure'
10 changes: 10 additions & 0 deletions .jira/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
deployments:
environmentMapping:
development:
- "DEV-*"
testing:
- "TST-*"
staging:
- "STG-*"
production:
- "PROD-*"
4 changes: 2 additions & 2 deletions CI/deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
set -e

echo -e "Stopping docker containers..."
CMD="cd $REMOTE_PATH && echo $SSH_PASS | sudo -S docker-compose pull api"
CMD="cd $REMOTE_PATH && echo $SSH_PASS | sudo -S docker compose pull api"
ssh -oStrictHostKeyChecking=no -o PubkeyAuthentication=yes $CONNECTION "$CMD"

echo -e "Stopping docker containers..."
CMD="cd $REMOTE_PATH && echo $SSH_PASS | sudo -S docker-compose up -d --no-deps api"
CMD="cd $REMOTE_PATH && echo $SSH_PASS | sudo -S docker compose up -d --no-deps api"
ssh -oStrictHostKeyChecking=no -o PubkeyAuthentication=yes $CONNECTION "$CMD"

echo -e "Deployed!"
105 changes: 105 additions & 0 deletions migrations/1725323084593-convert-resource-field-roles-to-objectid.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
import { Resource } from '@models';
import { startDatabaseForMigration } from '../src/utils/migrations/database.helper';
import mongoose from 'mongoose';
import { logger } from '@services/logger.service';

/**
* Convert a value ( string or mongo object id ) to mongo object id.
*
* @param value value to transform
* @returns value as mongo object id
*/
const convertToObjectId = (value) => {
// Only convert if value is a valid ObjectId string
if (mongoose.Types.ObjectId.isValid(value) && typeof value === 'string') {
return new mongoose.Types.ObjectId(value);
}
return value; // Return original if it's not a valid string ObjectId
};

/**
* Sample function of up migration
*
* @returns just migrate data.
*/
export const up = async () => {
console.log('oua oua');
await startDatabaseForMigration();
try {
// Find resources where fields.permissions.canSee or fields.permissions.canUpdate contain strings
const resources = await Resource.find({
$or: [
{
'fields.permissions.canSee': { $elemMatch: { $type: 'string' } },
},
{
'fields.permissions.canUpdate': { $elemMatch: { $type: 'string' } },
},
],
});

// Loop through each resource and update the fields
for (const resource of resources) {
let updated = false;

// Iterate through the fields array
// eslint-disable-next-line @typescript-eslint/no-loop-func
resource.fields = resource.fields.map((field) => {
if (field.name === 'campaign') {
// eslint-disable-next-line @typescript-eslint/no-loop-func
console.log(field);
}
if (field.permissions) {
// Check and convert canSee strings to ObjectIds
if (field.permissions.canSee) {
field.permissions.canSee = field.permissions.canSee.map((perm) => {
const updatedPerm = convertToObjectId(perm);
if (updatedPerm !== perm) updated = true;
return updatedPerm;
});
}

// Check and convert canUpdate strings to ObjectIds
if (field.permissions.canUpdate) {
field.permissions.canUpdate = field.permissions.canUpdate.map(
(perm) => {
const updatedPerm = convertToObjectId(perm);
if (updatedPerm !== perm) updated = true;
return updatedPerm;
}
);
}
}
if (field.name === 'campaign') {
// eslint-disable-next-line @typescript-eslint/no-loop-func
console.log(field);
}
return field;
});

// Save the resource if any updates were made
if (updated) {
resource.markModified('fields');
await resource.save();
logger.info(
`Updated resource ${resource.name} with ID: ${resource._id}`
);
}
}

logger.info('Completed updating resources.');
} catch (error) {
logger.error('Error updating resources:', error);
}
};

/**
* Sample function of down migration
*
* @returns just migrate data.
*/
export const down = async () => {
/*
Code you downgrade script here!
*/
};
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": "oort-backend",
"version": "2.6.2",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
Expand Down
4 changes: 4 additions & 0 deletions src/models/application.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ export interface Application extends Document {
modifiedAt: Date;
description?: string;
sideMenu?: boolean;
variant?: string;
logo?: string;
hideMenu?: boolean;
status?: any;
createdBy?: mongoose.Types.ObjectId;
Expand Down Expand Up @@ -75,6 +77,8 @@ const applicationSchema = new Schema<Application>(
description: String,
sideMenu: Boolean,
hideMenu: Boolean,
variant: String,
logo: String,
permissions: {
canSee: [
{
Expand Down
4 changes: 2 additions & 2 deletions src/routes/download/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -450,8 +450,8 @@ router.post('/records', async (req, res) => {
await sendEmail({
message: {
to: req.context.user.username,
subject: `${params.application} - Your data export is completed - ${params.fileName}`, // TODO : put in config for 1.3
html: 'Dear colleague,\n\nPlease find attached to this e-mail the requested data export.\n\nFor any issues with the data export, please contact ems2@who.int\n\n Best regards,\nems2@who.int', // TODO : put in config for 1.3
subject: `${params.application} - Your data export is completed - ${params.fileName}`,
html: 'Dear colleague,\n\nPlease find attached to this e-mail the requested data export.\n\nFor any issues with the data export, please contact your manager.',
attachments,
},
});
Expand Down
Loading