reactioncommerce/meteor-security

1.3.0 not working with Meteor.roles

Closed this issue ยท 4 comments

First of all, thanks for this package! ๐Ÿ˜ƒ
This line used to work before 1.3.0:

Security.permit(['insert', 'remove', 'update']).collections([Meteor.roles]).ifHasRole('admin').apply();

I think this line is responsible for the error and I think that this issue is related to #23

We are experiencing a similar problem with Meteor 1.2. We get the following error trace in the console:

TypeError: Cannot convert null to object
     at hasOwnProperty (native)
     at Function._.has (packages/underscore/underscore.js:1072:1)
     at packages/ongoworks_security/lib/server/security-util.js:54:1
     at packages/underscore/underscore.js:208:1
     at Array.filter (packages/es5-shim/.npm/package/node_modules/es5-shim/es5-shim.js:479:1)
     at Function._.filter._.select (packages/underscore/underscore.js:198:1)
     at Function._.reject (packages/underscore/underscore.js:207:1)
     at packages/ongoworks_security/lib/server/security-util.js:53:1
     at Array.forEach (packages/es5-shim/.npm/package/node_modules/es5-shim/es5-shim.js:417:1)
     at Function._.each._.forEach (packages/underscore/underscore.js:105:1)

Things work fine when commenting out any lines that call ifHasRole.

Is there a workaround?

Tried to make my own method, still doesn't work, I am not sure its really related to Role functionality?

Security.defineMethod('ifRole', {
  fetch: [],
  transform: null,
  deny: function (type, arg, userId) {
    console.log('deny');
    console.log(arg);
    return !Roles.userIsInRole(userId, [arg]);
  }
});

Items.permit(['insert','update','delete']).ifRole('admin').apply();
=> Exited with code: 8
W20160324-16:40:27.389(-6)? (STDERR) 
W20160324-16:40:27.389(-6)? (STDERR) C:\Users\video\AppData\Local\.meteor\packages\meteor-tool\1.1.10\mt-os.windows.x86_32\dev_bundle\server-lib\node_modules\fibers\future.js:245
W20160324-16:40:27.389(-6)? (STDERR)                        throw(ex);
W20160324-16:40:27.389(-6)? (STDERR)                              ^
W20160324-16:40:27.389(-6)? (STDERR) TypeError: Cannot convert null to object
W20160324-16:40:27.389(-6)? (STDERR)     at hasOwnProperty (native)
W20160324-16:40:27.389(-6)? (STDERR)     at Function._.has (packages/underscore/underscore.js:1072:1)
W20160324-16:40:27.389(-6)? (STDERR)     at packages/ongoworks_security/lib/server/security-util.js:54:1
W20160324-16:40:27.389(-6)? (STDERR)     at packages/underscore/underscore.js:208:1
W20160324-16:40:27.389(-6)? (STDERR)     at Array.filter (packages/es5-shim/.npm/package/node_modules/es5-shim/es5-shim.js:479:1)
W20160324-16:40:27.389(-6)? (STDERR)     at Function._.filter._.select (packages/underscore/underscore.js:198:1)
W20160324-16:40:27.389(-6)? (STDERR)     at Function._.reject (packages/underscore/underscore.js:207:1)
W20160324-16:40:27.389(-6)? (STDERR)     at packages/ongoworks_security/lib/server/security-util.js:53:1
W20160324-16:40:27.389(-6)? (STDERR)     at Array.forEach (packages/es5-shim/.npm/package/node_modules/es5-shim/es5-shim.js:417:1)
W20160324-16:40:27.389(-6)? (STDERR)     at Function._.each._.forEach (packages/underscore/underscore.js:105:1)

Pretty sure this is fixed in 2.0, or at least I cannot reproduce it. If not, please open a new issue with a link to a simple reproduction app.