Prechádzať zdrojové kódy

Merge branch 'test' of http://110.188.24.182:10023/Fengwo/hotline into test

tangjiang 1 mesiac pred
rodič
commit
ff01940057

+ 2 - 1
src/Hotline.Api/Controllers/BaseController.cs

@@ -2,13 +2,14 @@
 using Microsoft.AspNetCore.Mvc;
 using MiniExcelLibs;
 using System.IO;
+using Microsoft.AspNetCore.Authorization;
 
 namespace Hotline.Api.Controllers;
 
 [ApiController]
 [Produces("application/json")]
 [Route("api/v1/[controller]")]
-//[LogFilter]
+[Authorize(Policy = AppDefaults.AuthPolicy.Hotline)]
 public class BaseController : ControllerBase
 {
     protected FileStreamResult ExcelStreamResult(Stream stream, string fileName = null)

+ 1 - 1
src/Hotline.Api/Controllers/Snapshot/SnapshotController.cs

@@ -316,7 +316,7 @@ public class SnapshotController : BaseController
     /// <param name="dto"></param>
     /// <returns></returns>
     [HttpPost("report")]
-    [LogFilter("志愿者上报")]
+    [LogFilterAlpha("志愿者上报")]
     public async Task<AddVolunteerReportOutDto> AddVolunteerReportAsync([FromBody] AddVolunteerReportInDto dto)
         => await _snapshotApplication.AddVolunteerReportAsync(dto, HttpContext.RequestAborted);
 

+ 3 - 0
src/Hotline.Api/StartupExtensions.cs

@@ -208,7 +208,10 @@ internal static class StartupExtensions
         //compression
         services.RegisterCompression();
 
+        //authorization
         services.AddSingleton<IAuthorizationPolicyProvider, AuthorizationPolicyProvider>();
+        services.RegisterAuthorization(configuration);
+
         services.AddSingleton<IAuthorizationHandler, PermissionHandler>();
         services.AddScoped<ExpireTimeFactory>();
         services.AddScoped<IExpireTimeSupplier, DaySupplier>();

+ 9 - 0
src/Hotline.Api/StartupHelper.cs

@@ -126,6 +126,15 @@ namespace Hotline.Api
             return services;
         }
 
+        public static IServiceCollection RegisterAuthorization(this IServiceCollection services, ConfigurationManager configuration)
+        {
+            services.AddAuthorization(options =>
+            {
+                options.AddPolicy(AppDefaults.AuthPolicy.Hotline, d => d.RequireClaim("scope", AppDefaults.AuthPolicy.Hotline));
+            });
+            return services;
+        }
+
         /// <summary>
         /// Swagger
         /// </summary>

+ 5 - 3
src/Hotline.Application/Identity/IdentityAppService.cs

@@ -128,7 +128,8 @@ public class IdentityAppService : IIdentityAppService, IScopeDependency
             new(JwtClaimTypes.Subject, account.Id),
             new(JwtClaimTypes.PhoneNumber, account.PhoneNo ?? string.Empty),
             new(AppClaimTypes.UserDisplayName, account.Name),
-            new(JwtClaimTypes.Scope, jwtOptions.Scope),
+            //new(JwtClaimTypes.Scope, jwtOptions.Scope),
+            new(JwtClaimTypes.Scope, account.Scope),
             new(AppClaimTypes.UserPasswordChanged, account.PasswordChanged.ToString()),
             new(AppClaimTypes.StaffNo, user.StaffNo ?? string.Empty),
         };
@@ -247,7 +248,8 @@ public class IdentityAppService : IIdentityAppService, IScopeDependency
             new(JwtClaimTypes.Subject, account.Id),
             new(JwtClaimTypes.PhoneNumber, account.PhoneNo ?? string.Empty),
             new(AppClaimTypes.UserDisplayName, account.Name),
-            new(JwtClaimTypes.Scope, jwtOptions.Scope),
+            //new(JwtClaimTypes.Scope, jwtOptions.Scope),
+            new(JwtClaimTypes.Scope, account.Scope),
             new(AppClaimTypes.UserPasswordChanged, account.PasswordChanged.ToString()),
             new(AppClaimTypes.StaffNo, user.StaffNo ?? string.Empty),
         };
@@ -343,7 +345,7 @@ public class IdentityAppService : IIdentityAppService, IScopeDependency
         {
             new(JwtClaimTypes.Subject, thirdAccount.Id),
             new(JwtClaimTypes.PhoneNumber, thirdAccount.PhoneNumber ?? string.Empty),
-            new(JwtClaimTypes.Scope, jwtOptions.Scope),
+            new(JwtClaimTypes.Scope, jwtOptions.Scope),//todo 三方账号的scope
             new(AppClaimTypes.OpenId, thirdAccount.OpenId),
         };
         claims = await _thirdAccountDomainFactory.GetClaimAsync(thirdAccount, claims, cancel);

+ 7 - 1
src/Hotline.Application/Snapshot/IndustryApplication.cs

@@ -385,10 +385,16 @@ public class IndustryApplication : IIndustryApplication, IScopeDependency
     public ISugarQueryable<VolunteerReportItemsOutDto> GetVolunteerReportItems(VolunteerReportItemsInDto dto)
     {
         var query = _volunteerReportRepository.Queryable()
+            .LeftJoin<SystemDicData>((volunteer, dic) => volunteer.JobType == dic.Id)
             .WhereIF(dto.Name.NotNullOrEmpty(), m => m.Name.Contains(dto.Name))
             .WhereIF(dto.PhoneNumber.NotNullOrEmpty(), m => m.PhoneNumber.Contains(dto.PhoneNumber))
             .OrderByDescending(m => m.CreationTime)
-            .Select<VolunteerReportItemsOutDto>();
+            .Select((volunteer, dic) => new VolunteerReportItemsOutDto
+            {
+                JobType = dic.DicDataName,
+                PhoneNumber = volunteer.DeclarePhoneNumber,
+                FullAddress = volunteer.Address + volunteer.FullAddress
+            }, true);
         return query;
     }
 

+ 5 - 0
src/Hotline/AppDefaults.cs

@@ -34,5 +34,10 @@ namespace Hotline
             public const string ZiGong = "ZiGong";
             public const string LuZhou = "LuZhou";
         }
+
+        public class AuthPolicy
+        {
+            public const string Hotline = "hotline_api";
+        }
     }
 }

+ 3 - 0
src/Hotline/Identity/Accounts/Account.cs

@@ -65,6 +65,9 @@ namespace Hotline.Identity.Accounts
         /// </summary>
         public EAccountType AccountType { get; set; } = EAccountType.Personal;
 
+        [SugarColumn(DefaultValue = "hotline_api")]
+        public string Scope { get; set; }
+
         [Navigate(typeof(AccountRole), nameof(AccountRole.AccountId), nameof(AccountRole.RoleId))]
         public List<Role> Roles { get; set; }
 

+ 6 - 0
src/Hotline/Snapshot/CommunityInfo.cs

@@ -29,6 +29,12 @@ public class CommunityInfo : CreationSoftDeleteEntity
     [SugarColumn(ColumnDescription = "社区全称")]
     public string FullName { get; set; }
 
+    /// <summary>
+    /// 部门编号
+    /// </summary>
+    [SugarColumn(ColumnDescription = "部门编号")]
+    public string DepartmentNo { get; set; }
+
     /// <summary>
     /// 父社区Code
     /// </summary>