I have created a canvas app in the app I want some users to only view the data and some users to only edit the data .How to achieve the same.
Also I have one table created in dataverse which should only be editable by Super admins. How to do the setup for same.
@saritawavhal, Just to be clear, those roles and that security only applies to Dataverse tables. If the app is using any other data sources then those roles are meaningless.
To control access to data in a canvas app based on user roles and permissions, you can leverage Power Apps roles and Dataverse security roles.
Define User Roles in Canvas App: In Power Apps, you can define roles for your users. You might have roles like "Viewers" and "Editors." You can create these roles in the Power Platform admin center.
Use Security in Formulas: Utilize the roles in the formulas of your app controls. For example, you might have a button that triggers an edit action. In the OnSelect property of that button, you can use the User and Role functions to check the user's role and conditionally allow or block the action.
If(User().Roles["Editors"], Navigate(EditScreen, ScreenTransition.None), Notify("You don't have permission to edit.", NotificationType.Error))
This code checks if the user has the "Editors" role and navigates to the edit screen. If not, it shows an error notification.
Create Dataverse Security Roles: In the Dataverse, you can create security roles. For your scenario, create a "Super Admins" role.
Assign Roles to Users: Assign users to the appropriate roles in the Dataverse. Super admins should be assigned to the "Super Admins" security role.
Set Entity Permissions: Go to the Dataverse environment, select your table (entity), and set the entity permissions based on roles. In the entity settings, you can define who can read, write, create, or delete records.
For "Super Admins," give them full permissions. For other roles, restrict permissions as needed.
If my response helped resolving your issue, kindly click on "Accept as Solution." This helps others easily locate the solution and also marks the question as resolved. If you found the information beneficial for other reasons, please give it a Thumbs Up. Thank you!
Power apps doesn't provide a security layer. User's will have whatever access they normally have to the underlying data source in the app. So whether they can view or edit the data depends on what permissions they have in the data source. Different data sources do permissions differently. For Data verse permissions are assigned based on roles created for the tables.
Hi @oshinjain , You can create one table in data verse, let say User Details. This table will have column like Full Name, Email Address and Role. You define 3 roles. View , Edit and Admin
Add all users in this table with thier roles that you want. You can use Power Automate to upload data to this table.
Now on the App , OnStart property you can have this logic
Set(gblvar_CurrentUserRole, LookUp(TableName, FullName = User().FullName).Role)
This variable gives you the role. Now, on each controls displaymode property you can have below code:
If(gblvar_CurrentUserRole = "View", DisplayMode.Disabled, Or(gblvar_CurrentUserRole = "Edit",gblvar_CurrentUserRole = "Admin"),DisplayMode.Edit)
-----------------------------------------------------------------------------------------------------------------------------
I hope this helps.
Please click Accept as solution ✅ if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs up.👍
Thanks,
ANB
WarrenBelz
146,535
Most Valuable Professional
RandyHayes
76,287
Super User 2024 Season 1
Pstork1
65,908
Most Valuable Professional