Open Closed

How to restrict an entity object creation on the Tenant side? #1498


User avatar
0
VivekKoppula created

I created an multi tenant application as per the options shown here in these images in this issue(closed now).

I created a new entity called Gender as per the steps explained in this section. I

I did not want mult-tenant feature on this, so ensured the multi-tenant check box is NOT Selected.

When I run the appication, every thing is working fine.

The host admin is now able to created objects of Gender.

Now I dont want the tenants to create such objects. I logged in as CompanyA/Admin(tenant - CompanyA) and I am able to create Gender.

I want to restrict this. Tenants should not be allowed to create Gender objects while the host should be allowed. How can I achieve that?

Looking at the code, it appears that this should be something to do with Permissions. But I have no clue what do with this.

public class Genders {
    public const string Default = GroupName + ".Genders";
    public const string Edit = Default + ".Edit";
    public const string Create = Default + ".Create";
    public const string Delete = Default + ".Delete";
}

One way I found is to ensure that the tenant id is null in the GenderAppService class. If the tenant id is not null, then it means that the user is from a tenant. Then in such a case throw some exception. But this is from the developers perspective. Can the end host admin do something himself to impose such a restriction?


2 Answer(s)
  • User Avatar
    0
    VivekKoppula created

    Ok, one solution I got is the following.

    var genderPermission = myGroup.AddPermission(AbpAppTmpltMvcPvtPermissions.Genders.Default, L("Permission:Genders"), MultiTenancySides.Host);
    

    Added the parameter MultiTenancySides.Host.

    That file is AbpAppTmpltMvcPvtPermissionDefinitionProvider from the contract project AbpAppTmpltMvcPvt.Application.Contracts and inside Permissions folder.

  • User Avatar
    0
    alper created
    Support Team Director

    that's the good solution

Boost Your Development
ABP Live Training
Packages
See Trainings
Mastering ABP Framework Book
Do you need assistance from an ABP expert?
Schedule a Meeting
Mastering ABP Framework Book
The Official Guide
Mastering
ABP Framework
Learn More
Mastering ABP Framework Book
Made with ❤️ on ABP v9.2.0-preview. Updated on March 20, 2025, 18:00