cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
nicktalsma
Frequent Visitor

Row Level Security in Power Apps Canvas App - SharePoint Data Source

I am trying to figure out how to implement row level security in my Power Apps Canvas App...   The app will have a basic form where users will be able to create a new record. For example, a user will enter the Reporting Date (date picker), Fac Name (drop down) and Admits (free text). The Fac ID, Area and Region fields will auto-populate (Lookup formula referencing a SharePoint facility list) based on the data entered in Fac Name. 

 

Form (Insert Record):

Reporting Date8/29/2023
Fac NameChicago
Admits5
Fac ID150
AreaSmith
RegionWilson

 

From lowest level management to highest, each facility has a Program Director (info not stored in SharePoint list below), Area Director and Regional Director.  Typically a Program Director will only be responsible for one facility, but in same cases may oversee two or three. The Area Director will cover a small group of sites and the Regional Director will cover a larger group of sites.  

 

SharePoint Facility List:

FacilityAreaRegion
150SmithWilson
151SmithWilson
152SmithWilson
153JonesWilson
154JonesWilson
155JonesWilson
156BrownMiller
157BrownMiller
158BrownMiller
159DavisMiller
160DavisMiller
161DavisMiller

 

Beyond creating a new record, I want users to be able to only read/edit records that were created for a facility where they have responsibilities.  For example, the Program Director garcia@example.com should only have access to facilities 151 and 152. The Area Director smith@example.com should only have access to facilities 150, 151 and 152.  The Regional Director wilson@example.com should only have access to facilities 150, 151, 152, 153, 154, and 155.  My initial thought is to create a SharePoint user list, like the example below. 

 

From there I am a little lost... I assume I will need to somehow filter a gallery/data table based on the current users 'User().Email' as it relates to the SharePoint user list?  I'm a novice a SharePoint and don't really know where to start here... 

 

SharePoint User List

FacilityUser Email
150moore@example.com
151garcia@example.com
152garcia@example.com
153robinson@example.com
154allen@example.com
155harris@example.com
156taylor@example.com
157johnson@example.com
158lewis@example.com
159perez@example.com
160clark@example.com
161clark@example.com
150smith@example.com
151smith@example.com
152smith@example.com
153jones@example.com
154jones@example.com
155jones@example.com
156brown@example.com
157brown@example.com
158brown@example.com
159davis@example.com
160davis@example.com
161davis@example.com
150wilson@example.com
151wilson@example.com
152wilson@example.com
153wilson@example.com
154wilson@example.com
155wilson@example.com
156miller@example.com
157miller@example.com
158miller@example.com
159miller@example.com
160miller@example.com
161miller@example.com

 

 

Other thoughts.  Would there be a simpler way to store the Area and Region emails in the SharePoint user list since Area and Region are fields that are recorded on the form?  Maybe some sort of 'triple filter' that filters first by matching on Fac ID, then on Area, then on Region? 

 

This is all just filtering on the front end within Power Apps...  Which I am guessing is not super secure as anyone with access could get to all the data in SharePoint.  Is there a better way to do this?  Anything I saw on Google appeared to get pretty complicated within Power Automate and didn't really match my use case.  

 

Any help here would be much appreciated!  

1 ACCEPTED SOLUTION

Accepted Solutions

I ended up going a slightly different direction.  Instead of trying to filter a gallery/data table by the user's permission's all at once - I decided to add all the allowed facilities in a collection and add to a dropdown.  The gallery/data table can then be filtered by the facility dropdown.  Not exactly how I wanted it, but I think this approach will be a little cleaner than Reza's hack in the YouTube video. 

 

So I have a 3 column list setup in SP (called sp_users) with column headers email, type and permission. 

 

I created 5 collections based on the 5 types of users groups there are possible (Admin, Facility, Area, Region & LOB), filtering by current user email.  

 

The permission column will either have the Facility ID in it or the Area, Region or LOB name - or it will say Admin if the user should have global access.

 

