Skip to content

Commit

Permalink
Merge from UAT into release branch
Browse files Browse the repository at this point in the history
  • Loading branch information
Paul McCafferty committed Aug 11, 2021
2 parents 276c913 + b863d0a commit 939348c
Show file tree
Hide file tree
Showing 57 changed files with 6,088 additions and 3,875 deletions.
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,21 @@ This is a NodeJS Express server, which provides the Back End API Server to the G
To set up the API on your local do the following steps

#### Step 1

Clone the API repository.

`git clone https://github.com/HDRUK/gateway-api`

#### Step 2
#### Step 2

Run the npm install

```
npm install
```

#### Step 3

Create a .env file in the root of the project with this content:

```
Expand Down Expand Up @@ -56,9 +60,11 @@ DISCOURSE_CATEGORY_PROJECTS_ID=
DISCOURSE_CATEGORY_DATASETS_ID=
DISCOURSE_CATEGORY_PAPERS_ID=
DISCOURSE_SSO_SECRET=
```

#### Step 4

Start the API via command line.

`node server.js`
Expand Down
62 changes: 62 additions & 0 deletions migrations/1620558117918-applications_versioning.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import { DataRequestModel } from '../src/resources/datarequest/datarequest.model';
import { buildVersionTree } from '../src/resources/datarequest/datarequest.entity';
import constants from '../src/resources/utilities/constants.util';

async function up() {
// 1. Add default application type to all applications
// 2. Add version 1 to all applications
// 3. Create version tree for all applications

let accessRecords = await DataRequestModel.find()
.select('_id version versionTree amendmentIterations')
.lean();
let ops = [];

accessRecords.forEach(accessRecord => {
const versionTree = buildVersionTree(accessRecord);
const { _id } = accessRecord;
ops.push({
updateOne: {
filter: { _id },
update: {
applicationType: constants.submissionTypes.INITIAL,
majorVersion: 1.0,
version: undefined,
versionTree,
},
upsert: false,
},
});
});

await DataRequestModel.bulkWrite(ops);
}

async function down() {
// 1. Remove application type from all applications
// 2. Remove version from all applications
// 3. Remove version tree from all applications

let accessRecords = await DataRequestModel.find().select('_id version versionTree amendmentIterations').lean();
let ops = [];

accessRecords.forEach(accessRecord => {
const { _id } = accessRecord;
ops.push({
updateOne: {
filter: { _id },
update: {
applicationType: undefined,
majorVersion: undefined,
version: 1,
versionTree: undefined,
},
upsert: false,
},
});
});

await DataRequestModel.bulkWrite(ops);
}

module.exports = { up, down };
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "hdruk-rdt-api",
"config": {
"mongodbMemoryServer": {
"version": "latest"
"version": "5.0.0-rc7"
}
},
"version": "0.1.1",
Expand Down
4 changes: 2 additions & 2 deletions src/config/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ configuration.findAccount = Account.findAccount;
const oidc = new Provider(process.env.api_url || 'http://localhost:3001', configuration);
oidc.proxy = true;

var domains = [process.env.homeURL];
var domains = [/\.healthdatagateway\.org$/, process.env.homeURL];

var rx = /^([http|https]+:\/\/[a-z]+)\.([^/]*)/;
var arr = rx.exec(process.env.homeURL);
Expand Down Expand Up @@ -238,7 +238,7 @@ app.use('/api/v1/dataset-onboarding', require('../resources/dataset/datasetonboa
app.use('/api/v1/datasets', require('../resources/dataset/v1/dataset.route'));
app.use('/api/v2/datasets', require('../resources/dataset/v2/dataset.route'));

app.use('/api/v1/data-access-request/schema', require('../resources/datarequest/datarequest.schemas.route'));
app.use('/api/v1/data-access-request/schema', require('../resources/datarequest/schema/datarequest.schemas.route'));
app.use('/api/v1/data-access-request', require('../resources/datarequest/datarequest.route'));

app.use('/api/v1/collections', require('../resources/collections/collections.route'));
Expand Down
5 changes: 5 additions & 0 deletions src/resources/bpmnworkflow/bpmnworkflow.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ module.exports = {
console.error(err.message);
});
},

postUpdateProcess: async bpmContext => {
// Create Axios requet to start Camunda process
let { taskId, applicationStatus, dateSubmitted, publisher, actioner, archived } = bpmContext;
Expand Down Expand Up @@ -108,6 +109,7 @@ module.exports = {
console.error(err.message);
});
},

postStartManagerReview: async bpmContext => {
// Start manager-review process
let { applicationStatus, managerId, publisher, notifyManager, taskId } = bpmContext;
Expand Down Expand Up @@ -135,20 +137,23 @@ module.exports = {
console.error(err.message);
});
},

postManagerApproval: async bpmContext => {
// Manager has approved sectoin
let { businessKey } = bpmContext;
await axios.post(`${bpmnBaseUrl}/api/gateway/workflow/v1/manager/completed/${businessKey}`, bpmContext.config).catch(err => {
console.error(err.message);
});
},

