Base solution for your next web application
Ends in:
01 DAYS
01 HRS
01 MIN
01 SEC
Open Closed

How to make custom filter based on MustHaveOrganisationId? #6996


User avatar
0
mujthabagroad created

Hi,

How we can get the data which has MustHaveOrganisationId including child OU, added a custom filter for OU filter, but we need to get the data only under OU and sub OU which user has permission.

Thanks.


5 Answer(s)
  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi @mujthabagroad

    Instead of using OrganizationId, you can use Code field or Organization unit and do a query like below:

    _repository.GetAll().Where(e=> e.Code.StartsWith(filteredOuCode))

    Organization unit codes are generated according to level of OUs. So if an OU has the code 0001, its children will have 0001.0001, 0001.0002 etc... as the code.

  • User Avatar
    0
    mujthabagroad created

    Hi @ismcagdas,

    yes we can get the children with this, but I need to get only OUs and Sub OUs which is assigned to the user or role in the permission and data filter should apply based on all permitted OUs

    Thanks.

  • User Avatar
    0
    ryancyq created
    Support Team

    Hi,

    Not sure if you need permission here (since your data is permitted via OU Id)

    Nonetheless, you can get the permitted OU Ids as follows:

    1. get ou ids of the current user
    2. get role ids of current user
    3. get ou ids base on the role ids in (2)

    The permitted OU ids should be (1) + (2)

  • User Avatar
    0
    mujthabagroad created

    Hi @ryancyq,

    Thanks for your response, That is possible if we do a manual query and we need to do for all entities to get filtered, but my aim was to add as data filters for all entities. My scenario is:

    • We have Parent OU as Business Entity Office and Sub OU as Divisions, in an office will have multiple divisions
    • The user will have only one or more division access based on permission.
    • In all grid, data should be filtered and shown only which user has OU permissions
    • Should show all data without filtering if we are not setting any OU permissions for the user

    For this, we added MustHaveOrganizationUnit for all entities and we have OU id in all tables. Now we need to add data filters for all tables to filter the data based on WHERE IN permitted OU.

    Thanks.

  • User Avatar
    0
    ryancyq created
    Support Team

    Hi, if you want to implement it as data filter, you can refer to the doc for it. See https://aspnetboilerplate.com/Pages/Documents/Data-Filters

    However, do note that evaluating current user PERMITTED OU ids might be too expensive to be calculated for every query, you might want to consider caching it.