mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-29 22:01:49 +03:00
ed16998461
refs #6421, #6525 - The configuration API endpoint was a bit of an animal: - It's used currently in two ways, once for general config, another for the about page. - These two things are different, and would require different permissions in future. - There was also both a browse and a read version, even though only browse was used. - The response from the browse was being artificially turned into many objects, when its really just one with multiple keys - The new version treats each type of config as a different single object with several keys - The new version therefore only has a 'read' request - A basic read request with no key will return basic config that any client would need - A read request with the about key returns the about config - A read request with a different key could therefore return some other config
62 lines
2.3 KiB
JavaScript
62 lines
2.3 KiB
JavaScript
var _ = require('lodash'),
|
|
Promise = require('bluebird'),
|
|
api = require('../api'),
|
|
errors = require('../errors'),
|
|
updateCheck = require('../update-check'),
|
|
i18n = require('../i18n'),
|
|
adminControllers;
|
|
|
|
adminControllers = {
|
|
// Route: index
|
|
// Path: /ghost/
|
|
// Method: GET
|
|
index: function index(req, res) {
|
|
/*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]; })
|
|
};
|
|
|
|
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'};
|
|
|
|
res.render('default', {
|
|
configuration: configuration
|
|
});
|
|
});
|
|
}
|
|
|
|
updateCheck().then(function then() {
|
|
return updateCheck.showUpdateNotification();
|
|
}).then(function then(updateVersion) {
|
|
if (!updateVersion) {
|
|
return;
|
|
}
|
|
|
|
var notification = {
|
|
type: 'upgrade',
|
|
location: 'settings-about-upgrade',
|
|
dismissible: false,
|
|
status: 'alert',
|
|
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(errors.logError);
|
|
}
|
|
};
|
|
|
|
module.exports = adminControllers;
|