I check the first collection (UserCollectionAdmin) if the user is an Admin (FacilityCollection is an existing collection that list all of our facilities). If so they get all active HRS facilities, otherwise the remaining 4 collections are checked and combined.   So it is possible for someone to have a combination of Facility, Area, Region & LOB permissions in the PermissionCollection.

 

Finally I add a concatenated column and end up with my final ListCollection that my dropdown uses.  

 

ClearCollect(UserCollectionAdmin, Filter(sp_users, type = "Admin", email = Lower(User().Email)));
ClearCollect(UserCollectionFacility, Filter(sp_users, type = "Facility", email = Lower(User().Email)));
ClearCollect(UserCollectionArea, Filter(sp_users, type = "Area", email = Lower(User().Email)));
ClearCollect(UserCollectionRegion, Filter(sp_users, type = "Region", email = Lower(User().Email)));
ClearCollect(UserCollectionLOB, Filter(sp_users, type = "LOB", email = Lower(User().Email)));


If(LookUp(UserCollectionAdmin,"Admin" in permission,true),ClearCollect(PermissionCollection, Filter(FacilityCollection, status = "ACTIVE", lob = "HRS")),

Concurrent(
            ClearCollect(col6, Filter(FacilityCollection, status = "ACTIVE", lob = "HRS", facility_id in ShowColumns(UserCollectionFacility,"permission"))),
            ClearCollect(col7, Filter(FacilityCollection, status = "ACTIVE", lob = "HRS", area in ShowColumns(UserCollectionArea,"permission"))),
            ClearCollect(col8, Filter(FacilityCollection, status = "ACTIVE", lob = "HRS", region in ShowColumns(UserCollectionRegion,"permission"))),
            ClearCollect(col9, Filter(FacilityCollection, status = "ACTIVE", lob = "HRS", lob in ShowColumns(UserCollectionLOB,"permission")))
);
ClearCollect(PermissionCollection, col6, col7, col8, col9);

Clear(col6);
Clear(col7);
Clear(col8);
Clear(col9);

);

ClearCollect(ListCollection, AddColumns(PermissionCollection,"name_id",location&" - "&facility_id))

 

 

Added distinct and sort to have a alphabetized list of facilities with the name and ID of the facility.  

Sort(Distinct(ListCollection, name_id),Value,SortOrder.Ascending)

 

 

May not be the most elegant solution, but it seems to work for me. 

 

 

View solution in original post

7 REPLIES 7
EddieE
Super User
Super User

@nicktalsma 

Row Level security in SharePoint really isn't a thing. If you want that you need to look at something like DataVerse but that also comes with extra licensing costs.

 

This @RezaDorrani video walks through Item Level permissions in SharePoint and may have some ideas for you?

https://www.youtube.com/watch?v=EJyZfYMi4n0

 

I think the basic takeaway is that Filtering in PowerApps won't stop users from getting full access to your SP data, so you need to think outside the box if you want to setup something like this in an app.


If my response solves your question, please accept as a solution.
Thank you!

Understood about SharePoint data not being protected.  

I’d still be curious about how to go about filtering this within Power Apps so that folks are only looking at the data that matters to them. 


Thank you!

 

@nicktalsma 

Ok then, I think you have picked a tricky app / data problem here. Basically, you need to use a function like 'in' to filter your data by person / email but you will run into delegation issues using 'in'.

 

One way I see that you may be able to tackle this is by setting up the 'SharePoint User List' with a Choice column for Facility rather than having a record per Facility & User Email, it would look like

 

User Email                          FacilityAccess
moore@example.com       150
garcia@example.com        151, 152
robinson@example.com   153
allen@example.com          154

brown@example.com       156, 157, 158
davis@example.com         159, 160, 161

This would also be much easier to manage when adding / removing access to facilities.

 

Then, in the App OnStart you could add something like this

Set(
    vFacilityAccess,
    Concat(
        First( Filter( UserList, UserEmail = Lower(User().Email))).FacilityAccess,
        Value,
        ", "
    )
)

 

