Skip to content

Commit 0830bba

Browse files
Merge branch 'develop' into feature/DEVSU-2670-add-compatibility-matrix
2 parents 8fc0db8 + 44d4f52 commit 0830bba

16 files changed

Lines changed: 389 additions & 69 deletions

File tree

README.md

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,16 @@ Once you are done with testing, delete the temporary database
155155
dropdb -U ipr_service -h iprdevdb.bcgsc.ca DEVSU-777-temp-ipr-sync-dev
156156
```
157157

158+
## Seeder
159+
160+
Use seeder to load the default templates, projects and users for db.
161+
162+
```bash
163+
npx sequelize-cli db:seed:all --url "postgres://$IPR_SERVICE_USER:$IPR_SERVICE_PASS@$IPR_DATABASE_SERVER/$IPR_DATABASE_NAME"
164+
165+
npx sequelize-cli db:seed:undo --url "postgres://$IPR_SERVICE_USER:$IPR_SERVICE_PASS@$IPR_DATABASE_SERVER/$IPR_DATABASE_NAME"
166+
```
167+
158168
## Database Insert Not Through API
159169

160170
When adding/inserting entries directly into a database table without using the API, be sure to update the primary key (id)
@@ -247,7 +257,7 @@ pm2 start current/pm2.config.js --env production
247257
│ │
248258
│ ├── middleware # Middleware
249259
│ │ Location for all globally required middleware definitions.
250-
│ │
260+
│ │
251261
│ ├── schemas # Schemas
252262
│ │ Location for all globally required schema definitions.
253263
│ │
@@ -299,7 +309,7 @@ pm2 start current/pm2.config.js --env production
299309
300310
├── migrations # Migrations
301311
│ Contains files for updating db schemas and data
302-
312+
303313
└── migrationTools # Migration Tools
304314
Contains files with functions to help with migrations
305315
```
@@ -337,7 +347,7 @@ The search feature enables users to search for report(s) that match a given set
337347

338348
Syntax: **/reports?searchParams=[<category>|<keyword>|<threshold>]**
339349

340-
- *[]*: indicators of a search parameter block. A query can contain one or many parameter blocks
350+
- *[]*: indicators of a search parameter block. A query can contain one or many parameter blocks
341351
- *category*: the search category that a report belongs to. Possible values include patientId, projectName, diagnosis, keyVariant, kbVariant, structuralVariant, smallMutation, and therapeuticTarget
342352
- *keyword*: the search keyword that a report can match with. Could be a variant name or a therapeutic target name
343353
- *threshold*: the matching threshold scales from 0 to 1 and determines the cutoff of similarity between the search keyword and a match value. A threshold of 1 means the entire match value or a substring of it is identical to the search keyword.

app/middleware/__mocks__/graphkbIprLogin.js

Lines changed: 0 additions & 6 deletions
This file was deleted.

app/middleware/graphkbIprLogin.js

Lines changed: 0 additions & 54 deletions
This file was deleted.

