Rails and Mongoid best way to implement sharing system
- by Matteo Pagliazzi
I have to model User and Board in rails using mongoid as ODM.
Each board is referenced to an user through a foreign key user_id and now I want to add the ability to share a board with other users.
Following CRUD I'd create a new Model called something like Share and it's releated Controller with the ability to create/edit/delete a Share but I have some doubts:
First, where to save informations about Shares? I think I may create a field in the Board's collection called shared_with including an array of user ids. in a MySQL I'd created a new table with the ids of who share, the resource shared and the user the resources is shared with but I don't think that's necessary using MongoDB.
Every user a Board is shared with should be able to edit the Board (but not to delete it) so the Board should have two relations one with the owner and another with the users the board is shared with, right?
For permission (the owner should be able to delete a board but the users it is shared with shouldn't) what to use? I'm using Devise for authentication but I think something like CanCan would fit better. but how to implement it?
What do you think about this way? Do you find any problems or have better solutions?