Skip to content

merge from project and product templates #2

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

Merged
merged 2 commits into from
May 26, 2018
Merged
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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ Run image:
`docker run -p 3000:3000 -i -t -e DB_HOST=172.17.0.1 tc_projects_services`
You may replace 172.17.0.1 with your docker0 IP.

You can paste **swagger.yaml** to [swagger editor](http://editor.swagger.io/) or import **postman.json** to verify endpoints.
You can paste **swagger.yaml** to [swagger editor](http://editor.swagger.io/) or import **postman.json** and **postman_environment.json** to verify endpoints.

#### Deploying without docker
If you don't want to use docker to deploy to localhost. You can simply run `npm run start` from root of project. This should start the server on default port `3000`.
232 changes: 232 additions & 0 deletions postman.json
Original file line number Diff line number Diff line change
Expand Up @@ -2345,6 +2345,238 @@
"response": []
}
]
},
{
"name": "Project Templates",
"description": "",
"item": [
{
"name": "Create project template",
"request": {
"method": "POST",
"header": [
{
"key": "Content-Type",
"value": "application/json"
},
{
"key": "Authorization",
"value": "Bearer {{jwt-token}}"
}
],
"body": {
"mode": "raw",
"raw": "{\r\n \"param\":{\r\n \"name\":\"new name\",\r\n \"key\":\"new key\",\r\n \"category\":\"new category\",\r\n \"scope\":{\r\n \"scope1\":\"scope 1\"\r\n },\r\n \"phases\":{\r\n \"phase1\":\"phase 1\"\r\n }\r\n }\r\n}"
},
"url": "{{api-url}}/v4/projectTemplates"
},
"response": []
},
{
"name": "List project templates",
"request": {
"method": "GET",
"header": [
{
"key": "Content-Type",
"value": "application/json"
},
{
"key": "Authorization",
"value": "Bearer {{jwt-token}}"
}
],
"body": {
"mode": "raw",
"raw": "{\r\n \"param\":{\r\n \"name\":\"new name\",\r\n \"key\":\"new key\",\r\n \"category\":\"new category\",\r\n \"scope\":{\r\n \"scope1\":\"scope 1\"\r\n },\r\n \"phases\":{\r\n \"phase1\":\"phase 1\"\r\n }\r\n }\r\n}"
},
"url": "{{api-url}}/v4/projectTemplates"
},
"response": []
},
{
"name": "Get project template",
"request": {
"method": "GET",
"header": [
{
"key": "Content-Type",
"value": "application/json"
},
{
"key": "Authorization",
"value": "Bearer {{jwt-token}}"
}
],
"body": {
"mode": "raw",
"raw": "{\r\n \"param\":{\r\n \"name\":\"new name\",\r\n \"key\":\"new key\",\r\n \"category\":\"new category\",\r\n \"scope\":{\r\n \"scope1\":\"scope 1\"\r\n },\r\n \"phases\":{\r\n \"phase1\":\"phase 1\"\r\n }\r\n }\r\n}"
},
"url": "{{api-url}}/v4/projectTemplates/1"
},
"response": []
},
{
"name": "Update project template",
"request": {
"method": "PATCH",
"header": [
{
"key": "Content-Type",
"value": "application/json"
},
{
"key": "Authorization",
"value": "Bearer {{jwt-token}}"
}
],
"body": {
"mode": "raw",
"raw": "{\r\n \"param\":{\r\n \"name\":\"new name\",\r\n \"key\":\"new key\",\r\n \"category\":\"new category\",\r\n \"scope\":{\r\n \"scope1\":\"scope 1\",\r\n \"scope2\": [\"a\"]\r\n },\r\n \"phases\":{\r\n \"phase1\":\"phase 1\",\r\n \"phase2\": {\r\n \t\"another\": \"another\"\r\n }\r\n }\r\n }\r\n}"
},
"url": "{{api-url}}/v4/projectTemplates/1"
},
"response": []
},
{
"name": "Delete project template",
"request": {
"method": "DELETE",
"header": [
{
"key": "Content-Type",
"value": "application/json"
},
{
"key": "Authorization",
"value": "Bearer {{jwt-token}}"
}
],
"body": {
"mode": "raw",
"raw": "{\r\n \"param\":{\r\n \"name\":\"new name\",\r\n \"key\":\"new key\",\r\n \"category\":\"new category\",\r\n \"scope\":{\r\n \"scope1\":\"scope 1\",\r\n \"scope2\": [\"a\"]\r\n },\r\n \"phases\":{\r\n \"phase1\":\"phase 1\",\r\n \"phase2\": {\r\n \t\"another\": \"another\"\r\n }\r\n }\r\n }\r\n}"
},
"url": "{{api-url}}/v4/projectTemplates/1"
},
"response": []
}
]
},
{
"name": "Product Templates",
"description": "",
"item": [
{
"name": "Create product template",
"request": {
"method": "POST",
"header": [
{
"key": "Content-Type",
"value": "application/json"
},
{
"key": "Authorization",
"value": "Bearer {{jwt-token}}"
}
],
"body": {
"mode": "raw",
"raw": "{\r\n \"param\":{\r\n \"name\":\"new name\",\r\n \"productKey\":\"new productKey\",\r\n \"icon\":\"http://example.com/icon-new.ico\",\r\n \"brief\": \"new brief\",\r\n \"details\": \"new details\",\r\n \"aliases\":{\r\n \"alias1\":\"alias 1\"\r\n },\r\n \"template\":{\r\n \"template1\":\"template 1\"\r\n }\r\n }\r\n}"
},
"url": "{{api-url}}/v4/productTemplates"
},
"response": []
},
{
"name": "List product templates",
"request": {
"method": "GET",
"header": [
{
"key": "Content-Type",
"value": "application/json"
},
{
"key": "Authorization",
"value": "Bearer {{jwt-token}}"
}
],
"body": {
"mode": "raw",
"raw": "{\r\n \"param\":{\r\n \"name\":\"new name\",\r\n \"key\":\"new key\",\r\n \"category\":\"new category\",\r\n \"scope\":{\r\n \"scope1\":\"scope 1\"\r\n },\r\n \"phases\":{\r\n \"phase1\":\"phase 1\"\r\n }\r\n }\r\n}"
},
"url": "{{api-url}}/v4/productTemplates"
},
"response": []
},
{
"name": "Get product template",
"request": {
"method": "GET",
"header": [
{
"key": "Content-Type",
"value": "application/json"
},
{
"key": "Authorization",
"value": "Bearer {{jwt-token}}"
}
],
"body": {
"mode": "raw",
"raw": "{\r\n \"param\":{\r\n \"name\":\"new name\",\r\n \"key\":\"new key\",\r\n \"category\":\"new category\",\r\n \"scope\":{\r\n \"scope1\":\"scope 1\"\r\n },\r\n \"phases\":{\r\n \"phase1\":\"phase 1\"\r\n }\r\n }\r\n}"
},
"url": "{{api-url}}/v4/productTemplates/1"
},
"response": []
},
{
"name": "Update product template",
"request": {
"method": "PATCH",
"header": [
{
"key": "Content-Type",
"value": "application/json"
},
{
"key": "Authorization",
"value": "Bearer {{jwt-token}}"
}
],
"body": {
"mode": "raw",
"raw": "{\r\n \"param\":{\r\n \"name\":\"new name\",\r\n \"productKey\":\"new productKey\",\r\n \"icon\":\"http://example.com/icon-new.ico\",\r\n \"brief\": \"new brief\",\r\n \"details\": \"new details\",\r\n \"aliases\":{\r\n \"alias1\":\"scope 1\",\r\n \"alias2\": [\"a\"]\r\n },\r\n \"template\":{\r\n \"template1\":\"template 1\",\r\n \"template2\": {\r\n \t\"another\": \"another\"\r\n }\r\n }\r\n }\r\n}"
},
"url": "{{api-url}}/v4/productTemplates/1"
},
"response": []
},
{
"name": "Delete product template",
"request": {
"method": "DELETE",
"header": [
{
"key": "Content-Type",
"value": "application/json"
},
{
"key": "Authorization",
"value": "Bearer {{jwt-token}}"
}
],
"body": {
"mode": "raw",
"raw": "{\r\n \"param\":{\r\n \"name\":\"new name\",\r\n \"key\":\"new key\",\r\n \"category\":\"new category\",\r\n \"scope\":{\r\n \"scope1\":\"scope 1\",\r\n \"scope2\": [\"a\"]\r\n },\r\n \"phases\":{\r\n \"phase1\":\"phase 1\",\r\n \"phase2\": {\r\n \t\"another\": \"another\"\r\n }\r\n }\r\n }\r\n}"
},
"url": "{{api-url}}/v4/productTemplates/1"
},
"response": []
}
]
}
]
}
21 changes: 11 additions & 10 deletions postman_environment.json
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
{
"id": "1d4b6c34-6da6-8651-3372-9c6d4d09cc8c",
"name": "project service",
"id": "e6b30b4b-1388-4622-8314-bc49ba1d752b",
"name": "tc-project-service",
"values": [
{
"enabled": true,
"key": "api-url",
"value": "http://localhost:3000",
"type": "text"
"description": "",
"type": "text",
"enabled": true
},
{
"enabled": true,
"key": "jwt-token",
"value": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJyb2xlcyI6WyJhZG1pbmlzdHJhdG9yIl0sImlzcyI6Imh0dHBzOi8vYXBpLnRvcGNvZGVyLWRldi5jb20iLCJoYW5kbGUiOiJwc2hhaDEiLCJleHAiOjI0NjI0OTQ2MTgsInVzZXJJZCI6IjQwMTM1OTc4IiwiaWF0IjoxNDYyNDk0MDE4LCJlbWFpbCI6InBzaGFoMUB0ZXN0LmNvbSIsImp0aSI6ImY0ZTFhNTE0LTg5ODAtNDY0MC04ZWM1LWUzNmUzMWE3ZTg0OSJ9.XuNN7tpMOXvBG1QwWRQROj7NfuUbqhkjwn39Vy4tR5I",
"type": "text"
"value": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJyb2xlcyI6WyJUb3Bjb2RlciBVc2VyIiwiYWRtaW5pc3RyYXRvciJdLCJpc3MiOiJodHRwczovL2FwaS50b3Bjb2Rlci1kZXYuY29tIiwiaGFuZGxlIjoidGVzdDEiLCJleHAiOjI1NjMwNzY2ODksInVzZXJJZCI6IjQwMDUxMzMzIiwiaWF0IjoxNDYzMDc2MDg5LCJlbWFpbCI6InRlc3RAdG9wY29kZXIuY29tIiwianRpIjoiYjMzYjc3Y2QtYjUyZS00MGZlLTgzN2UtYmViOGUwYWU2YTRhIn0.wKWUe0-SaiFVN-VR_-GwgFlvWaDkSbc8H55ktb9LAVw",
"description": "",
"type": "text",
"enabled": true
}
],
"timestamp": 1526351351170,
"_postman_variable_scope": "environment",
"_postman_exported_at": "2018-05-15T14:19:14.630Z",
"_postman_exported_using": "Postman/5.5.2"
"_postman_exported_at": "2018-05-18T18:54:18.167Z",
"_postman_exported_using": "Postman/6.0.10"
}
32 changes: 32 additions & 0 deletions src/models/productTemplate.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/* eslint-disable valid-jsdoc */

