0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-01-06 22:40:14 -05:00

Fixed frame context being empty

no issue
This commit is contained in:
kirrg001 2018-11-05 21:48:31 +01:00 committed by Rishabh Garg
parent 514eb22077
commit 22911b5812
2 changed files with 19 additions and 2 deletions

View file

@ -6,7 +6,14 @@ module.exports = {
browse(apiConfig, frame) {
debug('browse');
if (!_.get(frame, 'options.context.user') && _.get(frame, 'options.context.api_key_id')) {
// @TODO: `api_key_id` does not work long term, because it can be either a content or an admin api key?
/**
* ## current cases:
* - context object is empty (functional call, content api access)
* - api_key_id exists? content api access
* - user exists? admin api access
*/
if (Object.keys(frame.options.context).length === 0 || (!frame.options.context.user && frame.options.context.api_key_id)) {
// CASE: the content api endpoints for posts should only return non page type resources
if (frame.options.filter) {
if (frame.options.filter.match(/page:\w+\+?/)) {
@ -29,7 +36,14 @@ module.exports = {
read(apiConfig, frame) {
debug('read');
if (!_.get(frame, 'options.context.user') && _.get(frame, 'options.context.api_key_id')) {
// @TODO: `api_key_id` does not work long term, because it can be either a content or an admin api key?
/**
* ## current cases:
* - context object is empty (functional call, content api access)
* - api_key_id exists? content api access
* - user exists? admin api access
*/
if (Object.keys(frame.options.context).length === 0 || (!frame.options.context.user && frame.options.context.api_key_id)) {
frame.data.page = false;
}

View file

@ -23,6 +23,9 @@ describe('Unit: v2/utils/serializers/input/posts', function () {
const apiConfig = {};
const frame = {
options: {
context: {
user: 1
}
}
};