Comments (7)
Hi Kevin,
I think your approach is correct of having a separate groups collection and using the group id as the group wrt the Roles package. Rather than changing the Roles code to detect ObjectId I'd suggest using the string version of the ObjectId. You may be able to use 'toString()' or if that doesn't work, try 'toHexString()'. Here's a SO question that seemed relevant:
from meteor-roles.
Thanks for this.
Can I just check - what's the rationale for not allowing an ObjectId as a key for the groups dictionary?
I'm happy to use the toString() value here but obviously it's more convenient to keep the same data type for a field throughout the code. Also, apparently using ObjectId is more performant than string (although I don't know if that applies when were talking about an embedded document and not the _id field.)
from meteor-roles.
I would be happy to accept a pull request if you'd like to work on that. Just be sure to add a test or two to cover the new case.
On Apr 24, 2014, at 9:27 PM, Kevin Bennett [email protected] wrote:
Thanks for this.
Can I just check - what's the rationale for not allowing an ObjectId as a key for the groups dictionary?
I'm happy to use the toString() value here but obviously it's more convenient to keep the same data type for a field throughout the code. Also, apparently using ObjectId is more performant than string (although I don't know if that applies when were talking about an embedded document and not the _id field.)
—
Reply to this email directly or view it on GitHub.
from meteor-roles.
Heh, I forked and started implementing it and then discovered that in MondgoDB keys must be strings. So that puts an end to that. It could be possible by restructuring the roles doc to be an array, but a clunky solution and breaks backwards compatibility. You can mark this as closed : )
On a related note, would you accept a pull for the following:
- Roles.getAllGroups() - list all groups that exist for all users
- Roles.getGroupsForUser(role) - list all groups a user belongs to, optional restrict by role
- Automatically creating a group collection and insert a group each time a user is added to a new group, same as roles collection.
Thanks
from meteor-roles.
Thanks for looking into it.
Re: the other PRs, definitely for the first two.
Having a group collection that Roles creates is something I'd probably avoid. I debated whether to have the roles collection when I first wrote this package. I added it because I thought it would be useful for UI purposes to have a list of all roles but it's caused a lot of confusion for people so I think it was a mistake.
Can you expand a bit of your use case for how an automatically created groups collection would help?
Sent from my phone
On Apr 25, 2014, at 12:19 PM, Kevin Bennett [email protected] wrote:
Heh, I forked and started implementing it and then discovered that in MondgoDB keys must be strings. So that puts an end to that. It could be possible by restructuring the roles doc to be an array, but a clunky solution and breaks backwards compatibility. You can mark this as closed : )
On a related note, would you accept a pull for the following:
Roles.getAllGroups() - list all groups that exist for all users
Roles.getGroupsForUser(role) - list all groups a user belongs to, optional restrict by role
Automatically creating a group collection and insert a group each time a user is added to a new group, same as roles collection.
Thanks—
Reply to this email directly or view it on GitHub.
from meteor-roles.
I was thinking along the same lines as you were for 'roles' - I would like to display a list of all groups in the UI and it would be easier with a collection of all groups. But you're probably right that it's more confusing than necessary.
I'm gonna implement the getAllGroups and getGroupsForUser methods for now. If I need the create groups collection functionality later, we could achieve it by adding in hooks like onCreateGroupHook or something, and allow the new group to be published to a collection if required.
from meteor-roles.
I sent a pull request for Roles.getGroupsForUser with tests.
I see now that Roles.getAllGroups will be an expensive query, pulling the whole users collection and filtering down to unique keys in user.roles. For my use-case, this isn't acceptable. So I'm thinking I create a groups collection outside of the meteor-roles package.
I'll get back to you if I'm thinking of adding anything else.
from meteor-roles.
Related Issues (20)
- Support new Meteor async API (Meteor 2.8+) HOT 2
- Defaut publication uses only user._id, but no index is created on that field only HOT 2
- cannot add data into role-assignment HOT 3
- Meteor.roleAssignment, error: Property 'roleAssignment' does not exist on type 'typeof Meteor'. HOT 5
- Weird issue with role-assignement.. HOT 2
- Upgrading from 3.4.0 to 3.5.0 introduces 6x node "UnhandledPromiseRejectionWarning: TypeError: Cannot set property 'isCalledFromAsync' of undefined" warnings. HOT 1
- TypeError: Cannot set property 'isCalledFromAsync' of undefined ... HOT 4
- Improve community standards HOT 1
- Add code quality tools HOT 2
- Add selector to Roles.getUsersInRole HOT 2
- forwardMigrate2 tries to drop unset index HOT 1
- Add new function to change scope of existing role assignment HOT 1
- addRolesToParent -> Reset inheritance as unwanted roles may still be connected HOT 1
- Get a list of users with a scope HOT 13
- api docs still show v.3.4.0 in upper right corner HOT 1
- Not async? HOT 3
- Dependency on old [email protected] (need v3.0.0-rc300.1) HOT 3
- Roles.createRole is not a function (alanning:[email protected]) HOT 4
- Alpha 3 not compatible with Meteor 3 rc2 HOT 3
- Example app with selectable permissions HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from meteor-roles.