感觉跟之前版本区别不是很大,先记录下。
1. 首先在sitemap.config 文件里添加菜单。
<siteMapNode SystemName="SystemManage" nopResource="系统管理" PermissionNames="per_sys_role,per_sys_permission,per_sys_user" IconClass="fa-line-chart"> <siteMapNode SystemName="sys_role" nopResource="角色管理" PermissionNames="per_sys_role" controller="SystemManage" action="Role" IconClass="fa-dot-circle-o"/> <siteMapNode SystemName="sys_permission" nopResource="权限管理" PermissionNames="per_sys_permission" controller="SystemManage" action="Permission" IconClass="fa-dot-circle-o"/> <siteMapNode SystemName="sys_user" nopResource="用户管理" PermissionNames="per_sys_user" controller="SystemManage" action="User" IconClass="fa-dot-circle-o"/> </siteMapNode>
2. 然后在数据库PermissionRecord表里添加该菜单。
3. 还需要在 Nop.Services.Security.StandardPermissionProvider.cs 文件里添加权限记录
public static readonly PermissionRecord per_sys_role = new PermissionRecord { Name = "Admin area. Manage system", SystemName = "per_sys_role", Category = "SystemManage" }; public static readonly PermissionRecord per_sys_permission = new PermissionRecord { Name = "Admin area. Manage system", SystemName = "per_sys_permission", Category = "SystemManage" }; public static readonly PermissionRecord per_sys_user = new PermissionRecord { Name = "Admin area. Manage system", SystemName = "per_sys_user", Category = "SystemManage" };
public virtual IEnumerable<PermissionRecord> GetPermissions() { return new[] { AccessAdminPanel, AllowCustomerImpersonation, ManageProducts, ManageCategories, ManageManufacturers, ManageProductReviews, ManageProductTags, ManageAttributes, ManageCustomers, ManageVendors, ManageCurrentCarts, ManageOrders, ManageRecurringPayments, ManageGiftCards, ManageReturnRequests, OrderCountryReport, ManageAffiliates, ManageCampaigns, ManageDiscounts, ManageNewsletterSubscribers, ManagePolls, ManageNews, ManageBlog, ManageWidgets, ManageTopics, ManageForums, ManageMessageTemplates, ManageCountries, ManageLanguages, ManageSettings, ManagePaymentMethods, ManageExternalAuthenticationMethods, ManageTaxSettings, ManageShippingSettings, ManageCurrencies, ManageActivityLog, ManageAcl, ManageEmailAccounts, ManageStores, ManagePlugins, ManageSystemLog, ManageMessageQueue, ManageMaintenance, HtmlEditorManagePictures, ManageScheduleTasks, DisplayPrices, EnableShoppingCart, EnableWishlist, PublicStoreAllowNavigation, AccessClosedStore, per_sys_role, per_sys_permission, per_sys_user }; }
/// <summary> /// Get default permissions /// </summary> /// <returns>Permissions</returns> public virtual HashSet<(string systemRoleName, PermissionRecord[] permissions)> GetDefaultPermissions() { return new HashSet<(string, PermissionRecord[])> { ( NopCustomerDefaults.AdministratorsRoleName, new[] { AccessAdminPanel, AllowCustomerImpersonation, ManageProducts, ManageCategories, ManageManufacturers, ManageProductReviews, ManageProductTags, ManageAttributes, ManageCustomers, ManageVendors, ManageCurrentCarts, ManageOrders, ManageRecurringPayments, ManageGiftCards, ManageReturnRequests, OrderCountryReport, ManageAffiliates, ManageCampaigns, ManageDiscounts, ManageNewsletterSubscribers, ManagePolls, ManageNews, ManageBlog, ManageWidgets, ManageTopics, ManageForums, ManageMessageTemplates, ManageCountries, ManageLanguages, ManageSettings, ManagePaymentMethods, ManageExternalAuthenticationMethods, ManageTaxSettings, ManageShippingSettings, ManageCurrencies, ManageActivityLog, ManageAcl, ManageEmailAccounts, ManageStores, ManagePlugins, ManageSystemLog, ManageMessageQueue, ManageMaintenance, HtmlEditorManagePictures, ManageScheduleTasks, DisplayPrices, EnableShoppingCart, EnableWishlist, PublicStoreAllowNavigation, AccessClosedStore, per_sys_role, per_sys_permission, per_sys_user } ), ( NopCustomerDefaults.ForumModeratorsRoleName, new[] { DisplayPrices, EnableShoppingCart, EnableWishlist, PublicStoreAllowNavigation } ), ( NopCustomerDefaults.GuestsRoleName, new[] { DisplayPrices, EnableShoppingCart, EnableWishlist, PublicStoreAllowNavigation } ), ( NopCustomerDefaults.RegisteredRoleName, new[] { DisplayPrices, EnableShoppingCart, EnableWishlist, PublicStoreAllowNavigation } ), ( NopCustomerDefaults.VendorsRoleName, new[] { AccessAdminPanel, ManageProducts, ManageProductReviews, ManageOrders } ) }; }
4. 配置角色和权限记录表的关系,可在admin界面里操作。