Ghost/core/server/api/v2/utils/index.js
Fabien O'Carroll 9dd7aff9c6
Updated Content API to use members plans to determine permission (#10483)
no-issue


* Refactored hideMembersOnlyContent to 3 "stages"
* Exported paymentConfigured flag from members service
* Updated Content-API to check members service for paymentConfigured
* Updated members content output serializer to remove content if plan required and no plan
* Updated isContentAPI method
* Moved api util test
2019-02-14 18:17:02 +01:00

33 lines
1.2 KiB
JavaScript

module.exports = {
get permissions() {
return require('./permissions');
},
get serializers() {
return require('./serializers');
},
get validators() {
return require('./validators');
},
/**
* TODO: We need to check for public context as permission stage overrides
* the whole context object currently: https://github.com/TryGhost/Ghost/issues/10099
*/
isContentAPI: (frame) => {
const context = frame.options && frame.options.context || {};
// CASE: An empty context is considered public by the core/server/services/permissions/parse-context.js
// module, replicated here because the context is unparsed until after the permissions layer of the pipeline
const isPublic = context.public || Object.keys(context).length === 0;
// CASE: apiType = 'content' for HTTP Content API
return frame.apiType === 'content' || isPublic;
},
isAdminAPIKey: (frame) => {
return frame.options.context && Object.keys(frame.options.context).length !== 0 && frame.options.context.api_key &&
frame.options.context.api_key.type === 'admin';
}
};