Alanning:roles v2 released

For those who pay close attention, you might have notice that work has resumed on alanning:roles package under the stewardship of Meteor Community Packages, which culminated in release of long overdue second version.

Since this is v2, there are breaking changes:

Migration to 2.0

In meteor-roles 2.0, functions are mostly backwards compatible with 1.0, but roles are stored differently in the database. To migrate the database to new schema, run Meteor._forwardMigrate() on the server:

meteor shell > Package[‘alanning:roles’].Roles._forwardMigrate()

Changes between 1.0 and 2.0

Here is the list of important changes between meteor-roles 1.0 and 2.0 to consider when migrating to 2.0:

  • New schema for roles field and Meteor.roles collection.
  • Groups were renamed to scopes.
  • Scopes are always available, if you do not specify a scope, role is seen as a global role.
  • GLOBAL_GROUP is deprecated and should not be used anymore (just do not specify a scope, or use null ).
  • getGroupsForUser is deprecated, getScopesForUser should be used instead.
  • Functions which modify roles are available both on the client and server side, but should be called on the client side only from inside Meteor methods.
  • deleteRole can now delete role even when in use, it is automatically unset from all users.
  • Functions addRolesToParent and removeRolesFromParent were added.
  • addUsersToRoles and setUserRoles now require that roles exist and will not create missing roles automatically.
  • All functions work with 1.0 arguments, but in 2.0 accept extra arguments and/or options.

Changes

v2.0.1

  • Wrap localStorage in try/catch to avoid crash when disabled. Port fix from v1 branch. #182

v2.0.0

  • Rewrite with the new schema for roles field and Meteor.roles collection.
  • Support for roles hierarchies.
  • Groups were renamed to scopes.
  • Groups/scopes are always available, if you do not specify a scope, role is seen as a global role.
  • GLOBAL_GROUP is deprecated and should not be used anymore (just do not specify a scope, or use null ).
  • getGroupsForUser is deprecated, getScopesForUser should be used instead.
  • Functions which modify roles are available both on the client and server side, but should be called on the client side only from inside Meteor methods.
  • deleteRole can now delete role even when in use, it is automatically unset from all users.
  • Functions addRolesToParent and removeRolesFromParent were added.
  • addUsersToRoles and setUserRoles now require that roles exist and will not create missing roles automatically.
  • All functions work with 1.0 arguments, but in 2.0 accept extra arguments and/or options.

Going forward

There have also been updates to v1 and we will accept PRs for v1 and v2, but work has started on v3, which is primarily focused on code modernization and removal of underscore.

35 Likes

We are also working on other packages as well. I’m personally focusing on getting new version for collection hooks, which I think we can do this week.

6 Likes

Thanks for the announcement. I submitted an issue for the project. Hopefully the docs reflect the change accurately. [edit: fixed!]

1 Like

Fantastic! I use this package in a lot of projects, it is brilliant.

1 Like

Quite a lot happening right now. Great stuff!

5 Likes

Is there a website or something for Meteor community packages? How can we donate to it?

3 Likes

Some individual developers have setup PayPal or some other form of donation services. Nothing for the group at this moment.

There is an old topic that lists some of them. If the person you want to donate to is missing, try sending them a personal message.

Is it worth setting up an open collective for meteor community?

1 Like

We’ve briefly talked about it in the past. I think for that we would need a more formal structure and system than we have now.
I’m not against it, but that can get messy rather quickly. Hence I prefer to take it more slowly.

2 Likes

Drop us a note, please, when that happens :slight_smile:

1 Like

Thank you really much for your work on the Alanning:roles package.
Re migration from v1 to v2.0, you mention to use:

meteor shell > Package[‘alanning:roles’].Roles._forwardMigrate()

I understand meteor shell commands can be used on development/local app.
I’d love to use the v2.0 on a production app i’m running on galaxy. Is there a way to run meteor shell commands on a production or should i run a similar command in the startup/server/index.js file ?
Thanks in advance for your help

It should be safe to put this in a Meteor.startup block, deploy, then remove it for the next deployment. Looking at the code, it should be safe to run the migration method multiple times (it’ll run once for each server instance).

import { Roles } from 'meteor/alanning:roles'
Meteor.startup(() => {
  Roles._forwardMigrate()
})
2 Likes

Ok. Great. Thank you for your help