/**
* The Product Template model
*/
module.exports = (sequelize, DataTypes) => {
const ProductTemplate = sequelize.define('ProductTemplate', {
id: { type: DataTypes.BIGINT, primaryKey: true, autoIncrement: true },
name: { type: DataTypes.STRING(255), allowNull: false },
productKey: { type: DataTypes.STRING(45), allowNull: false },
icon: { type: DataTypes.STRING(255), allowNull: false },
brief: { type: DataTypes.STRING(45), allowNull: false },
details: { type: DataTypes.STRING(255), allowNull: false },
aliases: { type: DataTypes.JSON, allowNull: false },
template: { type: DataTypes.JSON, allowNull: false },
deletedAt: DataTypes.DATE,
createdAt: { type: DataTypes.DATE, defaultValue: DataTypes.NOW },
updatedAt: { type: DataTypes.DATE, defaultValue: DataTypes.NOW },
deletedBy: DataTypes.BIGINT,
createdBy: { type: DataTypes.BIGINT, allowNull: false },
updatedBy: { type: DataTypes.BIGINT, allowNull: false },
}, {
tableName: 'product_templates',
paranoid: true,
timestamps: true,
updatedAt: 'updatedAt',
createdAt: 'createdAt',
deletedAt: 'deletedAt',
});

return ProductTemplate;
};
30 changes: 30 additions & 0 deletions src/models/projectTemplate.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/* eslint-disable valid-jsdoc */

