Skip to content

Commit

Permalink
fix(events): add submitted status and its workflow. Fixes MEMB-638
Browse files Browse the repository at this point in the history
  • Loading branch information
serge1peshcoff committed Dec 30, 2019
1 parent fa142b5 commit 1200969
Show file tree
Hide file tree
Showing 5 changed files with 416 additions and 97 deletions.
2 changes: 1 addition & 1 deletion lib/events.js
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ exports.deleteEvent = async (req, res) => {
};

exports.setApprovalStatus = async (req, res) => {
if (!req.permissions.set_status) {
if (!req.permissions.change_status[req.body.status]) {
return errors.makeForbiddenError(res, 'You are not allowed to change status.');
}

Expand Down
18 changes: 17 additions & 1 deletion lib/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,23 @@ exports.getEventPermissions = ({ permissions, event, user }) => {
permissions.set_participants_attended = exports.isOrganizer(event, user) || permissions.manage_event[event.type];
permissions.set_participants_confirmed = exports.isOrganizer(event, user) || permissions.manage_event[event.type];
permissions.export = exports.isOrganizer(event, user) || permissions.manage_event[event.type];
permissions.set_status = permissions.approve_event[event.type];

const canApprove = permissions.approve_event[event.type];
const canApproveOrIsOrganizer = exports.isOrganizer(event, user) || canApprove;

// Status transitions.
// draft -> submitted - by LOs or those who can approve (ask for approval)
// submitted -> draft - by those who can approve (reject approval)
// submitted -> published - by those who can approve (approve and publish)
// published -> submitted - by those who can approve (unpublish)
// draft -> published - no direct transition
// publoshed -> draft - no direct transition
permissions.change_status = {
draft: event.status === 'submitted' && canApprove,
published: event.status === 'submitted' && canApprove,
submitted: (event.status === 'published' && canApprove)
|| (event.status === 'draft' && canApproveOrIsOrganizer)
};

return permissions;
};
Expand Down
29 changes: 29 additions & 0 deletions migrations/20191226235828-add-submitted-to-event-statuses.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
module.exports = {
up: async (queryInterface, Sequelize) => {
// https://stackoverflow.com/questions/45437924/drop-and-create-enum-with-sequelize-correctly
await queryInterface.changeColumn(
'events',
'status',
{ type: Sequelize.TEXT }
);
await queryInterface.sequelize.query('drop type enum_events_status;');
await queryInterface.changeColumn(
'events',
'status',
{ type: Sequelize.ENUM('draft', 'submitted', 'published'), allowNull: false }
);
},
down: async (queryInterface, Sequelize) => {
await queryInterface.changeColumn(
'events',
'status',
{ type: Sequelize.TEXT }
);
await queryInterface.sequelize.query('drop type enum_events_status;');
await queryInterface.changeColumn(
'events',
'status',
{ type: Sequelize.ENUM('draft', 'requesting', 'published'), allowNull: false }
);
}
};
6 changes: 3 additions & 3 deletions models/Event.js
Original file line number Diff line number Diff line change
Expand Up @@ -189,13 +189,13 @@ const Event = sequelize.define('event', {
}
},
status: {
type: Sequelize.ENUM('draft', 'requesting', 'published'),
type: Sequelize.ENUM('draft', 'submitted', 'published'),
allowNull: false,
defaultValue: 'draft',
validate: {
isIn: {
args: [['draft', 'requesting', 'published']],
msg: 'Event status should be one of these: "draft", "requesting", "published".'
args: [['draft', 'submitted', 'published']],
msg: 'Event status should be one of these: "draft", "submitted", "published".'
}
}
},
Expand Down
Loading

0 comments on commit 1200969

Please sign in to comment.