0

I'm using alanning roles for setting up roles and groups. I currently have a method that allows to change the role of a user and it works perfectly. I use similar syntax to set the group for a user and I don't get any errors on the console and it spits my object as indicated below, however when I check the database no groups have been added to this user. I tried several things thus far to no success. Either my check throws an error or no errors but no update on the user object. What am I not seeing here?

Comes from this form...

<select {{disableIfAdmin _id}} name="userGroup" class="form-control">
      <option selected="{{selected group.[0] 'wazzio'}}" value="wazzio">Wazzio</option>
      <option selected="{{selected group.[0] 'estore'}}" value="estore">E-store</option>
      <option selected="{{selected group.[0] 'customer'}}" value="customer">Customer</option>
</select>

Object created...

Object {user: "ZgxC4K6qhx5zXht88", roles: "sales", group: "estore"}

This is the event listener to wait for a selection to call the method:

'change [name="userGroup"]': function( event, template ) {
  var group = $( event.target ).find( 'option:selected' ).val();

  Meteor.call( "setGroupOnUser", {
    user: this._id,
    roles: this.roles[0],
    group: group
  });
}

This is the method that is suppose to set the group to this user:

setGroupOnUser: function( options ) {

  console.log(options);
  check( options, {
    user: String,
    roles: String,
    group: String
  });

  try {
    Roles.setUserRoles( options.user, [options.roles], options.group);
  } catch ( exception ) {
    return exception;
  }
}

It throws this errror in the catch exception:

MinimongoError: can't append to array using string field name [estore] [409]"
Emmanuel Henri
  • 153
  • 3
  • 27
  • Is the data context of your event handler a user object? You refer to `this._id` but is that the `_id` of an actual user? Also you don't need to make `options.roles` into an array when you use `setUserRoles`, it will accept a simple string there. – Michel Floyd Jun 11 '16 at 18:26
  • @MichelFloyd yes it is as I'm using the exact same (almost identical) method to update the roles. The object that gets console.logged just before the check() function is the object I have at the top of my question `Object {user:...}` – Emmanuel Henri Jun 11 '16 at 18:52
  • I think the roles package sometimes appended roles directly, without a group. `{ roles: ['somerole'] }` (instead of using the global group). That could certainly cause the issue you're seeing, since you'd be trying to set `{ roles: { someGroup: ['someRole'] } }`. Try to query a user document that's giving you issues and see if that's what the matter is. – cwohlman Jun 12 '16 at 00:08

0 Answers0