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!
Solved! Go to Solution.
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 ?
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.
User | Count |
---|---|
259 | |
108 | |
93 | |
57 | |
40 |