Click here to Skip to main content
15,892,768 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a relatively complex model association in mind, and was wondering how I could accomplish it. In essence, this is what i want to accomplish.

- I have a User model, and a Document model
- User A can create a document. He is now the document admin.
1. He can then add other individual users to his document, and assign them permissions, ex: (Editor, Viewer, Admins)
2. He can also create a team, a group of users, and add multiple teams to his document. Each user on a team that User A has added to his document will also have a level of permissions. A user can belong to many teams.
I am a little bit confused about the associations I will have to setup.

What I have tried:

This is the code I have so far, which has not incorporated the team aspect:

<pre>
 class User < ApplicationRecord
   has_many :participations
   has_many :documents, through: :participations
 end

 class Document < ApplicationRecord
   has_many :participations
   has_many :users, through: :participations
 end

 class Participation < ApplicationRecord
   belongs_to :user
   belongs_to :document
   enum role: [ :admin, :editor, :viewer ]
 end
Posted
Updated 29-Apr-20 13:10pm

1 solution

What you are proposing will be a hybrid.

Role Based Authorization Users can be assigned into various roles (eg DocumentAdmin) and then those roles are mapped to the documents

User Level Authorization aka Access Control List User permissions are assigned directly to the document.

These are both well documented, as they have both been used for decades; it is the basics of how file system permissions are done
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900