Browse Source

新增用户个人信息、用户菜单列表、用户权限列表查询接口

zhontai 2 years ago
parent
commit
60350a77fd

+ 1 - 1
build/pkg.props

@@ -1,6 +1,6 @@
 <Project>
   <PropertyGroup>
-    <Version>3.3.6</Version>
+    <Version>3.3.7</Version>
 	<TargetFramework>net7.0</TargetFramework>
 	<GeneratePackageOnBuild>false</GeneratePackageOnBuild>
 	<GenerateDocumentationFile>true</GenerateDocumentationFile>

+ 1 - 1
src/hosts/ZhonTai.Host/Configs/appconfig.json

@@ -36,7 +36,7 @@
       {
         "name": "中台Admin",
         "code": "admin",
-        "version": "v3.3.6",
+        "version": "v3.3.7",
         "description": ""
       }
     ]

+ 5 - 2
src/platform/ZhonTai.Admin/Core/HostApp.cs

@@ -60,8 +60,11 @@ namespace ZhonTai.Admin.Core;
 /// <summary>
 /// 宿主应用
 /// </summary>
-public class HostApp
+public partial class HostApp
 {
+    [GeneratedRegex("[\\{\\\\\\/\\}]")]
+    private static partial Regex PathRegex();
+
     readonly HostAppOptions _hostAppOptions;
 
     public HostApp()
@@ -321,7 +324,7 @@ public class HostApp
                 {
                     var controllerAction = apiDesc.ActionDescriptor as ControllerActionDescriptor;
                     var api = controllerAction.AttributeRouteInfo.Template;
-                    api = Regex.Replace(api, @"[\{\\\/\}]", "-") + "-" + apiDesc.HttpMethod.ToLower();
+                    api = PathRegex().Replace(api, "-") + "-" + apiDesc.HttpMethod.ToLower();
                     return api.Replace("--", "-");
                 });
 

+ 122 - 0
src/platform/ZhonTai.Admin/Services/Auth/AuthService.cs

@@ -32,6 +32,7 @@ using ZhonTai.DynamicApi.Attributes;
 using FreeSql;
 using ZhonTai.Admin.Domain.TenantPermission;
 using Microsoft.AspNetCore.Identity;
+using System.Collections.Generic;
 
 namespace ZhonTai.Admin.Services.Auth;
 
@@ -109,6 +110,127 @@ public class AuthService : BaseService, IAuthService, IDynamicApi
         return new AuthGetPasswordEncryptKeyOutput { Key = guid, EncyptKey = encyptKey };
     }
 