This creates a Text string called vFacilityAccess that holds the facilities the User has access to, which you can reference in a gallery filter to only show facilities that the User has access to. To do that, you can follow @RezaDorrani 's video here where he talks about showing and hiding data - without delegation warnings - and using a Flexible Height gallery to do this.

 

https://www.youtube.com/watch?v=44j2VRbdWjk

 

Instead of using the ComboBox demo'd by Reza to help filter, you'd use the text string created above, if that makes sense?


If my response solves your question, please accept as a solution.
Thank you!
nicktalsma
Frequent Visitor

This sounds like a great solution!  I much prefer the use of the choice column over the many rows in my original post. 

 

To simply managing these lists further, I think I will want to create 4 SharePoint User Lists.  

  1. Facility based list as you demonstrated above
  2. Area based list that has Area Director Emails and the Area they are assigned to.  This can reference the Area field from the form.  Prevents me from having to type out each site for each user and keeping up to date as sites come online/offline.
  3. Region based list that has Region Director Emails and the Region they are assigned to.  This can reference the Region field from the form.  Prevents me from having to type out each site for each user and keeping up to date as sites come online/offline.
  4. Admin/Executive based list.  This would only need a single column of emails as these folks would have global access. Prevents me from having to type out each site for each user and keeping up to date as sites come online/offline.

As Area Director, Region Director and Executive turnover is infrequent. I think this will leave me with just managing the facility based list day-today. 

 

Then I guess would just need a filter in the gallery / data table that looks at those 4 lists using IF OR?  

 

I should have some time to play with this next week.  Thanks for your help @EddieE 

I ended up going a slightly different direction.  Instead of trying to filter a gallery/data table by the user's permission's all at once - I decided to add all the allowed facilities in a collection and add to a dropdown.  The gallery/data table can then be filtered by the facility dropdown.  Not exactly how I wanted it, but I think this approach will be a little cleaner than Reza's hack in the YouTube video. 

 

So I have a 3 column list setup in SP (called sp_users) with column headers email, type and permission. 

 

I created 5 collections based on the 5 types of users groups there are possible (Admin, Facility, Area, Region & LOB), filtering by current user email.  

 

The permission column will either have the Facility ID in it or the Area, Region or LOB name - or it will say Admin if the user should have global access.

 

I check the first collection (UserCollectionAdmin) if the user is an Admin (FacilityCollection is an existing collection that list all of our facilities). If so they get all active HRS facilities, otherwise the remaining 4 collections are checked and combined.   So it is possible for someone to have a combination of Facility, Area, Region & LOB permissions in the PermissionCollection.

 

Finally I add a concatenated column and end up with my final ListCollection that my dropdown uses.  

 

ClearCollect(UserCollectionAdmin, Filter(sp_users, type = "Admin", email = Lower(User().Email)));
ClearCollect(UserCollectionFacility, Filter(sp_users, type = "Facility", email = Lower(User().Email)));
ClearCollect(UserCollectionArea, Filter(sp_users, type = "Area", email = Lower(User().Email)));
ClearCollect(UserCollectionRegion, Filter(sp_users, type = "Region", email = Lower(User().Email)));
ClearCollect(UserCollectionLOB, Filter(sp_users, type = "LOB", email = Lower(User().Email)));


If(LookUp(UserCollectionAdmin,"Admin" in permission,true),ClearCollect(PermissionCollection, Filter(FacilityCollection, status = "ACTIVE", lob = "HRS")),

Concurrent(
            ClearCollect(col6, Filter(FacilityCollection, status = "ACTIVE", lob = "HRS", facility_id in ShowColumns(UserCollectionFacility,"permission"))),
            ClearCollect(col7, Filter(FacilityCollection, status = "ACTIVE", lob = "HRS", area in ShowColumns(UserCollectionArea,"permission"))),
            ClearCollect(col8, Filter(FacilityCollection, status = "ACTIVE", lob = "HRS", region in ShowColumns(UserCollectionRegion,"permission"))),
            ClearCollect(col9, Filter(FacilityCollection, status = "ACTIVE", lob = "HRS", lob in ShowColumns(UserCollectionLOB,"permission")))
);
ClearCollect(PermissionCollection, col6, col7, col8, col9);

Clear(col6);
Clear(col7);
Clear(col8);
Clear(col9);

);

