2015-09-17 16:25:15 -04:00
|
|
|
'use strict';
|
|
|
|
|
|
2016-10-31 13:52:26 +03:00
|
|
|
var async = require('async');
|
2017-08-30 14:26:41 -06:00
|
|
|
|
2016-10-31 13:52:26 +03:00
|
|
|
var meta = require('../../meta');
|
2017-08-30 14:26:41 -06:00
|
|
|
var emailer = require('../../emailer');
|
2018-03-27 17:01:51 -04:00
|
|
|
var plugins = require('../../plugins');
|
2016-10-31 13:52:26 +03:00
|
|
|
|
|
|
|
|
var settingsController = module.exports;
|
2015-09-17 16:25:15 -04:00
|
|
|
|
2016-10-13 11:43:39 +02:00
|
|
|
settingsController.get = function (req, res, next) {
|
2015-09-17 16:25:15 -04:00
|
|
|
var term = req.params.term ? req.params.term : 'general';
|
|
|
|
|
|
2015-09-21 17:17:23 -04:00
|
|
|
switch (req.params.term) {
|
2017-02-18 02:38:03 -07:00
|
|
|
case 'email':
|
|
|
|
|
renderEmail(req, res, next);
|
|
|
|
|
break;
|
2018-03-27 17:01:51 -04:00
|
|
|
case 'user':
|
|
|
|
|
renderUser(req, res, next);
|
|
|
|
|
break;
|
2017-02-18 02:38:03 -07:00
|
|
|
default:
|
|
|
|
|
res.render('admin/settings/' + term);
|
2015-09-21 17:17:23 -04:00
|
|
|
}
|
2015-09-17 16:25:15 -04:00
|
|
|
};
|
|
|
|
|
|
2015-09-21 17:17:23 -04:00
|
|
|
|
|
|
|
|
function renderEmail(req, res, next) {
|
2018-03-27 17:01:51 -04:00
|
|
|
async.waterfall([
|
|
|
|
|
function (next) {
|
|
|
|
|
async.parallel({
|
|
|
|
|
emails: async.apply(emailer.getTemplates, meta.config),
|
|
|
|
|
services: emailer.listServices,
|
|
|
|
|
}, next);
|
|
|
|
|
},
|
|
|
|
|
function (results) {
|
|
|
|
|
res.render('admin/settings/email', {
|
|
|
|
|
emails: results.emails,
|
|
|
|
|
sendable: results.emails.filter(function (email) {
|
|
|
|
|
return email.path.indexOf('_plaintext') === -1 && email.path.indexOf('partials') === -1;
|
|
|
|
|
}),
|
|
|
|
|
services: results.services,
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
], next);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function renderUser(req, res, next) {
|
|
|
|
|
var types = [
|
|
|
|
|
'notificationType_upvote',
|
|
|
|
|
'notificationType_new-topic',
|
|
|
|
|
'notificationType_new-reply',
|
|
|
|
|
'notificationType_follow',
|
|
|
|
|
'notificationType_new-chat',
|
|
|
|
|
'notificationType_group-invite',
|
|
|
|
|
];
|
|
|
|
|
|
2018-04-02 12:48:22 -04:00
|
|
|
var privilegedTypes = [
|
|
|
|
|
'notificationType_new-register',
|
|
|
|
|
'notificationType_post-queue',
|
|
|
|
|
'notificationType_new-post-flag',
|
|
|
|
|
'notificationType_new-user-flag',
|
|
|
|
|
];
|
|
|
|
|
|
2018-03-27 17:01:51 -04:00
|
|
|
async.waterfall([
|
|
|
|
|
function (next) {
|
|
|
|
|
plugins.fireHook('filter:user.notificationTypes', {
|
|
|
|
|
userData: {},
|
|
|
|
|
types: types,
|
2018-04-02 12:48:22 -04:00
|
|
|
privilegedTypes: privilegedTypes,
|
2018-03-27 17:01:51 -04:00
|
|
|
}, next);
|
|
|
|
|
},
|
|
|
|
|
function (results) {
|
2018-04-02 12:48:22 -04:00
|
|
|
var notificationSettings = results.types.concat(results.privilegedTypes).map(function (type) {
|
2018-03-27 17:01:51 -04:00
|
|
|
return {
|
|
|
|
|
name: type,
|
|
|
|
|
label: '[[notifications:' + type + ']]',
|
|
|
|
|
};
|
|
|
|
|
});
|
|
|
|
|
res.render('admin/settings/user', {
|
|
|
|
|
notificationSettings: notificationSettings,
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
], next);
|
2015-09-21 17:17:23 -04:00
|
|
|
}
|