/**
* The Project Template model
*/
module.exports = (sequelize, DataTypes) => {
const ProjectTemplate = sequelize.define('ProjectTemplate', {
id: { type: DataTypes.BIGINT, primaryKey: true, autoIncrement: true },
name: { type: DataTypes.STRING(255), allowNull: false },
key: { type: DataTypes.STRING(45), allowNull: false },
category: { type: DataTypes.STRING(45), allowNull: false },
scope: { type: DataTypes.JSON, allowNull: false },
phases: { type: DataTypes.JSON, allowNull: false },
deletedAt: DataTypes.DATE,
createdAt: { type: DataTypes.DATE, defaultValue: DataTypes.NOW },
updatedAt: { type: DataTypes.DATE, defaultValue: DataTypes.NOW },
deletedBy: DataTypes.BIGINT,
createdBy: { type: DataTypes.BIGINT, allowNull: false },
updatedBy: { type: DataTypes.BIGINT, allowNull: false },
}, {
tableName: 'project_templates',
paranoid: true,
timestamps: true,
updatedAt: 'updatedAt',
createdAt: 'createdAt',
deletedAt: 'deletedAt',
});

return ProjectTemplate;
};
18 changes: 18 additions & 0 deletions src/permissions/connectManagerOrAdmin.ops.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import util from '../util';
import { MANAGER_ROLES } from '../constants';