+    /// <summary>
+    /// 查询用户个人信息
+    /// </summary>
+    /// <returns></returns>
+    [Login]
+    public async Task<AuthUserProfileDto> GetUserProfileAsync()
+    {
+        if (!(User?.Id > 0))
+        {
+            throw ResultOutput.Exception("未登录");
+        }
+
+        using (_userRepository.DataFilter.Disable(FilterNames.Self, FilterNames.Data))
+        {
+            var profile = await _userRepository.GetAsync<AuthUserProfileDto>(User.Id);
+
+            return profile;
+        }
+    }
+   
+    /// <summary>
+    /// 查询用户菜单列表
+    /// </summary>
+    /// <returns></returns>
+    [Login]
+    public async Task<List<AuthUserMenuDto>> GetUserMenusAsync()
+    {
+        if (!(User?.Id > 0))
+        {
+            throw ResultOutput.Exception("未登录");
+        }
+
+        using (_userRepository.DataFilter.Disable(FilterNames.Self, FilterNames.Data))
+        {
+            var menuSelect = _permissionRepository.Select;
+
+            if (!User.PlatformAdmin)
+            {
+                var db = _permissionRepository.Orm;
+                if (User.TenantAdmin)
+                {
+                    menuSelect = menuSelect.Where(a =>
+                       db.Select<TenantPermissionEntity>()
+                       .Where(b => b.PermissionId == a.Id && b.TenantId == User.TenantId)
+                       .Any()
+                   );
+                }
+                else
+                {
+                    menuSelect = menuSelect.Where(a =>
+                       db.Select<RolePermissionEntity>()
+                       .InnerJoin<UserRoleEntity>((b, c) => b.RoleId == c.RoleId && c.UserId == User.Id)
+                       .Where(b => b.PermissionId == a.Id)
+                       .Any()
+                   );
+                }
+
+                menuSelect = menuSelect.AsTreeCte(up: true);
+            }
+
+            var menuList = await menuSelect
+                .Where(a => new[] { PermissionType.Group, PermissionType.Menu }.Contains(a.Type))
+                .ToListAsync(a => new AuthUserMenuDto { ViewPath = a.View.Path });
+
+            return menuList.DistinctBy(a => a.Id).OrderBy(a => a.ParentId).ThenBy(a => a.Sort).ToList();
+
+        }
+    }
+
+    /// <summary>
+    /// 查询用户权限列表
+    /// </summary>
+    /// <returns></returns>
+    [Login]
+    public async Task<AuthGetUserPermissionsOutput> GetUserPermissionsAsync()
+    {
+        if (!(User?.Id > 0))
+        {
+            throw ResultOutput.Exception("未登录");
+        }
+
+        using (_userRepository.DataFilter.Disable(FilterNames.Self, FilterNames.Data))
+        {
+            var authGetUserPermissionsOutput = new AuthGetUserPermissionsOutput
+            {
+                //用户信息
+                User = await _userRepository.GetAsync<AuthUserProfileDto>(User.Id)
+            };
+
+            var dotSelect = _permissionRepository.Select.Where(a => a.Type == PermissionType.Dot);
+
+            if (!User.PlatformAdmin)
+            {
+                var db = _permissionRepository.Orm;
+                if (User.TenantAdmin)
+                {
+                    dotSelect = dotSelect.Where(a =>
+                       db.Select<TenantPermissionEntity>()
+                       .Where(b => b.PermissionId == a.Id && b.TenantId == User.TenantId)
+                       .Any()
+                    );
+                }
+                else
+                {
+                    dotSelect = dotSelect.Where(a =>
+                        db.Select<RolePermissionEntity>()
+                        .InnerJoin<UserRoleEntity>((b, c) => b.RoleId == c.RoleId && c.UserId == User.Id)
+                        .Where(b => b.PermissionId == a.Id)
+                        .Any()
+                    );
+                }
+            }
+
+            //用户权限点
+            authGetUserPermissionsOutput.Permissions = await dotSelect.ToListAsync(a => a.Code);
+
+            return authGetUserPermissionsOutput;
+        }
+    }
+
+
     /// <summary>
     /// 查询用户信息
     /// </summary>

+ 2 - 2
src/platform/ZhonTai.Admin/Services/Auth/Dto/AuthGetUserInfoOutput.cs

@@ -10,12 +10,12 @@ public class AuthGetUserInfoOutput
     public AuthUserProfileDto User { get; set; }
 
     /// <summary>
-    /// 用户菜单
+    /// 用户菜单列表
     /// </summary>
     public List<AuthUserMenuDto> Menus { get; set; }
 
     /// <summary>
-    /// 用户权限
+    /// 用户权限列表
     /// </summary>
     public List<string> Permissions { get; set; }
 }

+ 16 - 0
src/platform/ZhonTai.Admin/Services/Auth/Dto/AuthGetUserPermissionsOutput.cs

@@ -0,0 +1,16 @@
+using System.Collections.Generic;
+
+namespace ZhonTai.Admin.Services.Auth.Dto;
+
+public class AuthGetUserPermissionsOutput
+{
+    /// <summary>
+    /// 用户个人信息
+    /// </summary>
+    public AuthUserProfileDto User { get; set; }
+
+    /// <summary>
+    /// 用户权限列表
+    /// </summary>
+    public List<string> Permissions { get; set; }
+}

+ 3 - 0
src/platform/ZhonTai.Admin/Services/Auth/Dto/AuthUserProfileDto.cs

@@ -1,5 +1,8 @@
 namespace ZhonTai.Admin.Services.Auth.Dto;
 
