Permalink
Browse files

default scope

  • Loading branch information...
1 parent b7242f5 commit a84082d066d98d87517dc76c6137afd96d88efbb @mwawrusch mwawrusch committed Jan 3, 2013
Showing with 17 additions and 8 deletions.
  1. +4 −2 README.md
  2. +7 −3 lib/api-facade-client.js
  3. +1 −1 package.json
  4. +5 −2 src/api-facade-client.coffee
View
@@ -32,6 +32,8 @@ Resonable documentation will be written when I have a bit more time.
## Release Notes
+### 0.2.1
+* Added support for default scope if none is present. E.g. define a default scope, which is used if options.scopes is null or contains nothing.
### 0.2.0
* First version
@@ -45,8 +47,8 @@ Resonable documentation will be written when I have a bit more time.
* Change version in package.json
git add . -A
-git commit -m "Upgrading to v0.2.0"
-git tag -a v0.2.0 -m 'version 0.2.0'
+git commit -m "Upgrading to v0.2.1"
+git tag -a v0.2.1 -m 'version 0.2.1'
git push --tags
npm publish
@@ -96,7 +96,7 @@
ApiFacadeClient.prototype.mappingsFromSchema = function(schema, options) {
- var filterScopes, finalFields, k, key, mappings, resultMappings, scope, scopeKey, scopeValue, v, _i, _len, _ref;
+ var filterScopes, finalFields, k, key, mappings, resultMappings, scope, scopeKey, scopeValue, scopes, v, _i, _len, _ref;
if (options == null) {
options = {};
}
@@ -108,10 +108,14 @@
if (!(filterScopes && _.keys(filterScopes).length > 0)) {
return mappings;
}
+ scopes = options.scopes;
+ if (!scopes || (_.isArray(scopes) && scopes.length === 0)) {
+ scopes = ['default'];
+ }
finalFields = {};
for (scopeKey in filterScopes) {
scopeValue = filterScopes[scopeKey];
- if (_.contains(options.scopes, scopeKey) && scopeValue.mode !== 'restrict') {
+ if (_.contains(scopes, scopeKey) && scopeValue.mode !== 'restrict') {
_ref = scopeValue.fields || {};
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
scope = _ref[_i];
@@ -121,7 +125,7 @@
}
for (scopeKey in filterScopes) {
scopeValue = filterScopes[scopeKey];
- if (_.contains(options.scopes, scopeKey) && scopeValue.mode === 'restrict') {
+ if (_.contains(scopes, scopeKey) && scopeValue.mode === 'restrict') {
for (k in finalFields) {
if (!_.contains(scopeValue.fields, k)) {
delete finalFields[k];
View
@@ -2,7 +2,7 @@
"author": "Martin Wawrusch <martin@wawrusch.com> (http://martinatsunset.com)",
"name": "api-facade",
"description": "A library that simplifies the exposure of data through REST interfaces in a secure, scope dependent way. Basically transforms internal data into whatever a client of your API has the right to see.",
- "version": "0.2.0",
+ "version": "0.2.1",
"main" : "lib/index.js",
"repository": {
"type": "git",
@@ -45,11 +45,14 @@ module.exports = class ApiFacadeClient
filterScopes = schema.scopes || {}
return mappings unless filterScopes && _.keys(filterScopes).length > 0
+ scopes = options.scopes
+ scopes = ['default'] if !scopes || (_.isArray(scopes) and scopes.length is 0)
+
finalFields = {}
- for scopeKey,scopeValue of filterScopes when _.contains(options.scopes,scopeKey) && scopeValue.mode isnt 'restrict'
+ for scopeKey,scopeValue of filterScopes when _.contains(scopes,scopeKey) && scopeValue.mode isnt 'restrict'
finalFields[scope] = true for scope in (scopeValue.fields || {})
- for scopeKey,scopeValue of filterScopes when _.contains(options.scopes,scopeKey) && scopeValue.mode is 'restrict'
+ for scopeKey,scopeValue of filterScopes when _.contains(scopes,scopeKey) && scopeValue.mode is 'restrict'
for k of finalFields
delete finalFields[k] if not _.contains( scopeValue.fields,k)

0 comments on commit a84082d

Please sign in to comment.