Looking for a user organisation example


#1

HI
Does anyone have a working example to organize users in groups? Possibly using 3stack:accounts-organisation ?

I intend to create a hierarchical organisation with managers/users and appropriate privileges. Other suggestions are welcome and any help would be appreciated, as I am still a novice.
Thanks


#2

This is a basic setup inside our settings.json file. This is not hierarchial, but you can setup quite complex roling with this one. It’s server-side readable only, so make sure you put it inside the private-object.

private: {
    default: ["read"], // applied for everyone
    groups: [
        {
            name: "superadmin",
            label: "Superadmin",
            roles: ["admin", "mod", "read", "write", "post"]
        },
        {
            name: "moderator",
            label: "Moderator",
            roles: ["mod", "read", "post"]
        },
        {
            name: "basic",
            label: "Basic user",
            roles: ["read", "post"]
        }
    ]
}

Each user has groups set inside the user object (accessible server only):

Meteor.user() = {
    _id: xyz12,
    emails: [...]
    ....

    groups: ["moderator"]    
}

Remember to publish contents of the groups-array in your publication.

Now I can check users’ privileges by comparing user’s groups from Meteor.user().groups with the settings.json-setup and see which rights the user has.

This example is far from perfect, but it’s still quite flexible, as you can check read/write/post/etc-rights in your controller.