From c5677b658ee4da726327e6bc881e9a0be6d82e7a Mon Sep 17 00:00:00 2001 From: maliming Date: Mon, 1 Mar 2021 15:13:11 +0800 Subject: [PATCH 1/4] Update Navigation-Menu and Toolbars. --- docs/en/UI/AspNetCore/Navigation-Menu.md | 24 ++++++++++++++++++++++-- docs/en/UI/AspNetCore/Toolbars.md | 13 +++++++++++++ 2 files changed, 35 insertions(+), 2 deletions(-) diff --git a/docs/en/UI/AspNetCore/Navigation-Menu.md b/docs/en/UI/AspNetCore/Navigation-Menu.md index 7a8fe31e3e..1ddc95da9e 100644 --- a/docs/en/UI/AspNetCore/Navigation-Menu.md +++ b/docs/en/UI/AspNetCore/Navigation-Menu.md @@ -104,14 +104,34 @@ There are more options of a menu item (the constructor of the `ApplicationMenuIt * `target` (`string`): Target of the menu item. Can be `null` (default), "\_*blank*", "\_*self*", "\_*parent*", "\_*top*" or a frame name for web applications. * `elementId` (`string`): Can be used to render the element with a specific HTML `id` attribute. * `cssClass` (`string`): Additional string classes for the menu item. +* `RequiredPermissionName` (`string`): The required permission name, this menu item will be removed if this permission is not granted. ### Authorization As seen above, a menu contributor contributes to the menu dynamically. So, you can perform any custom logic or get menu items from any source. -One use case is the [authorization](../../Authorization.md). You typically want to add menu items by checking a permission. +One use case is the [authorization](../../Authorization.md). -**Example: Check if the current user has a permission** +You can set the `RequiredPermissionName` property of the menu item. + +````csharp +context.Menu.AddItem( + new ApplicationMenuItem("MyProject.Crm", l["Menu:CRM"]) + .AddItem(new ApplicationMenuItem( + name: "MyProject.Crm.Customers", + displayName: l["Menu:Customers"], + url: "/crm/customers", + requiredPermissionName: "MyProject.Crm.Customers") + ).AddItem(new ApplicationMenuItem( + name: "MyProject.Crm.Orders", + displayName: l["Menu:Orders"], + url: "/crm/orders", + requiredPermissionName: "MyProject.Crm.Orders") + ) +); +```` + +You can also manually check permissions. ````csharp if (await context.IsGrantedAsync("MyPermissionName")) diff --git a/docs/en/UI/AspNetCore/Toolbars.md b/docs/en/UI/AspNetCore/Toolbars.md index 3f1185f61b..5da78afdac 100644 --- a/docs/en/UI/AspNetCore/Toolbars.md +++ b/docs/en/UI/AspNetCore/Toolbars.md @@ -52,6 +52,19 @@ public class MyToolbarContributor : IToolbarContributor } ```` +You can use the [authorization](../../Authorization.md) to decide whether to add a `ToolbarItem`. + +Use the `RequiredPermissionName` property of `ToolbarItem` or manually checking the permissions. + +````csharp +context.Toolbar.Items.Insert(0, new ToolbarItem(typeof(NotificationViewComponent), requiredPermissionName: "MyPermissionName")); + +if (await context.IsGrantedAsync("MyPermissionName")) +{ + //...add Toolbar items +} +```` + This class adds the `NotificationViewComponent` as the first item in the `Main` toolbar. Finally, you need to add this contributor to the `AbpToolbarOptions`, in the `ConfigureServices` of your [module](../../Module-Development-Basics.md): From abb12ef632f24caf60a4245eb20bf20d8a02ed14 Mon Sep 17 00:00:00 2001 From: maliming Date: Wed, 3 Mar 2021 11:04:57 +0800 Subject: [PATCH 2/4] Update Navigation-Menu.md --- docs/en/UI/AspNetCore/Navigation-Menu.md | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/docs/en/UI/AspNetCore/Navigation-Menu.md b/docs/en/UI/AspNetCore/Navigation-Menu.md index 1ddc95da9e..8480590f50 100644 --- a/docs/en/UI/AspNetCore/Navigation-Menu.md +++ b/docs/en/UI/AspNetCore/Navigation-Menu.md @@ -110,9 +110,18 @@ There are more options of a menu item (the constructor of the `ApplicationMenuIt As seen above, a menu contributor contributes to the menu dynamically. So, you can perform any custom logic or get menu items from any source. -One use case is the [authorization](../../Authorization.md). +One use case is the [authorization](../../Authorization.md). You typically want to add menu items by checking a permission. -You can set the `RequiredPermissionName` property of the menu item. +**Example: Check if the current user has a permission** + +````csharp +if (await context.IsGrantedAsync("MyPermissionName")) +{ + //...add menu items +} +```` + +For the authorization, you can use `RequiredPermissionName` as a shortcut. It is also more performant, ABP optimizes the permission check for all the items. ````csharp context.Menu.AddItem( @@ -131,15 +140,6 @@ context.Menu.AddItem( ); ```` -You can also manually check permissions. - -````csharp -if (await context.IsGrantedAsync("MyPermissionName")) -{ - //...add menu items -} -```` - > You can use `context.AuthorizationService` to directly access to the `IAuthorizationService`. ### Resolving Dependencies From 73dd6eb30d021cceaee7ff4087e142fe2120b8b1 Mon Sep 17 00:00:00 2001 From: maliming Date: Wed, 3 Mar 2021 11:09:14 +0800 Subject: [PATCH 3/4] Update Toolbars.md --- docs/en/UI/AspNetCore/Toolbars.md | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/docs/en/UI/AspNetCore/Toolbars.md b/docs/en/UI/AspNetCore/Toolbars.md index 5da78afdac..189d0d9c6e 100644 --- a/docs/en/UI/AspNetCore/Toolbars.md +++ b/docs/en/UI/AspNetCore/Toolbars.md @@ -54,16 +54,17 @@ public class MyToolbarContributor : IToolbarContributor You can use the [authorization](../../Authorization.md) to decide whether to add a `ToolbarItem`. -Use the `RequiredPermissionName` property of `ToolbarItem` or manually checking the permissions. - ````csharp -context.Toolbar.Items.Insert(0, new ToolbarItem(typeof(NotificationViewComponent), requiredPermissionName: "MyPermissionName")); - if (await context.IsGrantedAsync("MyPermissionName")) { //...add Toolbar items } ```` +You can use `RequiredPermissionName` as a shortcut. It is also more performant, ABP optimizes the permission check for all the items. + +````csharp +context.Toolbar.Items.Insert(0, new ToolbarItem(typeof(NotificationViewComponent), requiredPermissionName: "MyPermissionName")); +```` This class adds the `NotificationViewComponent` as the first item in the `Main` toolbar. @@ -84,4 +85,4 @@ That's all, you will see the notification icon on the toolbar when you run the a ## IToolbarManager -`IToolbarManager` is used to render the toolbar. It returns the toolbar items by a toolbar name. This is generally used by the [themes](Theming.md) to render the toolbar on the layout. \ No newline at end of file +`IToolbarManager` is used to render the toolbar. It returns the toolbar items by a toolbar name. This is generally used by the [themes](Theming.md) to render the toolbar on the layout. From 4676079245c11bc968af598ad8c538e6c1ebc220 Mon Sep 17 00:00:00 2001 From: maliming Date: Wed, 3 Mar 2021 11:19:53 +0800 Subject: [PATCH 4/4] Update Toolbars.md --- docs/en/UI/AspNetCore/Toolbars.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/en/UI/AspNetCore/Toolbars.md b/docs/en/UI/AspNetCore/Toolbars.md index 189d0d9c6e..66ec7519b8 100644 --- a/docs/en/UI/AspNetCore/Toolbars.md +++ b/docs/en/UI/AspNetCore/Toolbars.md @@ -60,6 +60,7 @@ if (await context.IsGrantedAsync("MyPermissionName")) //...add Toolbar items } ```` + You can use `RequiredPermissionName` as a shortcut. It is also more performant, ABP optimizes the permission check for all the items. ````csharp