Reputation: 8761
We want to be able to share resources inside our web application with new or other users. We want to do this by implementing an invitation code. I have seen this implemented many times before in other applications (google docs for example), where you send an invitation code to another user and that other user will have whatever access the first user agreed.
I am sure there has to be a pattern, or best approach already documented somewhere, I just need the right words to look for it. Will someone be able to point me in the right direction? Below is the use case:
Edit 1: (Possible Algorithm to Use based on Mark Answer):
In my domain model I have User and Account and each user has 0 or more accounts. Then we also have SharedSpace, each user has 0 or more share space and each account may have 0 or more sharespace. Now Sharespace will contain (inviationCode, spaceCode, active (yes), expiration, email (share with).
Any user who has an account (acct1) is able to share space with
acct1.shareSpace("spaceCodeToShare","Emailofusertosharewith");
The method shareSpace(string,string) will do the following:
- Create and send invitation Code to email
- If user is registered, he activates his code either clicking or entering it (using authorize or customAuthorize attribute and IPrincipal to prevent unauthorized access).
- IF user is not registered then he logs in and after a user entry for this user is created then he activates the code.
- If user never activates the code the the code expires and the active status toggles to false.
Do you think I am missing anything, it looks more simple than I thought it would be?
Upvotes: 2
Views: 2132
Reputation: 233150
It sounds to me like the permissions aspect would be best modeled using Access Control Lists (ACLs). Each resource simply has a an associated ACL, and by default, only the original owner has a permission to the resource.
When you send out an invitation code, you record that code along with the permission it represents. You will need to record that association in a durable store such as a database.
When the invited user activates the invitation code, you promote the potential permission you recorded into a real permission.
I wrote more about ACL-based security here and here.
Upvotes: 2
Reputation: 65877
I am not sure about the existing patterns. But this can be done simply by having well relationed sharedRights table structure.
if you still wanted to normailze the strucre
finally it would be something like
Users ---- SharedUsers |
------- SharedRights
Resourcss ---- SharedResources |
After accepting the invitatiion, you have to populate these table with the necessary info. And granding the permission to shared users by referring these table would be simple.
Upvotes: 0