user3323307
user3323307

Reputation: 253

Meteor-Roles and linked collections

I have a concept question when it comes to roles. Im not very familiar with database design or access control. Let's say i have 4 collections.

Any other thoughts?

Thank you.

Upvotes: 1

Views: 84

Answers (1)

xSkrappy
xSkrappy

Reputation: 747

Have you tried using : https://github.com/alanning/meteor-roles

I have used that to verify roles in meteor. There would be an entry in "Companies" Collection thus you can have a Company ID. With the usage of meteor roles , I think it would be easy to do your task. In Example.

User Collection would have :

_id:
Name:
Role : [ //owner , employee ]
Company ID: 

it is up to you if you would make roles and company ids an array to handle multiple companies for a single user record thus making it alot more flexible in the long run.

Next would be make a helper in your user collection to easily track the roles. IE.

    isAdmin(companyId) {
    if(isValidRolesData(this.roles,'default-group'))
        return this.roles['default-group'].indexOf(`${companyId}-admin`) > -1;
},

/**
 * Check if a user is Staff
 * 
 * @param {any} facilityid
 * @returns
 */
isStaff(companyId) {
    if(isValidRolesData(this.roles,'default-group'))
        return this.roles['default-group'].indexOf(`${companyId}-staff`) > -1;
},

/**
 * Check if a user is Receptionist
 * 
 * @param {any} facilityid
 * @returns
 */
isReceptionist(companyId) {
    if(isValidRolesData(this.roles,'default-group'))
        return this.roles['default-group'].indexOf(`${companyId}-receptionist`) > -1;
},

With that kind of flow I guess you can achieve the exact thing you needed :)

Upvotes: 1

Related Questions