Meteor-Community-Packages / meteor-roles

Authorization package for Meteor, compatible with built-in accounts packages
http://meteor-community-packages.github.io/meteor-roles/
MIT License
921 stars 168 forks source link

Suggest 'context' instead of 'group' or 'partition' #213

Closed jonlachlan closed 8 years ago

jonlachlan commented 8 years ago

1.X calls it 'group', 2.X will call it 'partition', but since 2.X is not released yet, why not call it the 'context' instead, which might be more intuitive.

mitar commented 8 years ago

Not sure if context is really any better?

jerfowler commented 8 years ago

How about "scope"? Such as these roles are valid only within this "scope".

jsamr commented 8 years ago

+1 for scope

mitar commented 8 years ago

Let's put it up to vote. I will create comments for each of them, and upvote/downvote those you like/dislike.

mitar commented 8 years ago

group

mitar commented 8 years ago

partition

mitar commented 8 years ago

context

mitar commented 8 years ago

scope

mitar commented 8 years ago

It seems scope has some fans here. :-)

mitar commented 8 years ago

I renamed partition to scope. If anyone was using this branch, you will have to rename it in the database. Probably something like from MongoDB shell:

db.users.update({}, {$rename: {'roles.partition': 'roles.scope'}}, {multi: true});
olgertse commented 8 years ago

In case someone needs to rename the fields, this is how to do it properly. All credit goes to this Stack Overflow answer

var bulk = db.users.initializeOrderedBulkOp(),
    count = 0;

db.users.find({ "roles.partition": { "$exists": true } }).forEach(function(doc) {
    doc.roles.forEach(function(role) {
        if ( role.hasOwnProperty("partition") ) { 
            bulk.find({ "_id": doc._id, "roles._id": role._id }).updateOne({
                "$set": { "roles.$.scope": role.partition }
            });
            bulk.find({ "_id": doc._id, "roles._id": role._id }).updateOne({
                "$unset": { "roles.$.partition": 1 }
            });
            count += 2;

            if ( count % 500 == 0 ) {
                bulk.execute();
                bulk = db.users.initializeOrderedBulkOp();
            }
        }
    });
});

if ( count % 500 !== 0 )
    bulk.execute();