From 22911b5812137075389ec299da8a7761b6fb6828 Mon Sep 17 00:00:00 2001 From: kirrg001 Date: Mon, 5 Nov 2018 21:48:31 +0100 Subject: [PATCH] Fixed frame context being empty no issue --- .../api/v2/utils/serializers/input/posts.js | 18 ++++++++++++++++-- .../v2/utils/serializers/input/posts_spec.js | 3 +++ 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/core/server/api/v2/utils/serializers/input/posts.js b/core/server/api/v2/utils/serializers/input/posts.js index b707a83094..469bcd52cc 100644 --- a/core/server/api/v2/utils/serializers/input/posts.js +++ b/core/server/api/v2/utils/serializers/input/posts.js @@ -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; } diff --git a/core/test/unit/api/v2/utils/serializers/input/posts_spec.js b/core/test/unit/api/v2/utils/serializers/input/posts_spec.js index 4b3693593a..8dea74004c 100644 --- a/core/test/unit/api/v2/utils/serializers/input/posts_spec.js +++ b/core/test/unit/api/v2/utils/serializers/input/posts_spec.js @@ -23,6 +23,9 @@ describe('Unit: v2/utils/serializers/input/posts', function () { const apiConfig = {}; const frame = { options: { + context: { + user: 1 + } } };