0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-01-20 22:42:53 -05:00

Add configuration/private endpoint and settings for Unsplash (#8895)

refs #8859

- adds new `configuration/private` endpoint for exposing config that should not be accessible without authentication
- adds `unsplashAPI` to private config
- adds empty `unsplash` config to default settings
This commit is contained in:
Kevin Ansfield 2017-08-15 15:59:16 +01:00 committed by Hannah Wolfe
parent b6b299a8f7
commit d064eda229
4 changed files with 33 additions and 1 deletions

View file

@ -67,7 +67,6 @@ function apiRoutes() {
// ## Configuration
apiRouter.get('/configuration', api.http(api.configuration.read));
apiRouter.get('/configuration/:key', authenticatePrivate, api.http(api.configuration.read));
apiRouter.get('/configuration/timezones', authenticatePrivate, api.http(api.configuration.read));
// ## Posts
apiRouter.get('/posts', authenticatePublic, api.http(api.posts.browse));

View file

@ -15,6 +15,14 @@ function fetchAvailableTimezones() {
return timezones;
}
function fetchPrivateConfig() {
var unsplashConfig = config.get('unsplash') || {};
return {
unsplashAPI: unsplashConfig
};
}
function getAboutConfig() {
return {
version: ghostVersion.full,
@ -88,6 +96,11 @@ configuration = {
return Promise.resolve({configuration: [fetchAvailableTimezones()]});
}
// Private configuration config for API keys used by the client
if (options.key === 'private') {
return Promise.resolve({configuration: [fetchPrivateConfig()]});
}
return Promise.resolve({configuration: []});
}
};

View file

@ -80,6 +80,9 @@
},
"slack": {
"defaultValue": "[{\"url\":\"\"}]"
},
"unsplash": {
"defaultValue": ""
}
},
"theme": {

View file

@ -79,4 +79,21 @@ describe('Configuration API', function () {
done();
}).catch(done);
});
it('can read private config and get all expected properties', function (done) {
ConfigurationAPI.read({key: 'private'}).then(function (response) {
var props;
should.exist(response);
should.exist(response.configuration);
response.configuration.should.be.an.Array().with.lengthOf(1);
props = response.configuration[0];
// property is set, but value not available, because settings API was not called yet
props.should.have.property('unsplashAPI').which.is.an.Object();
props.unsplashAPI.should.be.empty();
done();
}).catch(done);
});
});