Hi,
I have a project requirement as shown below.Please tell me is that possible with the ASP.netZero ng-2 version.
On this application:
Tenants = Projects
We need to create users globally.The user accounts and profile information needs to be stored globally.
The user needs to create a user account if he does not have a user account already. If he has already a user account, he can use this account for all projects (Tenants).
User Profile:
Every user can edit his profile data such as his user profile picture and etc. This information is shared across all projects (Tenants).
This functionality is quite similar to the Git hub.
On Git hub:
They can store users globally == Our app also needs this feature
Repository == Projects on our app
So please tell me is this possible with the ASP.netZero architecture? Thanks.
4 Answer(s)
-
0
Hi,
In ABP Multi Tenancy approach, each user belongs to a tenant or host. So, you cannot do it directly using User entity.
You have two options,
1 ) You can create a second entity which does not imlement IMayHaveTenant and IMustHaveTenant. You can store your global data in this entity and all tenants can access this entity/table.
- But if your entity is strictly related to User entity, then you can create a similar entity like this one <a class="postlink" href="https://github.com/aspnetboilerplate/module-zero/blob/09cb578f09ee0318b479aa31dd0ceff56a5d218d/src/Abp.Zero/Authorization/Users/UserAccount.cs">https://github.com/aspnetboilerplate/mo ... Account.cs</a>. Include UserId and TenantId in this entity and other properties you like (profilePicture for example) But Don't imlement IMayHaveTenant and IMustHaveTenant. This entity must be stored in host database. Then you will need a class like this <a class="postlink" href="https://github.com/aspnetboilerplate/module-zero/blob/09cb578f09ee0318b479aa31dd0ceff56a5d218d/src/Abp.Zero/Authorization/Users/UserAccountSynchronizer.cs">https://github.com/aspnetboilerplate/mo ... ronizer.cs</a>.
This class syncs the user data from users table to your new table.
You can use this new table globally.
I hope this helps.
-
0
Hi ismcagdas,
Thanks a lot for the feedback.
But I didn't get this, This class syncs the user data from users table to your new table.So can you please explain a little bit more about that? Thanks.
-
0
Hi,
If you check this class <a class="postlink" href="https://github.com/aspnetboilerplate/module-zero/blob/09cb578f09ee0318b479aa31dd0ceff56a5d218d/src/Abp.Zero/Authorization/Users/UserAccountSynchronizer.cs">https://github.com/aspnetboilerplate/mo ... ronizer.cs</a>, you can see that it handles EntityCreated, EntityUpdated, EntityDeleted events for AbpUserBase entity (for AbpUsersTable).
Then in each event, we switch to host context (on host database) and take appropriate action. When a new user is created in a tenant/host database, we insert same record to AbpUserAccounts table here <a class="postlink" href="https://github.com/aspnetboilerplate/module-zero/blob/09cb578f09ee0318b479aa31dd0ceff56a5d218d/src/Abp.Zero/Authorization/Users/UserAccountSynchronizer.cs#L40">https://github.com/aspnetboilerplate/mo ... zer.cs#L40</a>.
We do similar things for updating a user and deleting a user.
In this way, we have a single table in host database which is a union of all tenant/host AbpUsers tables.
-
0
Hi ismcagdas,
Hmm ... Very interesting ... Really nice explanation. Thanks a lot :)