3

I'm trying to add the roles package and then set a custom user role like guest or member so I can use it with paid plans. I'm getting the following error

Exception in defer callback: Error: When the modifier option is true, validation object must have at least one operator
at checkModifier (packages/aldeed:simple-schema/simple-schema-validation.js:271:1)
at doValidation1 (packages/aldeed:simple-schema/simple-schema-validation.js:321:1)

When I run the following function

Meteor.methods({
    setUserRole: function(userId, roleToSet){
        // check(Meteor.userId(), String);
        check(userId, String );
        check(roleToSet, String);

        var user = Meteor.users.findOne(userId);

        if (_.isEmpty(user.roles)) {
            Roles.addUsersToRoles(userId, roleToSet);
        }
    }
});
Almog
  • 2,639
  • 6
  • 30
  • 59
  • This probably doesn't cause the error. Can you post the relevant parts of your `Roles` schema and the `addUsersToRoles` function? – halbgut Jul 27 '15 at 10:14
  • I have the same error. Did you able to find the source? It is definitely the Schema related. But I can't figure out yet. – Kostanos Dec 20 '15 at 21:27

3 Answers3

1

This error is thrown by simple-schema, it means that an update method is used using a modifier that doesn't have an operator ($set, $unset, .. etc). The latest version of the roles package seems to avoid this in the code related to Roles.addUsersToRoles, but if the error goes away when you comment the line where you use addUsersToRoles method, then maybe you need to

  1. Make sure you are using latest version of roles package or use :

    meteor update alanning:roles 
    
  2. Check the code that calls this method and make sure arguments are correct and in correct order

  3. Make sure you are not mixing grouped with non-grouped model (when using the roles package you should choose whether to always use groups or never use them) .. for example :

     Roles.addUsersToRoles(userId, roles, Roles.GLOBAL_GROUP)
    
Mahmoud Mostafa
  • 181
  • 1
  • 6
1

This often means you're trying to $set a field that hasn't been added to the schema.

If you're using Telescope, make sure you call Users.addField() for whatever fields are needed by the Roles package.

Sacha
  • 1,987
  • 1
  • 24
  • 41
  • I added the field 100% it still didn't work I ended up removing the roles package and just setting an isGuest field under the user. – Almog Jul 30 '15 at 20:40
1

This happens when you apply schema to Users collection.

There are two types of roles you can apply:

  roles: {
      type: Object,
      optional: true,
      blackbox: true
  },

or

  roles: {
      type: [String],
      optional: true
  }

You can't use both at the same time. In your case, as you do not use the groups in Roles.addUsersToRoles(userId, roleToSet); you need the second example of roles schema definition.

Just be aware that you will not be able to use groups without changing the scheme.

Kostanos
  • 9,615
  • 4
  • 51
  • 65