Base solution for your next web application
Open Closed

Tenant data is not available to Host #9771


User avatar
0
huntethan89 created

I am developing tenant based application (Single database). I have created database table using IMayHaveTenant, Now when I log in using Host account I am not getting records created by Tenants.

I have studied this tutorial about disabling filters. Disabling Filters, Using this I am able to get Tenants+Host data. But the issue is when I logged in as a Tenant, Host data +Other Tenants data is also available to logged in Tenant. Please suggest how to achieve this:

  1. Host can view all data (Host +Tenants).
  2. Tenant can only view his data.

Here is my App Service Code:

IQueryable<Entity_Tag_Color> query = _tagColorRepository.GetAll()
                .WhereIf(!input.Name.IsNullOrWhiteSpace(), x => x.Name.Contains(input.Name.Trim()));

int recordsCount = 0;
List<Entity_Tag_Color> allRecords = null;
using (_unitOfWorkManager.Current.DisableFilter(AbpDataFilters.MayHaveTenant))
{
recordsCount= await query.CountAsync();

allRecords = await query.OrderBy(input.Sorting).PageBy(input).ToListAsync();

}
  • What is your product version? 8.0.0.0
  • What is your product type (Angular or MVC)? MVC
  • What is product framework type? .net framework

If issue related with ABP Framework

  • What is ABP Framework version? 8.0.0.0

1 Answer(s)
  • User Avatar
    0
    zony created
    Support Team

    Hi smartlayer, If you want the host to view all data, just disable the tenant filter. If you only want tenants to see their own data, you can add a judgment logic, because when the host logs in, its TenantId is empty. You just need to write the code like this:

    public async Task TestDemoAsync()
    {
        IDisposable filterDisposable = null;
        try
        {
            if (AbpSession.MultiTenancySide == MultiTenancySides.Host)
            {
                filterDisposable = UnitOfWorkManager.Current.DisableFilter(AbpDataFilters.MayHaveTenant);
            }
    
            recordsCount = await query.CountAsync();
            allRecords = await query.OrderBy(input.Sorting).PageBy(input).ToListAsync();
        }
        finally
        {
            filterDisposable?.Dispose();
        }
    }