+/// <summary>
+/// 用户个人信息
+/// </summary>
 public class AuthUserProfileDto
 {
     /// <summary>

+ 10 - 10
src/platform/ZhonTai.Admin/ZhonTai.Admin.csproj

@@ -16,9 +16,9 @@
 		<PackageReference Include="CSRedisCore" Version="3.8.670" />
 		<PackageReference Include="Caching.CSRedis" Version="3.8.670" />
 		<PackageReference Include="FluentValidation.AspNetCore" Version="11.2.2" />
-		<PackageReference Include="FreeSql" Version="3.2.689" />
+		<PackageReference Include="FreeSql" Version="3.2.690" />
 		<PackageReference Include="FreeSql.Cloud" Version="1.6.3" />
-		<PackageReference Include="FreeSql.Repository" Version="3.2.689" />
+		<PackageReference Include="FreeSql.Repository" Version="3.2.690" />
 		<PackageReference Include="FreeScheduler" Version="1.0.9" />
 		<PackageReference Include="IdentityServer4.AccessTokenValidation" Version="3.0.1" />
 		<PackageReference Include="Mapster" Version="7.3.0" />
@@ -28,8 +28,8 @@
 		<PackageReference Include="NLog" Version="5.1.2" />
 		<PackageReference Include="NLog.Web.AspNetCore" Version="5.2.2" />
 		<PackageReference Include="OnceMi.AspNetCore.OSS" Version="1.1.9" />
-		<PackageReference Include="SixLabors.ImageSharp" Version="2.1.3" />
-		<PackageReference Include="SixLabors.ImageSharp.Drawing" Version="1.0.0-beta14" />
+		<PackageReference Include="SixLabors.ImageSharp" Version="3.0.0" />
+		<PackageReference Include="SixLabors.ImageSharp.Drawing" Version="1.0.0-beta15" />
 		<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="6.27.0" />
 		<PackageReference Include="Swashbuckle.AspNetCore" Version="6.5.0" />
 		<PackageReference Include="UAParser" Version="3.1.47" />
@@ -37,12 +37,12 @@
 	</ItemGroup>
 
 	<ItemGroup Condition="'$(Configuration)'=='Debug'">
-		<PackageReference Include="FreeSql.Provider.MySql" Version="3.2.689" />
-		<PackageReference Include="FreeSql.Provider.SqlServer" Version="3.2.689" />
-		<PackageReference Include="FreeSql.Provider.PostgreSQL" Version="3.2.689" />
-		<PackageReference Include="FreeSql.Provider.Oracle" Version="3.2.689" />
-		<PackageReference Include="FreeSql.Provider.Sqlite" Version="3.2.689" />
-		<PackageReference Include="FreeSql.Provider.MySqlConnector" Version="3.2.689" />
+		<PackageReference Include="FreeSql.Provider.MySql" Version="3.2.690" />
+		<PackageReference Include="FreeSql.Provider.SqlServer" Version="3.2.690" />
+		<PackageReference Include="FreeSql.Provider.PostgreSQL" Version="3.2.690" />
+		<PackageReference Include="FreeSql.Provider.Oracle" Version="3.2.690" />
+		<PackageReference Include="FreeSql.Provider.Sqlite" Version="3.2.690" />
+		<PackageReference Include="FreeSql.Provider.MySqlConnector" Version="3.2.690" />
 	</ItemGroup>
 
 	<ItemGroup>

+ 79 - 2
src/platform/ZhonTai.Admin/ZhonTai.Admin.xml

@@ -1734,6 +1734,14 @@
             宿主应用
             </summary>
         </member>
+        <member name="M:ZhonTai.Admin.Core.HostApp.PathRegex">
+            <remarks>
+            Pattern explanation:<br/>
+            <code>
+            ○ Match a character in the set [/\\{}].<br/>
+            </code>
+            </remarks>
+        </member>
         <member name="M:ZhonTai.Admin.Core.HostApp.Run(System.String[])">
             <summary>
             运行应用
@@ -3650,6 +3658,24 @@
             </summary>
             <returns></returns>
         </member>
+        <member name="M:ZhonTai.Admin.Services.Auth.AuthService.GetUserProfileAsync">
+            <summary>
+            查询用户个人信息
+            </summary>
+            <returns></returns>
+        </member>
+        <member name="M:ZhonTai.Admin.Services.Auth.AuthService.GetUserMenusAsync">
+            <summary>
+            查询用户菜单列表
+            </summary>
+            <returns></returns>
+        </member>
+        <member name="M:ZhonTai.Admin.Services.Auth.AuthService.GetUserPermissionsAsync">
+            <summary>
+            查询用户权限列表
+            </summary>
+            <returns></returns>
+        </member>
         <member name="M:ZhonTai.Admin.Services.Auth.AuthService.GetUserInfoAsync">
             <summary>
             查询用户信息
@@ -3700,12 +3726,22 @@
         </member>
         <member name="P:ZhonTai.Admin.Services.Auth.Dto.AuthGetUserInfoOutput.Menus">
             <summary>
-            用户菜单
+            用户菜单列表
             </summary>
         </member>
         <member name="P:ZhonTai.Admin.Services.Auth.Dto.AuthGetUserInfoOutput.Permissions">
             <summary>
-            用户权限点
+            用户权限列表
+            </summary>
+        </member>
+        <member name="P:ZhonTai.Admin.Services.Auth.Dto.AuthGetUserPermissionsOutput.User">
+            <summary>
+            用户个人信息
+            </summary>
+        </member>
+        <member name="P:ZhonTai.Admin.Services.Auth.Dto.AuthGetUserPermissionsOutput.Permissions">
+            <summary>
+            用户权限列表
             </summary>
         </member>
         <member name="P:ZhonTai.Admin.Services.Auth.Dto.AuthGetVerifyCodeOutput.Key">
@@ -3868,6 +3904,11 @@
             排序
             </summary>
         </member>
+        <member name="T:ZhonTai.Admin.Services.Auth.Dto.AuthUserProfileDto">
+            <summary>
+            用户个人信息
+            </summary>
+        </member>
         <member name="P:ZhonTai.Admin.Services.Auth.Dto.AuthUserProfileDto.UserName">
             <summary>
             账号
@@ -7170,5 +7211,41 @@
             </summary>
             <param name="app"></param>
         </member>
+        <member name="T:System.Text.RegularExpressions.Generated.PathRegex_0">
+            <summary>Custom <see cref="T:System.Text.RegularExpressions.Regex"/>-derived type for the PathRegex method.</summary>
+        </member>
+        <member name="F:System.Text.RegularExpressions.Generated.PathRegex_0.Instance">
+            <summary>Cached, thread-safe singleton instance.</summary>
+        </member>
+        <member name="M:System.Text.RegularExpressions.Generated.PathRegex_0.#ctor">
+            <summary>Initializes the instance.</summary>
+        </member>
+        <member name="T:System.Text.RegularExpressions.Generated.PathRegex_0.RunnerFactory">
+            <summary>Provides a factory for creating <see cref="T:System.Text.RegularExpressions.RegexRunner"/> instances to be used by methods on <see cref="T:System.Text.RegularExpressions.Regex"/>.</summary>
+        </member>
+        <member name="M:System.Text.RegularExpressions.Generated.PathRegex_0.RunnerFactory.CreateInstance">
+            <summary>Creates an instance of a <see cref="T:System.Text.RegularExpressions.RegexRunner"/> used by methods on <see cref="T:System.Text.RegularExpressions.Regex"/>.</summary>
+        </member>
+        <member name="T:System.Text.RegularExpressions.Generated.PathRegex_0.RunnerFactory.Runner">
+            <summary>Provides the runner that contains the custom logic implementing the specified regular expression.</summary>
+        </member>
+        <member name="M:System.Text.RegularExpressions.Generated.PathRegex_0.RunnerFactory.Runner.Scan(System.ReadOnlySpan{System.Char})">
+            <summary>Scan the <paramref name="inputSpan"/> starting from base.runtextstart for the next match.</summary>
+            <param name="inputSpan">The text being scanned by the regular expression.</param>
+        </member>
+        <member name="M:System.Text.RegularExpressions.Generated.PathRegex_0.RunnerFactory.Runner.TryFindNextPossibleStartingPosition(System.ReadOnlySpan{System.Char})">
+            <summary>Search <paramref name="inputSpan"/> starting from base.runtextpos for the next location a match could possibly start.</summary>
+            <param name="inputSpan">The text being scanned by the regular expression.</param>
+            <returns>true if a possible match was found; false if no more matches are possible.</returns>
+        </member>
+        <member name="T:System.Text.RegularExpressions.Generated.Utilities">
+            <summary>Helper methods used by generated <see cref="T:System.Text.RegularExpressions.Regex"/>-derived implementations.</summary>
+        </member>
+        <member name="F:System.Text.RegularExpressions.Generated.Utilities.s_defaultTimeout">
+            <summary>Default timeout value set in <see cref="T:System.AppContext"/>, or <see cref="F:System.Text.RegularExpressions.Regex.InfiniteMatchTimeout"/> if none was set.</summary>
+        </member>
+        <member name="F:System.Text.RegularExpressions.Generated.Utilities.s_hasTimeout">
+            <summary>Whether <see cref="F:System.Text.RegularExpressions.Generated.Utilities.s_defaultTimeout"/> is non-infinite.</summary>
+        </member>
     </members>
 </doc>