Skip to content

Commit

Permalink
feat(slack): post notification for newly created apps
Browse files Browse the repository at this point in the history
  • Loading branch information
Hans Kristian Flaatten committed Jul 21, 2016
1 parent 342ec05 commit 062514a
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
23 changes: 21 additions & 2 deletions apps/app/controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,10 @@ route.post('/new', (req, res, next) => {
desc: req.body.desc,
active: req.api.apps.length < APPS_FREE,
approved: req.api.apps.length < APPS_FREE,
}));
});

// Add the new application to the user
req.api.apps.push(app);

const error = req.api.validateSync();
if (error) {
Expand All @@ -90,13 +93,26 @@ route.post('/new', (req, res, next) => {
req.api.save(err => {
if (err) { next(err); return; }

if (req.api.apps.length > APPS_FREE) {
// Construct Slack notification message
const message = {
text: 'En ny applikasjon har blitt registrert :tada:',
attachments: [app.slackAttachment()],
};

// Warn about pending app approval.
if (!app.approved) {
req.session.message = {
class: 'info',
title: 'Venter på godkjenning',
message: 'Din applikasjon venter på godkjenning.',
};

res.set('x-app-message', 'pending');

// Add interactive Slack buttons for easy approval
message.attachments.push(app.slackRequestApproval());

// Inform about app created.
} else {
req.session.message = {
class: 'positive',
Expand All @@ -105,6 +121,9 @@ route.post('/new', (req, res, next) => {
};
}

// Post message to Slack
slackr(message);

res.set('x-app-status', 'success');
res.redirect(303, '/app');
});
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@
"raven": "^0.11.0",
"semantic-ui-less": "^2.1.8",
"sendgrid": "^2.0.0",
"slackr": "^1.0.0",
"trumbowyg": "^2.0.5"
},
"engines": {
Expand Down
2 changes: 2 additions & 0 deletions test/support/env.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ delete process.env.MONGO_URI;
process.env.APP_ADMINS = 'Foo,Bar';
process.env.APP_SECRET = 'foobar';

process.env.SLACK_WEBHOOK_URI = 'https://localhost/foo/bar';

process.env.USER_NO_PROFILE_COOKIE = sessions[0].cookie;
process.env.USER_NO_PROFILE_OWNER = users[0].userName;

Expand Down

0 comments on commit 062514a

Please sign in to comment.