/**
* Only Connect Manager, Connect Admin, and administrator are allowed to perform the operations
* @param {Object} req the express request instance
* @return {Promise} returns a promise
*/
module.exports = req => new Promise((resolve, reject) => {
const hasAccess = util.hasRoles(req, MANAGER_ROLES);

if (!hasAccess) {
return reject(new Error('You do not have permissions to perform this action'));
}

return resolve(true);
});
12 changes: 12 additions & 0 deletions src/permissions/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const projectEdit = require('./project.edit');
const projectDelete = require('./project.delete');
const projectMemberDelete = require('./projectMember.delete');
const projectAdmin = require('./admin.ops');
const connectManagerOrAdmin = require('./connectManagerOrAdmin.ops');

module.exports = () => {
Authorizer.setDeniedStatusCode(403);
Expand All @@ -23,6 +24,17 @@ module.exports = () => {
Authorizer.setPolicy('project.downloadAttachment', projectView);
Authorizer.setPolicy('project.updateMember', projectEdit);
Authorizer.setPolicy('project.admin', projectAdmin);

Authorizer.setPolicy('projectTemplate.create', connectManagerOrAdmin);
Authorizer.setPolicy('projectTemplate.edit', connectManagerOrAdmin);
Authorizer.setPolicy('projectTemplate.delete', connectManagerOrAdmin);
Authorizer.setPolicy('projectTemplate.view', true);

Authorizer.setPolicy('productTemplate.create', connectManagerOrAdmin);
Authorizer.setPolicy('productTemplate.edit', connectManagerOrAdmin);
Authorizer.setPolicy('productTemplate.delete', connectManagerOrAdmin);
Authorizer.setPolicy('productTemplate.view', true);

Authorizer.setPolicy('project.addProjectPhase', projectEdit);
Authorizer.setPolicy('project.updateProjectPhase', projectEdit);
Authorizer.setPolicy('project.deleteProjectPhase', projectEdit);
Expand Down
Loading