From 847fc63b0c469a4ea957f3a4bba97a45343387de Mon Sep 17 00:00:00 2001 From: Sebastian Mihalache <sebastian.mihalache@gmail.con> Date: Wed, 18 Jul 2018 11:11:41 +0300 Subject: [PATCH] fix authsome mode --- .../src/fixtures/users.js | 72 +++++++++++++++++++ packages/xpub-faraday/config/authsome-mode.js | 10 ++- 2 files changed, 79 insertions(+), 3 deletions(-) diff --git a/packages/component-fixture-manager/src/fixtures/users.js b/packages/component-fixture-manager/src/fixtures/users.js index c858e23e3..e118c2bce 100644 --- a/packages/component-fixture-manager/src/fixtures/users.js +++ b/packages/component-fixture-manager/src/fixtures/users.js @@ -26,6 +26,12 @@ const users = { admin: true, id: admin.id, isActive: true, + notifications: { + email: { + user: true, + system: true, + }, + }, }, editorInChief: { type: 'user', @@ -42,6 +48,12 @@ const users = { isConfirmed: false, editorInChief: true, isActive: true, + notifications: { + email: { + user: true, + system: true, + }, + }, }, handlingEditor: { type: 'user', @@ -58,6 +70,12 @@ const users = { handlingEditor: true, title: 'Mr', isActive: true, + notifications: { + email: { + user: true, + system: true, + }, + }, }, answerHE: { type: 'user', @@ -74,6 +92,12 @@ const users = { handlingEditor: true, title: 'Mr', isActive: true, + notifications: { + email: { + user: true, + system: true, + }, + }, }, user: { type: 'user', @@ -99,6 +123,12 @@ const users = { }), token: chance.hash(), isActive: true, + notifications: { + email: { + user: true, + system: true, + }, + }, }, author: { type: 'user', @@ -118,6 +148,12 @@ const users = { teams: [authorTeamID], confirmationToken: chance.hash(), isActive: true, + notifications: { + email: { + user: true, + system: true, + }, + }, }, reviewer: { type: 'user', @@ -135,6 +171,12 @@ const users = { teams: [revTeamID], invitationToken: 'inv-token-123', isActive: true, + notifications: { + email: { + user: true, + system: true, + }, + }, }, answerReviewer: { type: 'user', @@ -152,6 +194,12 @@ const users = { teams: [revTeamID], invitationToken: 'inv-token-123', isActive: true, + notifications: { + email: { + user: true, + system: true, + }, + }, }, submittingAuthor: { type: 'user', @@ -168,6 +216,12 @@ const users = { save: jest.fn(() => users.submittingAuthor), isConfirmed: false, isActive: true, + notifications: { + email: { + user: true, + system: true, + }, + }, }, recReviewer: { type: 'user', @@ -184,6 +238,12 @@ const users = { isConfirmed: true, teams: [revTeamID], isActive: true, + notifications: { + email: { + user: true, + system: true, + }, + }, }, inactiveReviewer: { type: 'user', @@ -200,6 +260,12 @@ const users = { isConfirmed: true, teams: [revTeamID], isActive: false, + notifications: { + email: { + user: true, + system: true, + }, + }, }, inactiveUser: { type: 'user', @@ -225,6 +291,12 @@ const users = { }), token: chance.hash(), isActive: false, + notifications: { + email: { + user: true, + system: true, + }, + }, }, } diff --git a/packages/xpub-faraday/config/authsome-mode.js b/packages/xpub-faraday/config/authsome-mode.js index 1c6078a2d..2a6968bf4 100644 --- a/packages/xpub-faraday/config/authsome-mode.js +++ b/packages/xpub-faraday/config/authsome-mode.js @@ -1,5 +1,5 @@ const config = require('config') -const { get, pickBy, last } = require('lodash') +const { get, pickBy, last, has } = require('lodash') const statuses = config.get('statuses') const helpers = require('./authsome-helpers') @@ -280,8 +280,12 @@ async function applyEditorInChiefPolicy(user, operation, object, context) { } const authsomeMode = async (userId, operation, object, context) => { - if (get(object, 'targetUser.isActive')) { - return !!object.targetUser.isActive + if (get(object, 'targetUser')) { + if (has(object, 'targetUser.isActive')) { + return !!object.targetUser.isActive + } + + return true } if (!userId) { -- GitLab