Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
1 year ago
Solved

Dynamic RLS based on multiple columns and many to many relationship

Hello,

 

I am trying to create a dynamic RLS, but the problem is that my model is a many to many relationship between users table and mapping table and I am not able to create an active relationship  with Security filter aplied. 

This is the model:

Here is a sample of data from the model

1. Fact

dataset_entitydataset_path
EBEsilver/semarchy/merchants/acceptorReferential
EBEsilver/sun/finance/ledgerAccount
EBGsilver/tri2/merchant/invoiceBulletin
EBGsilver/tri2/merchant/merchantData
ECZsilver/tri/operation/tVrfVoucherRedemptionForm
ECZsilver/tri/sales/tCusCustomer
EDEsilver/sharepointFiles/marketing/salesforceProducts
EDEsilver/sharepointFiles/operation/brandLookup
EDEsilver/sharepointFiles/operation/cmoCardDetails
EFIsilver/delicard/marketing/cards
EFIsilver/delicard/marketing/customers

 

2. Mapping

dataset_entityCountryBL
EBEBelgiumBenefits
EBGUNKNOWN 
ECZCzech RepublicBenefits
EDEGermanyMobility
EFIFinland

Benefits

 

And this is my Users table (exel file in the sharepoint, can be edited anytime by the owner) this will be linked to mapping table:

UserCountryBL
[email protected]BelgiumBenefits
[email protected]BelgiumMobility
[email protected]GermanyMobility
[email protected]GermanyMobility
[email protected]FinlandBenefits
[email protected]FinlandMobility
[email protected]Czech RepublicAll
[email protected]AllBenefits

 

So I need to create a dynamic RLS because users can be added or changed in a specific country and to give access to Country and BL

 

Thank you!

 

  • Anonymous's avatar
    Anonymous
    1 year ago

    SOLUTION!

     

    VAR _UserEmail = USERPRINCIPALNAME()
    VAR _UserBL =
        CALCULATETABLE(
            VALUES(Users_files_from_sharepoint[BL]),
            FILTER(Users_files_from_sharepoint, Users_files_from_sharepoint[User email] = _UserEmail)
        )
    VAR _UserCountry =
        CALCULATETABLE(
            VALUES(Users_files_from_sharepoint[Country]),
            FILTER(Users_files_from_sharepoint, Users_files_from_sharepoint[User email] = _UserEmail)
        )

    RETURN

        (CONTAINS(_UserBL, Users_files_from_sharepoint[BL], "eQ") &&
         CONTAINS(_UserCountry, Users_files_from_sharepoint[Country], "eQ"))
        ||
        (CONTAINS(_UserBL, Users_files_from_sharepoint[BL], "All") &&
         CostMonitoring_Mapping_files_from_sharepoint[Country] IN _UserCountry)
        ||
        (CONTAINS(_UserCountry, Users_files_from_sharepoint[Country], "All") &&
         CostMonitoring_Mapping_files_from_sharepoint[BL] IN _UserBL)
        ||
        (NOT CONTAINS(_UserBL, Users_files_from_sharepoint[BL], "All") &&
         NOT CONTAINS(_UserCountry, Users_files_from_sharepoint[Country], "All") &&
         CostMonitoring_Mapping_files_from_sharepoint[BL] IN _UserBL &&
         CostMonitoring_Mapping_files_from_sharepoint[Country] IN _UserCountry)

3 Replies

  • Create new columns on your mapping table and user table, e.g.

    Combined Columns =
    COMBINEVALUES ( "|", Mapping[Country], Mapping[BL] )
    

    and then use the new columns to create a many-to-many relationship, single direction so that users filters mapping.

    • Anonymous's avatar
      Anonymous
      Not applicable

      Thank you! but what about the situations where I have a user that needs to see the Country and all BL, or a user who needs to see a BL for every Countries?

  • Anonymous's avatar
    Anonymous
    Not applicable

    SOLUTION!

     

    VAR _UserEmail = USERPRINCIPALNAME()
    VAR _UserBL =
        CALCULATETABLE(
            VALUES(Users_files_from_sharepoint[BL]),
            FILTER(Users_files_from_sharepoint, Users_files_from_sharepoint[User email] = _UserEmail)
        )
    VAR _UserCountry =
        CALCULATETABLE(
            VALUES(Users_files_from_sharepoint[Country]),
            FILTER(Users_files_from_sharepoint, Users_files_from_sharepoint[User email] = _UserEmail)
        )

    RETURN

        (CONTAINS(_UserBL, Users_files_from_sharepoint[BL], "eQ") &&
         CONTAINS(_UserCountry, Users_files_from_sharepoint[Country], "eQ"))
        ||
        (CONTAINS(_UserBL, Users_files_from_sharepoint[BL], "All") &&
         CostMonitoring_Mapping_files_from_sharepoint[Country] IN _UserCountry)
        ||
        (CONTAINS(_UserCountry, Users_files_from_sharepoint[Country], "All") &&
         CostMonitoring_Mapping_files_from_sharepoint[BL] IN _UserBL)
        ||
        (NOT CONTAINS(_UserBL, Users_files_from_sharepoint[BL], "All") &&
         NOT CONTAINS(_UserCountry, Users_files_from_sharepoint[Country], "All") &&
         CostMonitoring_Mapping_files_from_sharepoint[BL] IN _UserBL &&
         CostMonitoring_Mapping_files_from_sharepoint[Country] IN _UserCountry)