I'm using Rails 5.0.0.1 and a custom authentication/authorization system (similar to Devise/CanCan).
I'm working on a Rails app and I'm looking for some advice on how to show/hide data based on whether or not a user is part of a "group" or "project".
The app: basically, users can "highlight" lines of a text article. They are first presented with a view of the article’s contents (i.e., an index of its lines). They can select a line to highlight. When a line has been highlighted, any user can click on it to bring up a comments section for that line.
Article has_many Lines
Line has_many Highlights
Highlight has_many Comments
User has_many Highlights
User has_many Comments
Highlight belongs_to User
Comments belongs_to Highlight
Comments belongs_to User
Now I would like to add "Group Project" functionality. A user selects an article to use in a Group Project. He invites other users to this project. Invited users can highlight and comment, but all the highlights and comments are only visible to users of that project.
My idea was to create ‘scope’. By default, for all articles, highlights, and comments, the scope is ‘public’. Any user can log in and view those articles, highlights, comments. But a user can also access one of his Group Projects and see (possibly the same) articles with ‘privately’ scoped highlights, comments, etc. This brings up the problem that a single Line can have multiple highlights and comments with different scopes. An article's line's highlights/comments have a single public version and multiple private versions.
My question is how can I efficiently deal with these multiple instances? Should I create new instances of the Lines for each project? This seems like unnecessary duplication in the database. Should I put some conditional in the controller or model to scope based on project_id or something similar?
I know there are multiple gems for dealing with "user groups", but they are typically used for authorization. I would like for a user to be able to create any number of projects, which each have their own invitees and highlights and comments.