|
|
@@ -6,8 +6,6 @@ module.exports = function(crowi, app) {
|
|
|
, Page = models.Page
|
|
|
, User = models.User
|
|
|
, Config = models.Config
|
|
|
- , PluginUtils = require('../plugins/plugin-utils')
|
|
|
- , pluginUtils = new PluginUtils()
|
|
|
, ApiResponse = require('../util/apiResponse')
|
|
|
|
|
|
, MAX_PAGE_LIST = 5
|
|
|
@@ -68,12 +66,9 @@ module.exports = function(crowi, app) {
|
|
|
}
|
|
|
|
|
|
actions.index = function(req, res) {
|
|
|
- return res.render('admin/index', {
|
|
|
- plugins: pluginUtils.listPlugins(crowi.rootDir),
|
|
|
- });
|
|
|
+ return res.render('admin/index');
|
|
|
};
|
|
|
|
|
|
- // app.get('/admin/app' , admin.app.index);
|
|
|
actions.app = {};
|
|
|
actions.app.index = function(req, res) {
|
|
|
var settingForm;
|
|
|
@@ -87,75 +82,23 @@ module.exports = function(crowi, app) {
|
|
|
actions.app.settingUpdate = function(req, res) {
|
|
|
};
|
|
|
|
|
|
- // app.get('/admin/security' , admin.security.index);
|
|
|
- actions.security = {};
|
|
|
- actions.security.index = function(req, res) {
|
|
|
- var settingForm;
|
|
|
- settingForm = Config.setupCofigFormData('crowi', req.config);
|
|
|
- return res.render('admin/security', { settingForm });
|
|
|
- };
|
|
|
-
|
|
|
- // app.get('/admin/markdown' , admin.markdown.index);
|
|
|
- actions.markdown = {};
|
|
|
- actions.markdown.index = function(req, res) {
|
|
|
- var config = crowi.getConfig();
|
|
|
- var markdownSetting = Config.setupCofigFormData('markdown', config);
|
|
|
- return res.render('admin/markdown', {
|
|
|
- markdownSetting: markdownSetting,
|
|
|
- });
|
|
|
- };
|
|
|
-
|
|
|
- // app.post('/admin/markdown/lineBreaksSetting' , admin.markdown.lineBreaksSetting);
|
|
|
- actions.markdown.lineBreaksSetting = function(req, res) {
|
|
|
- var markdownSetting = req.form.markdownSetting;
|
|
|
-
|
|
|
- req.session.markdownSetting = markdownSetting;
|
|
|
- if (req.form.isValid) {
|
|
|
- Config.updateNamespaceByArray('markdown', markdownSetting, function(err, config) {
|
|
|
- Config.updateConfigCache('markdown', config);
|
|
|
- req.session.markdownSetting = null;
|
|
|
- req.flash('successMessage', ['Successfully updated!']);
|
|
|
- return res.redirect('/admin/markdown');
|
|
|
- });
|
|
|
- } else {
|
|
|
- req.flash('errorMessage', req.form.errors);
|
|
|
- return res.redirect('/admin/markdown');
|
|
|
- }
|
|
|
- };
|
|
|
-
|
|
|
- // app.get('/admin/customize' , admin.customize.index);
|
|
|
- actions.customize = {};
|
|
|
- actions.customize.index = function(req, res) {
|
|
|
- var settingForm;
|
|
|
- settingForm = Config.setupCofigFormData('crowi', req.config);
|
|
|
-
|
|
|
- return res.render('admin/customize', {
|
|
|
- settingForm: settingForm,
|
|
|
- });
|
|
|
- };
|
|
|
-
|
|
|
// app.get('/admin/notification' , admin.notification.index);
|
|
|
actions.notification = {};
|
|
|
actions.notification.index = function(req, res) {
|
|
|
var config = crowi.getConfig();
|
|
|
var UpdatePost = crowi.model('UpdatePost');
|
|
|
var slackSetting = Config.setupCofigFormData('notification', config);
|
|
|
- var hasSlackAppConfig = Config.hasSlackAppConfig(config);
|
|
|
- var hasSlackIwhUrl = Config.hasSlackIwhUrl(config);
|
|
|
+ var hasSlackConfig = Config.hasSlackConfig(config);
|
|
|
var hasSlackToken = Config.hasSlackToken(config);
|
|
|
var slack = crowi.slack;
|
|
|
var slackAuthUrl = '';
|
|
|
|
|
|
- if (!Config.hasSlackAppConfig(req.config)) {
|
|
|
+ if (!Config.hasSlackConfig(req.config)) {
|
|
|
slackSetting['slack:clientId'] = '';
|
|
|
slackSetting['slack:clientSecret'] = '';
|
|
|
- }
|
|
|
- else {
|
|
|
+ } else {
|
|
|
slackAuthUrl = slack.getAuthorizeURL();
|
|
|
}
|
|
|
- if (!Config.hasSlackIwhUrl(req.config)) {
|
|
|
- slackSetting['slack:incomingWebhookUrl'] = '';
|
|
|
- }
|
|
|
|
|
|
if (req.session.slackSetting) {
|
|
|
slackSetting = req.session.slackSetting;
|
|
|
@@ -167,15 +110,14 @@ module.exports = function(crowi, app) {
|
|
|
return res.render('admin/notification', {
|
|
|
settings,
|
|
|
slackSetting,
|
|
|
- hasSlackAppConfig,
|
|
|
- hasSlackIwhUrl,
|
|
|
+ hasSlackConfig,
|
|
|
hasSlackToken,
|
|
|
slackAuthUrl
|
|
|
});
|
|
|
});
|
|
|
};
|
|
|
|
|
|
- // app.post('/admin/notification/slackSetting' , admin.notification.slackSetting);
|
|
|
+ // app.post('/admin/notification/slackSetting' , admin.notification.slackauth);
|
|
|
actions.notification.slackSetting = function(req, res) {
|
|
|
var slackSetting = req.form.slackSetting;
|
|
|
|
|
|
@@ -183,10 +125,8 @@ module.exports = function(crowi, app) {
|
|
|
if (req.form.isValid) {
|
|
|
Config.updateNamespaceByArray('notification', slackSetting, function(err, config) {
|
|
|
Config.updateConfigCache('notification', config);
|
|
|
- req.flash('successMessage', ['Successfully Updated!']);
|
|
|
req.session.slackSetting = null;
|
|
|
|
|
|
- // Re-setup
|
|
|
crowi.setupSlack().then(function() {
|
|
|
return res.redirect('/admin/notification');
|
|
|
});
|
|
|
@@ -202,23 +142,14 @@ module.exports = function(crowi, app) {
|
|
|
const code = req.query.code;
|
|
|
const config = crowi.getConfig();
|
|
|
|
|
|
- if (!code || !Config.hasSlackAppConfig(req.config)) {
|
|
|
+ if (!code || !Config.hasSlackConfig(req.config)) {
|
|
|
return res.redirect('/admin/notification');
|
|
|
}
|
|
|
|
|
|
- var slack = crowi.slack;
|
|
|
- var bot = slack.initAppBot(true);
|
|
|
- var args = {
|
|
|
- code,
|
|
|
- client_id: config.notification['slack:clientId'],
|
|
|
- client_secret: config.notification['slack:clientSecret'],
|
|
|
- }
|
|
|
- bot.api.oauth.access(args, 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 {
|
|
|
+ const slack = crowi.slack;
|
|
|
+ slack.getOauthAccessToken(code)
|
|
|
+ .then(data => {
|
|
|
+ debug('oauth response', data);
|
|
|
Config.updateNamespaceByArray('notification', {'slack:token': data.access_token}, function(err, config) {
|
|
|
if (err) {
|
|
|
req.flash('errorMessage', ['Failed to save access_token. Please try again.']);
|
|
|
@@ -227,23 +158,11 @@ module.exports = function(crowi, app) {
|
|
|
req.flash('successMessage', ['Successfully Connected!']);
|
|
|
}
|
|
|
|
|
|
- slack.initAppBot();
|
|
|
return res.redirect('/admin/notification');
|
|
|
});
|
|
|
- }
|
|
|
- });
|
|
|
- };
|
|
|
-
|
|
|
- // app.post('/admin/notification/slackSetting/disconnect' , admin.notification.disconnectFromSlack);
|
|
|
- actions.notification.disconnectFromSlack = function(req, res) {
|
|
|
- const config = crowi.getConfig();
|
|
|
- const slack = crowi.slack;
|
|
|
-
|
|
|
- Config.updateNamespaceByArray('notification', {'slack:token': ''}, function(err, config) {
|
|
|
- Config.updateConfigCache('notification', config);
|
|
|
- req.flash('successMessage', ['Successfully Disconnected!']);
|
|
|
-
|
|
|
- slack.initAppBot();
|
|
|
+ }).catch(err => {
|
|
|
+ debug('oauth response ERROR', err);
|
|
|
+ req.flash('errorMessage', ['Failed to fetch access_token. Please do connect again.']);
|
|
|
return res.redirect('/admin/notification');
|
|
|
});
|
|
|
};
|
|
|
@@ -259,64 +178,43 @@ module.exports = function(crowi, app) {
|
|
|
});
|
|
|
};
|
|
|
|
|
|
- // app.post('/admin/notification/slackIwhSetting' , admin.notification.slackIwhSetting);
|
|
|
- actions.notification.slackIwhSetting = function(req, res) {
|
|
|
- var slackIwhSetting = req.form.slackIwhSetting;
|
|
|
-
|
|
|
- if (req.form.isValid) {
|
|
|
- Config.updateNamespaceByArray('notification', slackIwhSetting, function(err, config) {
|
|
|
- Config.updateConfigCache('notification', config);
|
|
|
- req.flash('successMessage', ['Successfully Updated!']);
|
|
|
-
|
|
|
- // Re-setup
|
|
|
- crowi.setupSlack().then(function() {
|
|
|
- return res.redirect('/admin/notification#slack-incoming-webhooks');
|
|
|
- });
|
|
|
- });
|
|
|
- } else {
|
|
|
- req.flash('errorMessage', req.form.errors);
|
|
|
- return res.redirect('/admin/notification#slack-incoming-webhooks');
|
|
|
- }
|
|
|
- };
|
|
|
-
|
|
|
actions.search.buildIndex = function(req, res) {
|
|
|
var search = crowi.getSearcher();
|
|
|
if (!search) {
|
|
|
return res.redirect('/admin');
|
|
|
}
|
|
|
|
|
|
- return new Promise(function(resolve, reject) {
|
|
|
- search.deleteIndex()
|
|
|
+ Promise.resolve().then(function() {
|
|
|
+ return new Promise(function(resolve, reject) {
|
|
|
+ search.deleteIndex()
|
|
|
+ .then(function(data) {
|
|
|
+ debug('Index deleted.');
|
|
|
+ resolve();
|
|
|
+ }).catch(function(err) {
|
|
|
+ debug('Delete index Error, but if it is initialize, its ok.', err);
|
|
|
+ resolve();
|
|
|
+ });
|
|
|
+ });
|
|
|
+ }).then(function() {
|
|
|
+ search.buildIndex()
|
|
|
.then(function(data) {
|
|
|
- debug('Index deleted.');
|
|
|
- resolve();
|
|
|
- }).catch(function(err) {
|
|
|
- debug('Delete index Error, but if it is initialize, its ok.', err);
|
|
|
- resolve();
|
|
|
+ if (!data.errors) {
|
|
|
+ debug('Index created.');
|
|
|
+ }
|
|
|
+ return search.addAllPages();
|
|
|
+ })
|
|
|
+ .then(function(data) {
|
|
|
+ if (!data.errors) {
|
|
|
+ debug('Data is successfully indexed.');
|
|
|
+ } else {
|
|
|
+ debug('Data index error.', data.errors);
|
|
|
+ }
|
|
|
+ })
|
|
|
+ .catch(function(err) {
|
|
|
+ debug('Error', err);
|
|
|
});
|
|
|
- })
|
|
|
- .then(function() {
|
|
|
- return search.buildIndex()
|
|
|
- })
|
|
|
- .then(function(data) {
|
|
|
- if (!data.errors) {
|
|
|
- debug('Index created.');
|
|
|
- }
|
|
|
- return search.addAllPages();
|
|
|
- })
|
|
|
- .then(function(data) {
|
|
|
- if (!data.errors) {
|
|
|
- debug('Data is successfully indexed.');
|
|
|
- req.flash('successMessage', 'Data is successfully indexed.');
|
|
|
- } else {
|
|
|
- debug('Data index error.', data.errors);
|
|
|
- req.flash('errorMessage', `Data index error: ${data.errors}`);
|
|
|
- }
|
|
|
- return res.redirect('/admin/search');
|
|
|
- })
|
|
|
- .catch(function(err) {
|
|
|
- debug('Error', err);
|
|
|
- req.flash('errorMessage', `Error: ${err}`);
|
|
|
+
|
|
|
+ req.flash('successMessage', 'Now re-building index ... this takes a while.');
|
|
|
return res.redirect('/admin/search');
|
|
|
});
|
|
|
};
|
|
|
@@ -415,37 +313,8 @@ module.exports = function(crowi, app) {
|
|
|
};
|
|
|
|
|
|
actions.user.remove = function(req, res) {
|
|
|
- var id = req.params.id;
|
|
|
- let username = '';
|
|
|
-
|
|
|
- return new Promise((resolve, reject) => {
|
|
|
- User.findById(id, (err, userData) => {
|
|
|
- username = userData.username;
|
|
|
- return resolve(userData);
|
|
|
- });
|
|
|
- })
|
|
|
- .then((userData) => {
|
|
|
- return new Promise((resolve, reject) => {
|
|
|
- userData.statusDelete((err, userData) => {
|
|
|
- if (err) {
|
|
|
- reject(err);
|
|
|
- }
|
|
|
- resolve(userData);
|
|
|
- });
|
|
|
- });
|
|
|
- })
|
|
|
- .then((userData) => {
|
|
|
- return Page.removePageByPath(`/user/${username}`)
|
|
|
- .then(() => userData);
|
|
|
- })
|
|
|
- .then((userData) => {
|
|
|
- req.flash('successMessage', `${username} さんのアカウントを削除しました`);
|
|
|
- return res.redirect('/admin/users');
|
|
|
- })
|
|
|
- .catch((err) => {
|
|
|
- req.flash('errorMessage', '削除に失敗しました。');
|
|
|
- return res.redirect('/admin/users');
|
|
|
- });
|
|
|
+ // 未実装
|
|
|
+ return res.redirect('/admin/users');
|
|
|
};
|
|
|
|
|
|
// これやったときの relation の挙動未確認
|
|
|
@@ -505,28 +374,6 @@ module.exports = function(crowi, app) {
|
|
|
}
|
|
|
};
|
|
|
|
|
|
- actions.api.securitySetting = function(req, res) {
|
|
|
- var form = req.form.settingForm;
|
|
|
-
|
|
|
- if (req.form.isValid) {
|
|
|
- debug('form content', form);
|
|
|
- return saveSetting(req, res, form);
|
|
|
- } else {
|
|
|
- return res.json({status: false, message: req.form.errors.join('\n')});
|
|
|
- }
|
|
|
- };
|
|
|
-
|
|
|
- actions.api.customizeSetting = function(req, res) {
|
|
|
- var form = req.form.settingForm;
|
|
|
-
|
|
|
- if (req.form.isValid) {
|
|
|
- debug('form content', form);
|
|
|
- return saveSetting(req, res, form);
|
|
|
- } else {
|
|
|
- return res.json({status: false, message: req.form.errors.join('\n')});
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
// app.post('/_api/admin/notifications.add' , admin.api.notificationAdd);
|
|
|
actions.api.notificationAdd = function(req, res) {
|
|
|
var UpdatePost = crowi.model('UpdatePost');
|