From c5677b658ee4da726327e6bc881e9a0be6d82e7a Mon Sep 17 00:00:00 2001 From: maliming Date: Mon, 1 Mar 2021 15:13:11 +0800 Subject: [PATCH] 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):