ClearCollect(ListCollection, AddColumns(PermissionCollection,"name_id",location&" - "&facility_id))

 

 

Added distinct and sort to have a alphabetized list of facilities with the name and ID of the facility.  

Sort(Distinct(ListCollection, name_id),Value,SortOrder.Ascending)

 

 

May not be the most elegant solution, but it seems to work for me. 

 

 

@nicktalsma 

Sounds like you've got it sorted how you want/need it so well done mate!


If my response solves your question, please accept as a solution.
Thank you!

I wonder how PowerApps could ever scale without this being available? Is this a 'upsell measure in disguise' by MIcrosoft so that they purchase more DataVerse licenses or what?

 

Quite honestly, this makes the approach of PowerApps and ShP basically unusable / un-maintainable if you have more than 50 users.

 

Is there really no other solution to this problem?

Helpful resources

Announcements

Community will be READ ONLY July 16th, 5p PDT -July 22nd

Dear Community Members,   We'd like to let you know of an upcoming change to the community platform: starting July 16th, the platform will transition to a READ ONLY mode until July 22nd.   During this period, members will not be able to Kudo, Comment, or Reply to any posts.   On July 22nd, please be on the lookout for a message sent to the email address registered on your community profile. This email is crucial as it will contain your unique code and link to register for the new platform encompassing all of the communities.   What to Expect in the New Community: A more unified experience where all products, including Power Apps, Power Automate, Copilot Studio, and Power Pages, will be accessible from one community.Community Blogs that you can syndicate and link to for automatic updates. We appreciate your understanding and cooperation during this transition. Stay tuned for the exciting new features and a seamless community experience ahead!

Summer of Solutions | Week 4 Results | Winners will be posted on July 24th

We are excited to announce the Summer of Solutions Challenge!   This challenge is kicking off on Monday, June 17th and will run for (4) weeks.  The challenge is open to all Power Platform (Power Apps, Power Automate, Copilot Studio & Power Pages) community members. We invite you to participate in a quest to provide solutions in the Forums to as many questions as you can. Answers can be provided in all the communities.    Entry Period: This Challenge will consist of four weekly Entry Periods as follows (each an “Entry Period”)   - 12:00 a.m. PT on June 17, 2024 – 11:59 p.m. PT on June 23, 2024 - 12:00 a.m. PT on June 24, 2024 – 11:59 p.m. PT on June 30, 2024 - 12:00 a.m. PT on July 1, 2024 – 11:59 p.m. PT on July 7, 2024 - 12:00 a.m. PT on July 8, 2024 – 11:59 p.m. PT on July 14, 2024   Entries will be eligible for the Entry Period in which they are received and will not carryover to subsequent weekly entry periods.  You must enter into each weekly Entry Period separately.   How to Enter: We invite you to participate in a quest to provide "Accepted Solutions" to as many questions as you can. Answers can be provided in all the communities. Users must provide a solution which can be an “Accepted Solution” in the Forums in all of the communities and there are no limits to the number of “Accepted Solutions” that a member can provide for entries in this challenge, but each entry must be substantially unique and different.    Winner Selection and Prizes: At the end of each week, we will list the top ten (10) Community users which will consist of: 5 Community Members & 5 Super Users and they will advance to the final drawing. We will post each week in the News & Announcements the top 10 Solution providers.  At the end of the challenge, we will add all of the top 10 weekly names and enter them into a random drawing.  Then we will randomly select ten (10) winners (5 Community Members & 5 Super Users) from among all eligible entrants received across all weekly Entry Periods to receive the prize listed below. If a winner declines, we will draw again at random for the next winner.  A user will only be able to win once overall. If they are drawn multiple times, another user will be drawn at random.  Individuals will be contacted before the announcement with the opportunity to claim or deny the prize.  Once all of the winners have been notified, we will post in the News & Announcements of each community with the list of winners.   Each winner will receive one (1) Pass to the Power Platform Conference in Las Vegas, Sep. 18-20, 2024 ($1800 value). NOTE: Prize is for conference attendance only and any other costs such as airfare, lodging, transportation, and food are the sole responsibility of the winner. Tickets are not transferable to any other party or to next year’s event.   ** PLEASE SEE THE ATTACHED RULES for this CHALLENGE**   Week 1 Results: Congratulations to the Week 1 qualifiers, you are being entered in the random drawing that will take place at the end of the challenge. Community MembersNumber of SolutionsSuper UsersNumber of Solutions @anandm08  23 @WarrenBelz  31 @DBO_DV  10 @Amik  19 AmínAA 6 @mmbr1606  12 @rzuber  4 @happyume  7 @Giraldoj  3@ANB 6 (tie)   @SpongYe  6 (tie)     Week 2 Results: Congratulations to the Week 2 qualifiers, you are being entered in the random drawing that will take place at the end of the challenge. Community MembersSolutionsSuper UsersSolutions @anandm08  10@WarrenBelz 25 @DBO_DV  6@mmbr1606 14 @AmínAA 4 @Amik  12 @royg  3 @ANB  10 @AllanDeCastro  2 @SunilPashikanti  5 @Michaelfp  2 @FLMike  5 @eduardo_izzo  2   Meekou 2   @rzuber  2   @Velegandla  2     @PowerPlatform-P  2   @Micaiah  2     Week 3 Results: Congratulations to the Week 3 qualifiers, you are being entered in the random drawing that will take place at the end of the challenge.   Week 3:Community MembersSolutionsSuper UsersSolutionsPower Apps anandm0861WarrenBelz86DBO_DV25Amik66Michaelfp13mmbr160647Giraldoj13FLMike31AmínAA13SpongYe27     Week 4 Results: Congratulations to the Week 4 qualifiers, you are being entered in the random drawing that will take place at the end of the challenge.   Week 4:Community MembersSolutionsSuper UsersSolutionsPower Apps DBO-DV21WarranBelz26Giraldoj7mmbr160618Muzammmil_0695067Amik14samfawzi_acml6FLMike12tzuber6ANB8   SunilPashikanti8

