From 92ca5be1e7292617f46e168c549eca0ff2379097 Mon Sep 17 00:00:00 2001 From: aquelatecnologia <43894875+aquelatecnologia@users.noreply.github.com> Date: Mon, 23 Sep 2019 10:38:25 -0300 Subject: [PATCH 1/2] Fixing #28 Server.bind send its info to h.context --- lib/index.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/index.js b/lib/index.js index f21012b..14bf081 100644 --- a/lib/index.js +++ b/lib/index.js @@ -101,7 +101,9 @@ internals.validateRoutes = (server) => { * @param h Hapi Reponse Toolkit https://hapijs.com/api#response-toolkit */ internals.onPreHandler = async (request, h) => { - + //#28 server.binds send to h.context now + const config = h.context.config; + // Ignore OPTIONS requests if (request.route.method === 'options') { return h.continue; @@ -128,9 +130,9 @@ internals.onPreHandler = async (request, h) => { let roleHierarchy = null; // If we're not using hierarchy - if (!!this.config && this.config.hierarchy === true) { + if (!!config && config.hierarchy === true) { // this.config comes from plugin.bind - roleHierarchy = this.config.roleHierarchy; + roleHierarchy = config.roleHierarchy; } else { roleHierarchy = false; } From 8b6251d295ad3c1312b3afcdd762565007f104b1 Mon Sep 17 00:00:00 2001 From: Ricardo Rodriguez Date: Fri, 25 Oct 2019 02:43:30 -0500 Subject: [PATCH 2/2] Update acl.js fix unit test --- lib/acl.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/lib/acl.js b/lib/acl.js index ff52c00..f6c5565 100644 --- a/lib/acl.js +++ b/lib/acl.js @@ -39,10 +39,11 @@ internals.isGranted = function(userRole, requiredRole, hierarchy) { // If the user's role is not any of the possible roles if (index === -1) { - return false; - } - - userRoles = _.rest(hierarchy, index); // Get all the possible roles in the hierarchy + userRoles = userRole; + }else{ + userRoles = _.rest(hierarchy, index); // Get all the possible roles in the hierarchy + } + } else { userRoles = userRole; }