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 => {