multicolour-hapi-jsonapi
Advanced tools
Comparing version 0.2.1 to 0.2.2
30
index.js
@@ -67,2 +67,30 @@ "use strict" | ||
/** | ||
* Get any auth configuration | ||
* @param {Waterline.Collection} Collection to get auth roles from. | ||
* @param {String|Boolean} Name of the auth strategy to use or false. | ||
* @return {Object|Boolean} Auth will be false if none, otherwise an object. | ||
*/ | ||
get_auth_config(model, auth_strategy_name) { | ||
if (!auth_strategy_name) { | ||
return false | ||
} | ||
// If there's a specific role object | ||
// for this verb, set it. | ||
if (model.roles) { | ||
return { | ||
strategy: auth_strategy_name, | ||
scope: model.roles.get || model.roles | ||
} | ||
} | ||
// Otherwise, just use the defaults. | ||
else { | ||
return { | ||
strategy: auth_strategy_name, | ||
scope: ["user", "admin", "consumer"] | ||
} | ||
} | ||
} | ||
generate_related_resource_routes(server, multicolour) { | ||
@@ -111,3 +139,3 @@ // Get the collections. | ||
config: { | ||
// auth: this.get_auth_config(), | ||
auth: this.get_auth_config(model, multicolour.get("server").request("auth_config")), | ||
handler: (request, reply) => { | ||
@@ -114,0 +142,0 @@ // Merge the params into the query string params. |
{ | ||
"name": "multicolour-hapi-jsonapi", | ||
"version": "0.2.1", | ||
"version": "0.2.2", | ||
"description": "JSON API reply decorator built on Waterline and waterline-jsonapi", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -21,3 +21,7 @@ "use strict" | ||
} | ||
}, | ||
roles: { | ||
get: ["user"] | ||
} | ||
} |
29211
570