Check Out | 2024 Release Wave 2 Plans for Microsoft Dynamics 365 and Microsoft Power Platform

On July 16, 2024, we published the 2024 release wave 2 plans for Microsoft Dynamics 365 and Microsoft Power Platform. These plans are a compilation of the new capabilities planned to be released between October 2024 to March 2025. This release introduces a wealth of new features designed to enhance customer understanding and improve overall user experience, showcasing our dedication to driving digital transformation for our customers and partners.    The upcoming wave is centered around utilizing advanced AI and Microsoft Copilot technologies to enhance user productivity and streamline operations across diverse business applications. These enhancements include intelligent automation, AI-powered insights, and immersive user experiences that are designed to break down barriers between data, insights, and individuals. Watch a summary of the release highlights.    Discover the latest features that empower organizations to operate more efficiently and adaptively. From AI-driven sales insights and customer service enhancements to predictive analytics in supply chain management and autonomous financial processes, the new capabilities enable businesses to proactively address challenges and capitalize on opportunities.    

Updates to Transitions in the Power Platform Communities

We're embarking on a journey to enhance your experience by transitioning to a new community platform. Our team has been diligently working to create a fresh community site, leveraging the very Dynamics 365 and Power Platform tools our community advocates for.  We started this journey with transitioning Copilot Studio forums and blogs in June. The move marks the beginning of a new chapter, and we're eager for you to be a part of it. The rest of the Power Platform product sites will be moving over this summer.   Stay tuned for more updates as we get closer to the launch. We can't wait to welcome you to our new community space, designed with you in mind. Let's connect, learn, and grow together.   Here's to new beginnings and endless possibilities!   If you have any questions, observations or concerns throughout this process please go to https://aka.ms/PPCommSupport.   To stay up to date on the latest details of this migration and other important Community updates subscribe to our News and Announcements forums: Copilot Studio, Power Apps, Power Automate, Power Pages

Users online (853)