Reputation: 253
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.
Locations
What would be a good way to verify that a registered user belongs to a company? I'm thinking manual verification, as not everybody in the company should have access. But any clever thoughts are appreciated.
Collections equipment and locations holds documents belonging to different companies. These collections can get pretty big. Is it wise to have an "Equipment collection" for each company?
Should i create a group for each company and add user to the correct group?
What is the best way to link collections/documents to user/company?
Any other thoughts?
Thank you.
Upvotes: 1
Views: 84
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