mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-01-06 22:40:14 -05:00
d81bc91bd2
refs #7116, refs #2001 - Changes the way Ghost errors are implemented to benefit from proper inheritance - Moves all error definitions into a single file - Changes the error constructor to take an options object, rather than needing the arguments to be passed in the correct order. - Provides a wrapper so that any errors that haven't already been converted to GhostErrors get converted before they are displayed. Summary of changes: * 🐛 set NODE_ENV in config handler * ✨ add GhostError implementation (core/server/errors.js) - register all errors in one file - inheritance from GhostError - option pattern * 🔥 remove all error files * ✨ wrap all errors into GhostError in case of HTTP * 🎨 adaptions - option pattern for errors - use GhostError when needed * 🎨 revert debug deletion and add TODO for error id's
77 lines
3 KiB
JavaScript
77 lines
3 KiB
JavaScript
var debug = require('debug')('ghost:admin:controller'),
|
|
_ = require('lodash'),
|
|
Promise = require('bluebird'),
|
|
api = require('../api'),
|
|
config = require('../config'),
|
|
errors = require('../errors'),
|
|
logging = require('../logging'),
|
|
updateCheck = require('../update-check'),
|
|
i18n = require('../i18n'),
|
|
adminControllers;
|
|
|
|
adminControllers = {
|
|
// Route: index
|
|
// Path: /ghost/
|
|
// Method: GET
|
|
index: function index(req, res) {
|
|
debug('index called');
|
|
/*jslint unparam:true*/
|
|
|
|
function renderIndex() {
|
|
var configuration,
|
|
fetch = {
|
|
configuration: api.configuration.read().then(function (res) { return res.configuration[0]; }),
|
|
client: api.clients.read({slug: 'ghost-admin'}).then(function (res) { return res.clients[0]; }),
|
|
ghostAuth: api.clients.read({slug: 'ghost-auth'})
|
|
.then(function (res) { return res.clients[0]; })
|
|
.catch(function () {
|
|
return;
|
|
})
|
|
};
|
|
|
|
return Promise.props(fetch).then(function renderIndex(result) {
|
|
configuration = result.configuration;
|
|
|
|
configuration.clientId = {value: result.client.slug, type: 'string'};
|
|
configuration.clientSecret = {value: result.client.secret, type: 'string'};
|
|
|
|
if (result.ghostAuth && config.get('auth:type') === 'ghost') {
|
|
configuration.ghostAuthId = {value: result.ghostAuth.uuid, type: 'string'};
|
|
}
|
|
|
|
debug('rendering default template');
|
|
res.render('default', {
|
|
configuration: configuration
|
|
});
|
|
});
|
|
}
|
|
|
|
updateCheck().then(function then() {
|
|
return updateCheck.showUpdateNotification();
|
|
}).then(function then(updateVersion) {
|
|
if (!updateVersion) {
|
|
return;
|
|
}
|
|
|
|
var notification = {
|
|
status: 'alert',
|
|
type: 'info',
|
|
location: 'upgrade.new-version-available',
|
|
dismissible: false,
|
|
message: i18n.t('notices.controllers.newVersionAvailable',
|
|
{version: updateVersion, link: '<a href="http://support.ghost.org/how-to-upgrade/" target="_blank">Click here</a>'})};
|
|
|
|
return api.notifications.browse({context: {internal: true}}).then(function then(results) {
|
|
if (!_.some(results.notifications, {message: notification.message})) {
|
|
return api.notifications.add({notifications: [notification]}, {context: {internal: true}});
|
|
}
|
|
});
|
|
}).finally(function noMatterWhat() {
|
|
renderIndex();
|
|
}).catch(function (err) {
|
|
logging.error(new errors.GhostError({err: err}));
|
|
});
|
|
}
|
|
};
|
|
|
|
module.exports = adminControllers;
|