postStartStepReview: async bpmContext => {
//Start Step-Review process
let { businessKey } = bpmContext;
await axios.post(`${bpmnBaseUrl}/api/gateway/workflow/v1/complete/review/${businessKey}`, bpmContext, config).catch(err => {
console.error(err.message);
});
},

postCompleteReview: async bpmContext => {
//Start Next-Step process
let { businessKey } = bpmContext;
Expand Down
66 changes: 47 additions & 19 deletions src/resources/course/course.repository.js
Original file line number Diff line number Diff line change
Expand Up @@ -357,30 +357,38 @@ async function createMessage(authorId, toolId, toolName, toolType, activeflag, r

async function sendEmailNotifications(tool, activeflag, rejectionReason) {
let subject;
let html;
let adminCanUnsubscribe = true;
// 1. Generate tool URL for linking user from email
const toolLink = process.env.homeURL + '/' + tool.type + '/' + tool.id;
let resourceType = tool.type.charAt(0).toUpperCase() + tool.type.slice(1);

// 2. Build email body
// 2. Build email subject
if (activeflag === 'active') {
subject = `Your ${tool.type} ${tool.title} has been approved and is now live`;
html = `Your ${tool.type} ${tool.title} has been approved and is now live <br /><br /> ${toolLink}`;
subject = `${resourceType} ${tool.title} has been approved and is now live`;
} else if (activeflag === 'archive') {
subject = `Your ${tool.type} ${tool.title} has been archived`;
html = `Your ${tool.type} ${tool.title} has been archived <br /><br /> ${toolLink}`;
subject = `${resourceType} ${tool.title} has been archived`;
} else if (activeflag === 'rejected') {
subject = `Your ${tool.type} ${tool.title} has been rejected`;
html = `Your ${tool.type} ${tool.title} has been rejected <br /><br /> Rejection reason: ${rejectionReason} <br /><br /> ${toolLink}`;
subject = `${resourceType} ${tool.title} has been rejected`;
} else if (activeflag === 'add') {
subject = `Your ${tool.type} ${tool.title} has been submitted for approval`;
html = `Your ${tool.type} ${tool.title} has been submitted for approval<br /><br /> ${toolLink}`;
subject = `${resourceType} ${tool.title} has been submitted for approval`;
adminCanUnsubscribe = false;
} else if (activeflag === 'edit') {
subject = `Your ${tool.type} ${tool.title} has been updated`;
html = `Your ${tool.type} ${tool.title} has been updated<br /><br /> ${toolLink}`;
subject = `${resourceType} ${tool.title} has been updated`;
}

// Create object to pass through email data
let options = {
resourceType: tool.type,
resourceName: tool.title,
resourceLink: toolLink,
subject,
rejectionReason: rejectionReason,
activeflag,
type: 'author',
};
// Create email body content
let html = emailGenerator.generateEntityNotification(options);

if (adminCanUnsubscribe) {
// 3. Find the creator of the course and admins if they have opted in to email updates
var q = UserModel.aggregate([
Expand Down Expand Up @@ -435,6 +443,20 @@ async function sendEmailNotifications(tool, activeflag, rejectionReason) {
if (err) {
return new Error({ success: false, error: err });
}

// Create object to pass through email data
options = {
resourceType: tool.type,
resourceName: tool.title,
resourceLink: toolLink,
subject,
rejectionReason: rejectionReason,
activeflag,
type: 'admin',
};

html = emailGenerator.generateEntityNotification(options);

emailGenerator.sendEmail(emailRecipients, `${hdrukEmail}`, subject, html, adminCanUnsubscribe);
});
}
Expand All @@ -456,17 +478,23 @@ async function sendEmailNotificationToAuthors(tool, toolOwner) {
{ $project: { _id: 1, firstname: 1, lastname: 1, email: 1, role: 1, 'tool.emailNotifications': 1 } },
]);

// 3. Use the returned array of email recipients to generate and send emails with SendGrid
// 3. Create object to pass through email data
let options = {
resourceType: tool.type,
resourceName: tool.name,
resourceLink: toolLink,
type: 'co-author',
resourceAuthor: toolOwner.name,
};
// 4. Create email body content
let html = emailGenerator.generateEntityNotification(options);

// 5. Use the returned array of email recipients to generate and send emails with SendGrid
q.exec((err, emailRecipients) => {
if (err) {
return new Error({ success: false, error: err });
}
emailGenerator.sendEmail(
emailRecipients,
`${hdrukEmail}`,
`${toolOwner.name} added you as an author of the tool ${tool.name}`,
`${toolOwner.name} added you as an author of the tool ${tool.name} <br /><br /> ${toolLink}`
);
emailGenerator.sendEmail(emailRecipients, `${hdrukEmail}`, `${toolOwner.name} added you as an author of the course ${tool.name}`, html);
});
}

Expand Down
Loading

0 comments on commit 939348c

Please sign in to comment.