app/models/template/template.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@ module.exports = (sequelize, Sq) => {
5252
description: {
5353
type: Sq.TEXT,
5454
},
55+
editable: {
56+
type: Sq.BOOLEAN,
57+
},
5558
}, {
5659
...DEFAULT_OPTIONS,
5760
tableName: 'templates',

app/routes/graphkb/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ const {StatusCodes} = require('http-status-codes');
22
const express = require('express');
33

44
const logger = require('../../log');
5-
const loginMiddleware = require('../../middleware/graphkb');
5+
const graphkbLoginMiddleware = require('../../middleware/graphkb');
66
const {
77
graphkbAutocomplete,
88
graphkbEvidenceLevels,
@@ -63,7 +63,7 @@ const errorMap = {
6363
},
6464
};
6565

66-
router.use(loginMiddleware);
66+
router.use(graphkbLoginMiddleware);
6767

6868
/**
6969
* Autocomplete endpoint for interfacing with GraphKB. This endpoint is used by the client

app/routes/template/template.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@ router.route('/:template([A-z0-9-]{36})')
3535
return res.json(req.template.view('public'));
3636
})
3737
.put(async (req, res) => {
38+
if (!req.template.editable) {
39+
logger.error(`The template "${req.template.name}" is not editable.`);
40+
return res.status(HTTP_STATUS.BAD_REQUEST).json({error: {message: `The template "${req.template.name}" is not editable.`}});
41+
}
3842
// Validate request against schema
3943
try {
4044
validateAgainstSchema(updateSchema, req.body, false);

app/routes/user/user.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,9 @@ const {isAdmin, isManager} = require('../../libs/helperFunctions');
88

99
const validateAgainstSchema = require('../../libs/validateAgainstSchema');
1010
const {createSchema, updateSchema, notificationUpdateSchema} = require('../../schemas/user');
11-
const graphkbIprLoginMiddleware = require('../../middleware/graphkbIprLogin');
1211

1312
const router = express.Router({mergeParams: true});
1413

15-
router.use(graphkbIprLoginMiddleware);
16-
1714
// Middleware for getting/updating a user by ident
1815
router.param('userByIdent', async (req, res, next, ident) => {
1916
let result;

config/jest/jestSetup.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
// Apply mocking to all tests
22
jest.mock('../../app/queue.js');
33
jest.mock('../../app/libs/getUser.js');
4-
jest.mock('../../app/middleware/graphkbIprLogin.js');
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
module.exports = {
2+
async up(queryInterface, Sq) {
3+
await queryInterface.addColumn('templates', 'editable', {
4+
type: Sq.BOOLEAN,
5+
defaultValue: false,
6+
});
7+
},
8+
9+
async down(queryInterface) {
10+
await queryInterface.removeColumn('templates', 'editable');
11+
},
12+
};
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
const {v4: uuidv4} = require('uuid');
2+
const images = require('./constants/images.json');
3+
const templates = require('./constants/templates.json');
4+
const projects = require('./constants/projects.json');
5+
const users = require('./constants/users.json');
6+
const userGroups = require('./constants/user_groups.json');
7+
8+
const addBaseColumns = (records) => {
9+
return records.map((record) => {
10+
return {
11+
...record,
12+
ident: uuidv4(),
13+
created_at: new Date(),
14+
updated_at: new Date(),
15+
};
16+
});
17+
};
18+
19+
module.exports = {
20+
async up(queryInterface, Sequelize) {
21+
const templatesData = templates.map((template) => {
22+
template.sections = JSON.stringify(template.sections);
23+
return template;
24+
});
25+
await queryInterface.bulkInsert('images', addBaseColumns(images), {});
26+
await queryInterface.bulkInsert('templates', addBaseColumns(templatesData), {});
27+
await queryInterface.bulkInsert('projects', addBaseColumns(projects), {});
28+
await queryInterface.bulkInsert('users', addBaseColumns(users), {});
29+
await queryInterface.bulkInsert('user_groups', addBaseColumns(userGroups), {});
30+
31+
// give admin permission to user pori_admin
32+
const usersData = await queryInterface.sequelize.query(
33+
'SELECT id, username FROM users;',
34+
{type: Sequelize.QueryTypes.SELECT},
35+
);
36+
const poriAdmin = usersData.find((u) => {return u.username === 'pori_admin';});
37+
const groupsData = await queryInterface.sequelize.query(
38+
'SELECT id, name FROM user_groups;',
39+
{type: Sequelize.QueryTypes.SELECT},
40+
);
41+
const adminGroup = groupsData.find((g) => {return g.name === 'admin';});
42+
const userGroupData = [{
43+
user_id: poriAdmin.id,
44+
group_id: adminGroup.id,
45+
created_at: new Date(),
46+
updated_at: new Date(),
47+
}];
48+
49+
await queryInterface.bulkInsert('user_group_members', userGroupData);
50+
await queryInterface.bulkInsert('user_metadata', addBaseColumns([{user_id: poriAdmin.id}]));
51+
},
52+
53+
async down(queryInterface) {
54+
await queryInterface.bulkDelete('user_metadata', null, {});
55+
await queryInterface.bulkDelete('user_group_members', null, {});
56+
await queryInterface.bulkDelete('templates', null, {});
57+
await queryInterface.bulkDelete('images', null, {});
58+
await queryInterface.bulkDelete('projects', null, {});
59+
await queryInterface.bulkDelete('users', null, {});
60+
await queryInterface.bulkDelete('user_groups', null, {});
61+
},
62+
};

0 commit comments

Comments
 (0)