B2B application: users has its own users
-
16-03-2021 - |
Domanda
B2B Scenario I am trying is that:
The following Roles exists in the system:
- Super Admin
- Super Admin Staff
- Owner (client)
- Admin (owner i.e. client and creates admin to define sales counters)
- Sales Counters
That means there are users who'll create their own sub users e.g.
[FLAG-A] ROLE "SUPER ADMIN" creates a ROLE "Owner" and "OWNER" creates its own sub users ROLES i.e. "ADMN" & "SALES COUNTER".
Each role obviously has its info to login to the system
I tried to design database as following:
In this diagram I am assuming that main user creates sub user that in my view many to many relationship so I have to add table between them as "USER_PERSON".
Problem is to set "WHO CREATED USER" in the system. I mean which user has created sub user as described in [FLAG-A]
Please check this diagram
Soluzione
Your approach is unnecessarily complicated. Your situation boils down to this:
- You have users (also persons), with their corresponding attributes, including login credentials and such, but also status and last login date.
- A user (person) can have one (or more?) role(s).
- A role has one or more permissions.
- A user can be created by one other user, so the user's creator is among the user's attributes.
So, I'd model three entities:
- User (with all the properties), with a self-reference to the user's creator.
- Role, with a many-to-many relationship to User.
- Permission, with a many-to-one (or many-to-many) relationship to Role.
That's it.