Learn More, Pay Less!
Limited Time Offer!
Open Closed

Is there any way that i can change organizationUnit filter Type in AppService #8719


User avatar
0
hemanshams created
  • ABP Framework version: v8.3
  • UI Type: Angular
  • Database System: EF Core (SQL Server)

Hi abp support team, I read the documents about Organization Unit and filtering data (Doc1, Doc2) , and implement this with following steps:

  1. create IHasOrganizationUnit interface with property OrganizationUnitId
  2. create entity SampleEntity and implement the interface
  3. develop Filter in DbContext and add equal expresion to this filter
  4. develop ShouldFilterEntity for disabling and enabling this filter
  5. create Sample AppService class and implement GetList of data

now i can filter data with User Organization Unit in the appService as well.

Question: Is there any way that i can change filterType in AppService and filter data for:

  • list of OrganizationUnit, as List of User's Organization Units,
  • or User Organization Unit and its dependent Organization Unit in the hierarchy,
  • or something else?

Thanks


3 Answer(s)
  • User Avatar
    0
    EngincanV created
    Support Team .NET Developer

    or User Organization Unit and its dependent Organization Unit in the hierarchy,

    Hi, you can use the IdentityUserAppService's GetOrganizationUnitsAsync(Guid id) to get a user's all organization units. The result will be List<OrganizationUnitDto> and you can see the parentId's of the related organization units. If it's null, then it means it's a root organization unit.

    Regards.

  • User Avatar
    0
    hemanshams created

    or User Organization Unit and its dependent Organization Unit in the hierarchy,

    Hi, you can use the IdentityUserAppService's GetOrganizationUnitsAsync(Guid id) to get a user's all organization units. The result will be List<OrganizationUnitDto> and you can see the parentId's of the related organization units. If it's null, then it means it's a root organization unit.

    Regards.

    thanks for your attention to this question,

    this method is perfect for finding user's Organization Unit.

    but i need change filter type of my Entity from "equal" to "contain" as i need in business AppService, (i implement OU as same as this document)

    i mean: Situation 1: AppService1 gets data from my Entity with eaual filter type (set in DbContext Filter for OU) for current user's Organization Unit. Situation 2: AppService2 gets data from my Entity with contains filter type for List of user's Organization Unit and its hierarchy units.

    please give me additional information about above situations.

    Best Regards.

  • User Avatar
    0
    EngincanV created
    Support Team .NET Developer

    i mean:
    Situation 1: AppService1 gets data from my Entity with eaual filter type (set in DbContext Filter for OU) for current user's Organization Unit.
    Situation 2: AppService2 gets data from my Entity with contains filter type for List of user's Organization Unit and its hierarchy units.

    Hi, if I understood you correctly, for the first situation you want to apply the data filter and for the second one, you don't want to apply the data-filter and only query according to input filters. The first thing came to my mind is disabling data-filter according to a bool parameter value.

    Assume that you have a repository interface as below:

    public interface IMyRepository : IRepository<TEntity>
    {
        Task<List<TEntity>> GetAllAsync(/* other params... */, bool ignoreOUFilters = false);
    }
    

    In the repository implementation you can do something like:

    
    public async Task<List<TEntity>> GetAllAsync(/* other params... */, bool ignoreOUFilters = false)
    {
        if(ignoreOUFilters)
        {
            using(DataFilter.Disable<IHasOrganization>())
            {
                return await GetAllInternalAsync(/* other args... */, ignoreOUFilters);
            }
        }
        
        return await GetAllInternalAsync(/* other args... */, ignoreOUFilters);
    }
    
    private async Task<List<TEntity>> GetAllInternalAsync(/* other params... */, bool ignoreOUFilters = false)
    {
        //your query logic
    }
    

    Then, calling the repository method, pass if you want to allow has-organization data-filter or not.

    Regards.

Made with ❤️ on ABP v9.2.0-preview. Updated on February 13, 2025, 10:35