cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
MSFTPowerNoob
Regular Visitor

Redirect users to different pages based on their O365 group membership

Hi PowerApps Community,

 

My first post here! I have a PowerApp, part which I want to share with my Team (Admins) and part of it with the rest of the users (non-Admins). The Admins are all a part of an O365 group (Teams Team, actually!). I have a full flow of different pages that appear in sequence when you enter the Admins section. When a non-Admin enters this section, they see blank pages because I've restricted their access to these pages through different SharePoint lists.

 

Now in this app, I want to make it so that when an admin (logging into the app) clicks on the button, they should be redirected to the first of the series of pages mentioned before and a non-admin should be redirected to a page that says "Access Denied!"

 

In my scenario, I'm using the following terms so that it would be easy for anyone posting the solution and more importantly, easy for me to understand!

Scenario 1: Admin_User logs in and clicks on the button for the Admin Section. If this user is in the AdminUserGroup (which they should be), they're redirected (Navigate) to the first page of the Admin Section.

Scenario 2: Non-Admin_User logs in and clicks on the button for the Admin Section. This user is not part of the AdminUserGroup and hence needs to be Navigated to a page that says "Access Denied!" (All the necessary pages have been created and O365 Groups connector has been added as a data source)

 

I know this is a simple scenario with a possibly simple "If" statement as solution, but I tried a few posted in this community but got the error that an Operator was expected, but I had no clue where! I used the below expression: If(IsBlank(Filter(Office365Groups.ListGroupMembers("GROUP ID").value,mail=User().Email)), Navigate('first page'), Navigate('Access Denied');

 

Hope to hear from someone soon, thanks!

1 ACCEPTED SOLUTION

Accepted Solutions

OnVisible of the first screen of the app:

 

//untested formula, modify as needed for your scenario
Set
(
    myVarUserName
   ,User().FullName
);
With
(
    {
       myVarAdminID: LookUp
                     (
                        Office365Groups.ListOwnedGroups().value
                        ,displayName = "AdminUserGroup"
                     ).id
    }
   ,Set(
       myVarAdmin
      ,myVarUserName in Office365Groups.ListGroupMembers(myVarAdminID).value.displayName
   )
);

 

Optionally, for the above, you can replace

 

displayName = "AdminUserGroup"

 

with 

 

id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"

 

if you want to use an id instead of a display name

Changing the display name of the group might break it in the future if you don't explicitly go back in the formula and change it, that's why.

 

I guess if you are so sure of the id, you could maybe just use it instead of even doing the LookUp in that case.

 

//untested formula, modify as needed for your scenario
Set
(
    myVarUserName
   ,User().FullName
);
With
(
    {
       myVarAdminID:"xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
    }
   ,Set
    (
        myVarAdmin
       ,myVarUserName in Office365Groups.ListGroupMembers(myVarAdminID).value.displayName
    )
);

 

 

If you need to use e-mail of the user rather than the display name, then use this formula instead:

 

//untested formula, modify as needed for your scenario
Set
(
    myVarEmail
   ,User().Email
);
With
(
    {
       myVarAdminID: LookUp
                     (
                        Office365Groups.ListOwnedGroups().value
                        ,displayName = "AdminUserGroup"
                     ).id
    }
   ,Set(
       myVarAdmin
      ,myVarEmail in Office365Groups.ListGroupMembers(myVarAdminID).value.mail
   )
);

 

 

or

 

//untested formula, modify as needed for your scenario
Set
(
    myVarEmail
   ,User().Email
);
With
(
    {
       myVarAdminID:"xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
    }
   ,Set(
       myVarAdmin
      ,myVarEmail in Office365Groups.ListGroupMembers(myVarAdminID).value.mail
   )
);

 

and then,

 

OnSelect of Admin Section Button:

 

//untested formula, modify as needed for your scenario
Navigate(If(myVarAdmin,AdminScreen,AccessDeniedScreen))

 

 Does it work @MSFTPowerNoob ?

View solution in original post

2 REPLIES 2

OnVisible of the first screen of the app:

 

//untested formula, modify as needed for your scenario
Set
(
    myVarUserName
   ,User().FullName
);
With
(
    {
       myVarAdminID: LookUp
                     (
                        Office365Groups.ListOwnedGroups().value
                        ,displayName = "AdminUserGroup"
                     ).id
    }
   ,Set(
       myVarAdmin
      ,myVarUserName in Office365Groups.ListGroupMembers(myVarAdminID).value.displayName
   )
);

 

Optionally, for the above, you can replace

 

displayName = "AdminUserGroup"

 

with 

 

id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"

 

if you want to use an id instead of a display name

Changing the display name of the group might break it in the future if you don't explicitly go back in the formula and change it, that's why.

 

I guess if you are so sure of the id, you could maybe just use it instead of even doing the LookUp in that case.

 

//untested formula, modify as needed for your scenario
Set
(
    myVarUserName
   ,User().FullName
);
With
(
    {
       myVarAdminID:"xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
    }
   ,Set
    (
        myVarAdmin
       ,myVarUserName in Office365Groups.ListGroupMembers(myVarAdminID).value.displayName
    )
);

 

 

If you need to use e-mail of the user rather than the display name, then use this formula instead:

 

//untested formula, modify as needed for your scenario
Set
(
    myVarEmail
   ,User().Email
);
With
(
    {
       myVarAdminID: LookUp
                     (
                        Office365Groups.ListOwnedGroups().value
                        ,displayName = "AdminUserGroup"
                     ).id
    }
   ,Set(
       myVarAdmin
      ,myVarEmail in Office365Groups.ListGroupMembers(myVarAdminID).value.mail
   )
);

 

 

or

 

//untested formula, modify as needed for your scenario
Set
(
    myVarEmail
   ,User().Email
);
With
(
    {
       myVarAdminID:"xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
    }
   ,Set(
       myVarAdmin
      ,myVarEmail in Office365Groups.ListGroupMembers(myVarAdminID).value.mail
   )
);

 

and then,

 

OnSelect of Admin Section Button:

 

//untested formula, modify as needed for your scenario
Navigate(If(myVarAdmin,AdminScreen,AccessDeniedScreen))

 

 Does it work @MSFTPowerNoob ?

Thank you so much, @poweractivate! That does it and that was so quick from you! Thank you for a wonderful solution.

Helpful resources

Announcements
Power Apps News & Annoucements carousel

Power Apps News & Announcements

Keep up to date with current events and community announcements in the Power Apps community.

Community Call Conversations

Introducing the Community Calls Conversations

A great place where you can stay up to date with community calls and interact with the speakers.

Power Apps Community Blog Carousel

Power Apps Community Blog

Check out the latest Community Blog from the community!

Top Solution Authors
Top Kudoed Authors
Users online (5,657)