Base solution for your next web application
Open Closed

User Groups #4614


User avatar
0
OriAssurant created

How can we achieve User Groups (OU?) with scope only within the group? For example:

Tenant 1

  • (Store#1)

    • User 1
    • User 2
  • (Store#2) - User 3

    • User 4
  • (Store#3) - User 3

    • User 5

We would like to have Store#2, Store#3 be within the same scope (Group?), without sharing information (data) with Store#1.

After observing the behavior of OU's, it is a logical grouping but not scoped w/Privacy.

Thoughts?


8 Answer(s)
  • User Avatar
    0
    alper created
    Support Team

    So UserGroup fits for you. It's a way of filtering data in a tenant. Each Store can be a UserGroup.

  • User Avatar
    0
    OriAssurant created

    Can you point me to the documentation about "UserGroups"? I only see Org. Units...

  • User Avatar
    0
    alper created
    Support Team

    sorry! I wanted to say Organization Units :)

  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi @OriAssurant,

    AspNet only have Organization Units, you can use it in your case, it seems like a good fit. But, if you want to use both Organization Units and User Groups, then you have to implement User Groups.

    As you said, current OU design is a logical grouping but you can use current user's organization units to filter data or similar jobs.

  • User Avatar
    0
    OriAssurant created

    So in using OU's, how would we prevent cross OU members from seeing each other's data? You're not suggesting modifying every controller output's LINQ statement, are you?

  • User Avatar
    0
    ismcagdas created
    Support Team

    @OriAssurant, you can create an interface like IHasOrganizationUnit and implement this interface in the entities you want to filter according to current tenant's OUs.

    Then, you need to filter this by overriding GetAll method of your base repository. If you are using EF 6.x, you can use <a class="postlink" href="https://aspnetboilerplate.com/Pages/Documents/Data-Filters#introduction">https://aspnetboilerplate.com/Pages/Doc ... troduction</a>.

    The approach is similar to existing ISoftDelete interface.

  • User Avatar
    0
    OriAssurant created

    Thank you.

    I see ISoftDelete is being implement in the below fashion at AbpDbContext: protected override void OnModelCreating(DbModelBuilder modelBuilder) { base.OnModelCreating(modelBuilder); modelBuilder.Filter(AbpDataFilters.SoftDelete, (ISoftDelete d) => d.IsDeleted, false); modelBuilder.Filter(AbpDataFilters.MustHaveTenant, (IMustHaveTenant t, int tenantId) => t.TenantId == tenantId || (int?) t.TenantId == null, 0); //While "(int?)t.TenantId == null" seems wrong, it's needed. See <a class="postlink" href="https://github.com/jcachat/EntityFramework.DynamicFilters/issues/62#issuecomment-208198058">https://github.com/jcachat/EntityFramew ... -208198058</a> modelBuilder.Filter(AbpDataFilters.MayHaveTenant, (IMayHaveTenant t, int? tenantId) => t.TenantId == tenantId, 0); }

    However, if I create a new interface like IHasOraginzationUnit, how can I restrict it to just one entity/table in my Project's DbContext?

    • I also came across AbpUserStore in the meanwhile. Is there any way I can leverage this feature to achieve my task?
  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi,

    You can define filter similar to IMayHaveTenant. Then, Override the Initialize method of your dbContext, call base's Initialize first and then add your parameter value like below;

    this.SetFilterScopedParameterValue(AbpDataFilters.OuDataFilter, AbpDataFilters.Parameters.OuId, AbpSession.OuId?? 0);
    

    of course, you need to store user's OuId in the session when user logs in.