|
|
@@ -81,6 +81,89 @@ module.exports = function(crowi, app) {
|
|
|
actions.app.settingUpdate = function(req, res) {
|
|
|
};
|
|
|
|
|
|
+ // app.get('/admin/notification' , admin.notification.index);
|
|
|
+ actions.notification = {};
|
|
|
+ actions.notification.index = function(req, res) {
|
|
|
+ var config = crowi.getConfig();
|
|
|
+ var slackSetting = Config.setupCofigFormData('notification', config);
|
|
|
+ var hasSlackConfig = Config.hasSlackConfig(config);
|
|
|
+ var hasSlackToken = Config.hasSlackToken(config);
|
|
|
+ var slack = crowi.slack;
|
|
|
+ var slackAuthUrl = '';
|
|
|
+
|
|
|
+ if (!Config.hasSlackConfig(req.config)) {
|
|
|
+ slackSetting['slack:clientId'] = '';
|
|
|
+ slackSetting['slack:clientSecret'] = '';
|
|
|
+ } else {
|
|
|
+ debug('slack is:', slack);
|
|
|
+ slackAuthUrl = slack.getAuthorizeURL();
|
|
|
+ }
|
|
|
+
|
|
|
+ if (req.session.slackSetting) {
|
|
|
+ slackSetting = req.session.slackSetting;
|
|
|
+ req.session.slackSetting = null;
|
|
|
+ }
|
|
|
+
|
|
|
+ return res.render('admin/notification', {
|
|
|
+ slackSetting,
|
|
|
+ hasSlackConfig,
|
|
|
+ hasSlackToken,
|
|
|
+ slackAuthUrl
|
|
|
+ });
|
|
|
+ };
|
|
|
+
|
|
|
+ // app.post('/admin/notification/slackSetting' , admin.notification.slackauth);
|
|
|
+ actions.notification.slackSetting = function(req, res) {
|
|
|
+ var slackSetting = req.form.slackSetting;
|
|
|
+
|
|
|
+ req.session.slackSetting = slackSetting;
|
|
|
+ if (req.form.isValid) {
|
|
|
+ Config.updateNamespaceByArray('notification', slackSetting, function(err, config) {
|
|
|
+ Config.updateConfigCache('notification', config);
|
|
|
+ req.session.slackSetting = null;
|
|
|
+
|
|
|
+ crowi.setupSlack().then(function() {
|
|
|
+ return res.redirect('/admin/notification');
|
|
|
+ });
|
|
|
+ });
|
|
|
+ } else {
|
|
|
+ req.flash('errorMessage', req.form.errors);
|
|
|
+ return res.redirect('/admin/notification');
|
|
|
+ }
|
|
|
+ };
|
|
|
+
|
|
|
+ // app.get('/admin/notification/slackAuth' , admin.notification.slackauth);
|
|
|
+ actions.notification.slackAuth = function(req, res) {
|
|
|
+ var code = req.query.code;
|
|
|
+ var config = crowi.getConfig();
|
|
|
+
|
|
|
+ if (!code || !Config.hasSlackConfig(req.config)) {
|
|
|
+ return res.redirect('/admin/notification');
|
|
|
+ }
|
|
|
+
|
|
|
+ var slack = crowi.slack;
|
|
|
+ var bot = slack.createBot();
|
|
|
+ bot.api.oauth.access({code}, function(err, data) {
|
|
|
+ debug('oauth response', err, data);
|
|
|
+ if (!data.ok || !data.access_token) {
|
|
|
+ req.flash('errorMessage', ['Failed to fetch access_token. Please do connect again.']);
|
|
|
+ return res.redirect('/admin/notification');
|
|
|
+ } else {
|
|
|
+ Config.updateNamespaceByArray('notification', {'slack:token': data.access_token}, function(err, config) {
|
|
|
+ if (err) {
|
|
|
+ req.flash('errorMessage', ['Failed to save access_token. Please try again.']);
|
|
|
+ } else {
|
|
|
+ Config.updateConfigCache('notification', config);
|
|
|
+ req.flash('successMessage', ['Successfully Connected!']);
|
|
|
+ }
|
|
|
+
|
|
|
+ slack.createBot();
|
|
|
+ return res.redirect('/admin/notification');
|
|
|
+ });
|
|
|
+ }
|
|
|
+ });
|
|
|
+ };
|
|
|
+
|
|
|
actions.user = {};
|
|
|
actions.user.index = function(req, res) {
|
|
|
var page = parseInt(req.query.page) || 1;
|
|
|
@@ -193,44 +276,33 @@ module.exports = function(crowi, app) {
|
|
|
});
|
|
|
};
|
|
|
|
|
|
- actions.slackauthstart = function(req, res) {
|
|
|
- var Botkit = require('botkit');
|
|
|
- var controller = Botkit.slackbot();
|
|
|
- controller.configureSlackApp({
|
|
|
- clientId: '',
|
|
|
- clientSecret: '',
|
|
|
- redirectUri: 'http://localhost:3000/slackauth',
|
|
|
- scopes: ['chat:write:bot']
|
|
|
- });
|
|
|
-
|
|
|
- return res.render('admin/slackauthstart', {
|
|
|
- url: controller.getAuthorizeURL(),
|
|
|
- });
|
|
|
- };
|
|
|
-
|
|
|
actions.slackauth = function(req, res) {
|
|
|
- debug(req.query.code);
|
|
|
- var Botkit = require('botkit');
|
|
|
- var controller = Botkit.slackbot({debug: true});
|
|
|
- controller.configureSlackApp({
|
|
|
- clientId: '',
|
|
|
- clientSecret: '',
|
|
|
- redirectUri: 'http://localhost:3000/slackauth',
|
|
|
- scopes: ['chat:write:bot']
|
|
|
- });
|
|
|
+ //debug(req.query.code);
|
|
|
+ //var Botkit = require('botkit');
|
|
|
+ //var controller = Botkit.slackbot({debug: true});
|
|
|
+ //var config = crowi.getConfig();
|
|
|
+
|
|
|
+ //controller.configureSlackApp({
|
|
|
+ // clientId: '2462768682.25922619424',
|
|
|
+ // clientSecret: '2bbbc1c5d355e128ffd009a5d57629b9',
|
|
|
+ // redirectUri: config.crowi['app:url'] + '/slackauth',
|
|
|
+ // scopes: ['chat:write:bot']
|
|
|
+ //});
|
|
|
|
|
|
- var bot = controller.spawn();
|
|
|
- bot.api.oauth.access({code: req.query.code}, function (err, response) {
|
|
|
- debug(err, response);
|
|
|
- });
|
|
|
+ //var bot = controller.spawn();
|
|
|
+ //bot.api.oauth.access({code: req.query.code}, function (err, response) {
|
|
|
+ // debug(err, response);
|
|
|
+ //});
|
|
|
+ //var accessToken = 'xoxp-2462768682-2462768686-25940861495-3e4cc9168a';
|
|
|
+ //var accessToken = 'xoxp-2462768682-2462768686-26103706022-46943fb5ec';
|
|
|
//
|
|
|
// access_token: '',
|
|
|
// scope: 'identify,chat:write:bot',
|
|
|
// team_name: '',
|
|
|
// team_id: '' }
|
|
|
- //var bot = controller.spawn({token: ''});
|
|
|
+ //var bot = controller.spawn({token: accessToken});
|
|
|
//bot.api.chat.postMessage({
|
|
|
- // channel: '#xtest',
|
|
|
+ // channel: '#xtest2',
|
|
|
// username: 'Crowi',
|
|
|
// text: '/hoge/fuga/piyo is updated.',
|
|
|
// attachments: [
|
|
|
@@ -277,6 +349,15 @@ module.exports = function(crowi, app) {
|
|
|
}
|
|
|
};
|
|
|
|
|
|
+ // app.post('/_api/admin/notifications.add' , admin.api.notificationAdd);
|
|
|
+ actions.api.notificationAdd = function(req, res) {
|
|
|
+ };
|
|
|
+
|
|
|
+ // app.post('/_api/admin/notifications.remove' , admin.api.notificationRemove);
|
|
|
+ actions.api.notificationRemove = function(req, res) {
|
|
|
+ };
|
|
|
+
|
|
|
+
|
|
|
function saveSetting(req, res, form)
|
|
|
{
|
|
|
Config.updateNamespaceByArray('crowi', form, function(err, config) {
|