From fb40cfff108430056167e9b834e7c59a3d93add7 Mon Sep 17 00:00:00 2001 From: Argo Zhang Date: Thu, 19 Mar 2020 14:14:06 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20Client=20=E6=BC=94=E7=A4=BA=E5=B7=A5?= =?UTF-8?q?=E7=A8=8B=E6=97=A0=E6=B3=95=E6=89=93=E5=BC=80=20Home/Dummy=20?= =?UTF-8?q?=E8=A7=86=E5=9B=BE=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Helper/MenuHelper.cs | 9 +++++++++ src/client/Bootstrap.Client.DataAccess/Menu.cs | 13 +++++++++++++ src/client/Bootstrap.Client/Startup.cs | 1 + 3 files changed, 23 insertions(+) diff --git a/src/client/Bootstrap.Client.DataAccess/Helper/MenuHelper.cs b/src/client/Bootstrap.Client.DataAccess/Helper/MenuHelper.cs index afcee38c..5f917db0 100644 --- a/src/client/Bootstrap.Client.DataAccess/Helper/MenuHelper.cs +++ b/src/client/Bootstrap.Client.DataAccess/Helper/MenuHelper.cs @@ -37,5 +37,14 @@ namespace Bootstrap.Client.DataAccess /// /// public static IEnumerable RetrieveAllMenus(string userName) => CacheManager.GetOrAdd($"{RetrieveMenusAll}-{userName}", key => DbContextManager.Create()?.RetrieveAllMenus(userName), RetrieveMenusAll) ?? new BootstrapMenu[0]; + + /// + /// 通过当前用户名与指定菜单路径获取此菜单下所有授权按钮集合 (userName, url, auths) => bool + /// + /// 当前操作用户名 + /// 资源按钮所属菜单 + /// 资源授权码 + /// + public static bool AuthorizateButtons(string userName, string url, string auths) => DbContextManager.Create()?.AuthorizateButtons(userName, url, auths) ?? false; } } diff --git a/src/client/Bootstrap.Client.DataAccess/Menu.cs b/src/client/Bootstrap.Client.DataAccess/Menu.cs index 4290212a..98a9ad63 100644 --- a/src/client/Bootstrap.Client.DataAccess/Menu.cs +++ b/src/client/Bootstrap.Client.DataAccess/Menu.cs @@ -15,5 +15,18 @@ namespace Bootstrap.Client.DataAccess /// 当前登录的用户名 /// public virtual IEnumerable RetrieveAllMenus(string userName) => DbHelper.RetrieveAllMenus(userName); + + /// + /// 通过当前用户名与指定菜单路径获取此菜单下所有授权按钮集合 (userName, url, auths) => bool + /// + /// 当前操作用户名 + /// 资源按钮所属菜单 + /// 资源授权码 + /// + public virtual bool AuthorizateButtons(string userName, string url, string auths) + { + var menus = MenuHelper.RetrieveAllMenus(userName); + return DbHelper.AuthorizateButtons(menus, url, auths); + } } } diff --git a/src/client/Bootstrap.Client/Startup.cs b/src/client/Bootstrap.Client/Startup.cs index 097eae0d..49009d26 100644 --- a/src/client/Bootstrap.Client/Startup.cs +++ b/src/client/Bootstrap.Client/Startup.cs @@ -49,6 +49,7 @@ namespace Bootstrap.Client services.AddOnlineUsers(); services.AddBootstrapAdminAuthentication(Configuration); services.AddAuthorization(options => options.DefaultPolicy = new AuthorizationPolicyBuilder().RequireBootstrapAdminAuthorizate().Build()); + services.AddButtonAuthorization(MenuHelper.AuthorizateButtons); services.AddControllersWithViews(options => {