diff --git a/build/OSharpNS.nuspec b/build/OSharpNS.nuspec index 00c4dacf..6603c96f 100644 --- a/build/OSharpNS.nuspec +++ b/build/OSharpNS.nuspec @@ -2,7 +2,7 @@ OSharpNS - 6.0.10-preview.1021 + 8.0.9 OSharpFramework(.NET6.0/.NETCoreApp3.1) 柳柳软件(66soft.net) LiuliuSoft nnc @@ -16,18 +16,18 @@ osharp - - - - - + + + + + - - - - - + + + + + diff --git a/build/version.props b/build/version.props index 0f42ca8a..258a15d4 100644 --- a/build/version.props +++ b/build/version.props @@ -1,12 +1,12 @@ 8.0 - 1 + 9 -preview. - 113 - $(VersionMain).$(VersionPrefix)$(VersionSuffix)$(VersionSuffixVersion) - $(VersionMain).$(VersionPrefix).$(VersionSuffixVersion) - + 529 + + $(VersionMain).$(VersionPrefix) + $(VersionMain).$(VersionPrefix) diff --git a/osharp.sln.DotSettings b/osharp.sln.DotSettings index b40d7c28..4d65a297 100644 --- a/osharp.sln.DotSettings +++ b/osharp.sln.DotSettings @@ -92,12 +92,12 @@ LINE_BREAK False ----------------------------------------------------------------------- - <copyright file="$FILENAME$" company="OSharp开源团队"> - Copyright (c) 2014-$CURRENT_YEAR$ OSharp. All rights reserved. + <copyright file="${File.FileName}" company="OSharp开源团队"> + Copyright (c) 2014-${CurrentDate.Year} OSharp. All rights reserved. </copyright> <site>http://www.osharp.org</site> - <last-editor>$USER_NAME$</last-editor> - <last-date>$CURRENT_YEAR$-$CURRENT_MONTH$-$CURRENT_DAY$ $CURRENT_TIME$</last-date> + <last-editor>${User.Name}</last-editor> + <last-date>${CurrentDate.Year}-${CurrentDate.Month}-${CurrentDate.Day} ${CurrentDate.Hour}:${CurrentDate.Minute}</last-date> ----------------------------------------------------------------------- DBC DI @@ -114,6 +114,7 @@ SBC TB <Policy Inspect="True" Prefix="_" Suffix="" Style="aaBb" /> + <Policy><Descriptor Staticness="Static" AccessRightKinds="Private" Description="Static readonly fields (private)"><ElementKinds><Kind Name="READONLY_FIELD" /></ElementKinds></Descriptor><Policy Inspect="True" Prefix="_" Suffix="" Style="aaBb" /></Policy> <Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" /> <Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" /> <Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" /> @@ -163,6 +164,7 @@ False LIVE_MONITOR NOTIFY + True True True True @@ -175,6 +177,7 @@ True True True + True True True True diff --git a/samples/web/Liuliu.Demo.Core/Authorization/Dtos/AutoMapperConfiguration.cs b/samples/web/Liuliu.Demo.Core/Authorization/Dtos/AutoMapperConfiguration.cs index 2a26737e..cb4a13f1 100644 --- a/samples/web/Liuliu.Demo.Core/Authorization/Dtos/AutoMapperConfiguration.cs +++ b/samples/web/Liuliu.Demo.Core/Authorization/Dtos/AutoMapperConfiguration.cs @@ -27,8 +27,8 @@ public class AutoMapperConfiguration : AutoMapperTupleBase /// public override void CreateMap() { - CreateMap() - .ForMember(mr => mr.FilterGroupJson, opt => opt.MapFrom(dto => dto.FilterGroup.ToJsonString(false, false))); + //CreateMap() + // .ForMember(mr => mr.FilterGroupJson, opt => opt.MapFrom(dto => dto.FilterGroup.ToJsonString(false, false))); //mapper.CreateMap() // .ForMember(dto => dto.FilterGroup, opt => opt.ResolveUsing(mr => mr.FilterGroupJson?.FromJsonString())); diff --git a/samples/web/Liuliu.Demo.Core/Authorization/Dtos/EntityRoleOutputDto.cs b/samples/web/Liuliu.Demo.Core/Authorization/Dtos/EntityRoleOutputDto.cs index ab7ae694..135bd6fe 100644 --- a/samples/web/Liuliu.Demo.Core/Authorization/Dtos/EntityRoleOutputDto.cs +++ b/samples/web/Liuliu.Demo.Core/Authorization/Dtos/EntityRoleOutputDto.cs @@ -1,4 +1,4 @@ -// ----------------------------------------------------------------------- +// ----------------------------------------------------------------------- // // Copyright (c) 2014-2018 OSharp. All rights reserved. // @@ -43,7 +43,7 @@ public EntityRoleOutputDto(EntityRole entityRole) IsLocked = entityRole.IsLocked; Operation = entityRole.Operation; CreatedTime = entityRole.CreatedTime; - FilterGroup = entityRole.FilterGroupJson.FromJsonString(); + FilterGroup = entityRole.FilterGroup; } /// diff --git a/samples/web/Liuliu.Demo.Web/Liuliu.Demo.Web.csproj b/samples/web/Liuliu.Demo.Web/Liuliu.Demo.Web.csproj index 44186201..06379256 100644 --- a/samples/web/Liuliu.Demo.Web/Liuliu.Demo.Web.csproj +++ b/samples/web/Liuliu.Demo.Web/Liuliu.Demo.Web.csproj @@ -14,15 +14,15 @@ - + - - + + all runtime; build; native; contentfiles; analyzers; buildtransitive - + diff --git a/samples/web/Liuliu.Demo.WebApi/Liuliu.Demo.WebApi.csproj b/samples/web/Liuliu.Demo.WebApi/Liuliu.Demo.WebApi.csproj index 74f67d01..db3a74dc 100644 --- a/samples/web/Liuliu.Demo.WebApi/Liuliu.Demo.WebApi.csproj +++ b/samples/web/Liuliu.Demo.WebApi/Liuliu.Demo.WebApi.csproj @@ -21,30 +21,30 @@ - + - - - + + + all runtime; build; native; contentfiles; analyzers; buildtransitive - - - + + + all runtime; build; native; contentfiles; analyzers; buildtransitive - - - + + + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/samples/wpf/OSharp.CodeGeneration/OSharp.CodeGeneration.csproj b/samples/wpf/OSharp.CodeGeneration/OSharp.CodeGeneration.csproj index be835b7c..0c8d05ed 100644 --- a/samples/wpf/OSharp.CodeGeneration/OSharp.CodeGeneration.csproj +++ b/samples/wpf/OSharp.CodeGeneration/OSharp.CodeGeneration.csproj @@ -9,8 +9,8 @@ - - + + diff --git a/samples/wpf/OSharp.CodeGenerator/OSharp.CodeGenerator.csproj b/samples/wpf/OSharp.CodeGenerator/OSharp.CodeGenerator.csproj index c4f677ef..330356ee 100644 --- a/samples/wpf/OSharp.CodeGenerator/OSharp.CodeGenerator.csproj +++ b/samples/wpf/OSharp.CodeGenerator/OSharp.CodeGenerator.csproj @@ -14,16 +14,16 @@ - - - - - + + + + + all runtime; build; native; contentfiles; analyzers; buildtransitive - - + + diff --git a/src/OSharp.AspNetCore/HttpRequestExtensions.cs b/src/OSharp.AspNetCore/HttpRequestExtensions.cs index 904c6722..c493ecb1 100644 --- a/src/OSharp.AspNetCore/HttpRequestExtensions.cs +++ b/src/OSharp.AspNetCore/HttpRequestExtensions.cs @@ -17,7 +17,6 @@ public static class HttpContextExtensions /// /// 确定指定的 HTTP 请求是否为 AJAX 请求。 /// - /// /// /// 如果指定的 HTTP 请求是 AJAX 请求,则为 true;否则为 false。 /// @@ -75,7 +74,7 @@ public static string GetClientIp(this HttpContext context) string ip = context.Request.Headers["X-Forwarded-For"].FirstOrDefault(); if (string.IsNullOrEmpty(ip)) { - ip = context.Connection.RemoteIpAddress.ToString(); + ip = context.Connection.RemoteIpAddress?.ToString(); } return ip; } diff --git a/src/OSharp.AspNetCore/Mvc/Filters/AuditOperationAttribute.cs b/src/OSharp.AspNetCore/Mvc/Filters/AuditOperationAttribute.cs index eea6165f..b102ac9a 100644 --- a/src/OSharp.AspNetCore/Mvc/Filters/AuditOperationAttribute.cs +++ b/src/OSharp.AspNetCore/Mvc/Filters/AuditOperationAttribute.cs @@ -42,7 +42,7 @@ public override void OnActionExecuting(ActionExecutingContext context) UserAgent = context.HttpContext.Request.Headers["User-Agent"].FirstOrDefault(), CreatedTime = DateTime.Now }; - if (context.HttpContext.User.Identity.IsAuthenticated && context.HttpContext.User.Identity is ClaimsIdentity identity) + if (context.HttpContext.User.Identity?.IsAuthenticated == true && context.HttpContext.User.Identity is ClaimsIdentity identity) { operation.UserId = identity.GetUserId(); operation.UserName = identity.GetUserName(); diff --git a/src/OSharp.AspNetCore/OSharp.AspNetCore.csproj b/src/OSharp.AspNetCore/OSharp.AspNetCore.csproj index 57a31bd7..a4261d78 100644 --- a/src/OSharp.AspNetCore/OSharp.AspNetCore.csproj +++ b/src/OSharp.AspNetCore/OSharp.AspNetCore.csproj @@ -16,19 +16,19 @@ - - - + + + - - - + + + - - - + + + diff --git a/src/OSharp.Authorization.Datas/DataAuthCacheBase.cs b/src/OSharp.Authorization.Datas/DataAuthCacheBase.cs index 6400682c..9a7f6388 100644 --- a/src/OSharp.Authorization.Datas/DataAuthCacheBase.cs +++ b/src/OSharp.Authorization.Datas/DataAuthCacheBase.cs @@ -54,7 +54,11 @@ public virtual void BuildCaches() foreach (var entityRole in entityRoles) { - FilterGroup filterGroup = entityRole.FilterGroupJson.FromJsonString(); + FilterGroup filterGroup = entityRole.FilterGroupJson?.FromJsonString(); + if (filterGroup == null) + { + continue; + } string key = GetKey(entityRole.RoleName, entityRole.EntityTypeFullName, entityRole.Operation); string name = GetName(entityRole.RoleName, entityRole.EntityTypeFullName, entityRole.Operation); diff --git a/src/OSharp.Authorization.Datas/DataAuthorizationManagerBase.cs b/src/OSharp.Authorization.Datas/DataAuthorizationManagerBase.cs index f62db05b..2eea3864 100644 --- a/src/OSharp.Authorization.Datas/DataAuthorizationManagerBase.cs +++ b/src/OSharp.Authorization.Datas/DataAuthorizationManagerBase.cs @@ -7,6 +7,8 @@ // 2020-02-26 23:15 // ----------------------------------------------------------------------- +using OSharp.Json; + namespace OSharp.Authorization.DataAuthorization; @@ -120,7 +122,6 @@ public virtual async Task CreateEntityRoles(params TEntityRoleI { Check2.Validate(dtos, nameof(dtos)); - DataAuthCacheRefreshEventData eventData = new DataAuthCacheRefreshEventData(); OperationResult result = await EntityRoleRepository.InsertAsync(dtos, async dto => { @@ -141,27 +142,7 @@ public virtual async Task CreateEntityRoles(params TEntityRoleI throw new OsharpException($"角色“{role.Name}”和实体“{entityInfo.Name}”和操作“{dto.Operation}”的数据权限规则已存在,不能重复添加"); } - OperationResult checkResult = CheckFilterGroup(dto.FilterGroup, entityInfo); - if (!checkResult.Succeeded) - { - throw new OsharpException($"数据规则验证失败:{checkResult.Message}"); - } - - if (!dto.IsLocked) - { - eventData.SetItems.Add(new DataAuthCacheItem() - { - RoleName = role.Name, - EntityTypeFullName = entityInfo.TypeName, - Operation = dto.Operation, - FilterGroup = dto.FilterGroup - }); - } }); - if (result.Succeeded && eventData.HasData()) - { - await EventBus.PublishAsync(eventData); - } return result; } @@ -197,24 +178,18 @@ public virtual async Task UpdateEntityRoles(params TEntityRoleI throw new OsharpException($"角色“{role.Name}”和实体“{entityInfo.Name}”和操作“{dto.Operation}”的数据权限规则已存在,不能重复添加"); } - OperationResult checkResult = CheckFilterGroup(dto.FilterGroup, entityInfo); - if (!checkResult.Succeeded) - { - throw new OsharpException($"数据规则验证失败:{checkResult.Message}"); - } - DataAuthCacheItem cacheItem = new DataAuthCacheItem() { RoleName = role.Name, EntityTypeFullName = entityInfo.TypeName, Operation = dto.Operation, - FilterGroup = dto.FilterGroup + FilterGroup = entity.FilterGroup }; if (dto.IsLocked) { eventData.RemoveItems.Add(cacheItem); } - else + else if(entity.FilterGroup != null) { eventData.SetItems.Add(cacheItem); } @@ -228,6 +203,63 @@ public virtual async Task UpdateEntityRoles(params TEntityRoleI return result; } + /// + /// 设置角色数据权限的过滤条件组 + /// + /// 权限记录identity.api + /// 过滤条件组 + /// 业务操作结果 + public async Task SetFilterGroup(Guid id, FilterGroup group) + { + TEntityRole entityRole = await EntityRoleRepository.GetAsync(id); + if (entityRole == null) + { + return new OperationResult(OperationResultType.QueryNull, $"编号为“{id}”的数据权限信息不存在"); + } + + TRole role = await RoleRepository.GetAsync(entityRole.RoleId); + if (role == null) + { + return new OperationResult(OperationResultType.QueryNull, $"编号为“{entityRole.RoleId}”的角色信息不存在"); + } + + TEntityInfo entityInfo = await EntityInfoRepository.GetAsync(entityRole.EntityId); + if (entityInfo == null) + { + return new OperationResult(OperationResultType.QueryNull, $"编号为“{entityRole.EntityId}”的数据实体信息不存在"); + } + + OperationResult checkResult = CheckFilterGroup(group, entityInfo); + if (!checkResult.Succeeded) + { + return new OperationResult(OperationResultType.Error, $"数据规则验证失败:{checkResult.Message}"); + } + + IUnitOfWork unitOfWork = _provider.GetUnitOfWork(true); + entityRole.FilterGroupJson = group.ToJsonString(); + int count = await EntityRoleRepository.UpdateAsync(entityRole); + await unitOfWork.CommitAsync(); + if (count > 0) + { + DataAuthCacheRefreshEventData eventData = new DataAuthCacheRefreshEventData(); + eventData.SetItems.Add(new DataAuthCacheItem() + { + RoleName = role.Name, + EntityTypeFullName = entityInfo.TypeName, + Operation = entityRole.Operation, + FilterGroup = entityRole.FilterGroup + }); + if (eventData.HasData()) + { + await EventBus.PublishAsync(eventData); + } + + return new OperationResult(OperationResultType.Success, $"{role.Name} - {entityInfo.Name} - {entityRole.Operation} 的过滤条件设置成功"); + } + + return OperationResult.NoChanged; + } + /// /// 删除实体角色信息 /// @@ -244,7 +276,7 @@ public virtual async Task DeleteEntityRoles(params Guid[] ids) if (role != null && entityInfo != null) { eventData.RemoveItems.Add(new DataAuthCacheItem() - { RoleName = role.Name, EntityTypeFullName = entityInfo.TypeName, Operation = entity.Operation }); + { RoleName = role.Name, EntityTypeFullName = entityInfo.TypeName, Operation = entity.Operation }); } }); if (result.Succeeded && eventData.HasData()) diff --git a/src/OSharp.Authorization.Datas/Dtos/EntityRoleInputDtoBase.cs b/src/OSharp.Authorization.Datas/Dtos/EntityRoleInputDtoBase.cs index 4b719b7c..a2b8eeed 100644 --- a/src/OSharp.Authorization.Datas/Dtos/EntityRoleInputDtoBase.cs +++ b/src/OSharp.Authorization.Datas/Dtos/EntityRoleInputDtoBase.cs @@ -16,14 +16,6 @@ namespace OSharp.Authorization.Dtos; /// 角色编号类型 public abstract class EntityRoleInputDtoBase : IInputDto { - /// - /// 初始化一个类型的新实例 - /// - protected EntityRoleInputDtoBase() - { - FilterGroup = new FilterGroup(); - } - /// /// 获取或设置 主键,唯一标识 /// @@ -48,12 +40,6 @@ protected EntityRoleInputDtoBase() [DisplayName("数据权限操作")] public DataAuthOperation Operation { get; set; } - /// - /// 获取或设置 过滤条件组 - /// - [DisplayName("数据筛选条件组")] - public FilterGroup FilterGroup { get; set; } - /// /// 获取或设置 是否锁定 /// diff --git a/src/OSharp.Authorization.Datas/IEntityRoleStore.cs b/src/OSharp.Authorization.Datas/IEntityRoleStore.cs index aaac6aee..86f6d627 100644 --- a/src/OSharp.Authorization.Datas/IEntityRoleStore.cs +++ b/src/OSharp.Authorization.Datas/IEntityRoleStore.cs @@ -53,6 +53,14 @@ public interface IEntityRoleStore业务操作结果 Task UpdateEntityRoles(params TEntityRoleInputDto[] dtos); + /// + /// 设置角色数据权限的过滤条件组 + /// + /// 权限记录identity.api + /// 过滤条件组 + /// 业务操作结果 + Task SetFilterGroup(Guid id, FilterGroup group); + /// /// 删除实体角色信息 /// diff --git a/src/OSharp.AutoMapper/OSharp.AutoMapper.csproj b/src/OSharp.AutoMapper/OSharp.AutoMapper.csproj index e9fd8129..9c93a4aa 100644 --- a/src/OSharp.AutoMapper/OSharp.AutoMapper.csproj +++ b/src/OSharp.AutoMapper/OSharp.AutoMapper.csproj @@ -12,7 +12,7 @@ - + diff --git a/src/OSharp.EntityFrameworkCore.MySql/OSharp.EntityFrameworkCore.MySql.csproj b/src/OSharp.EntityFrameworkCore.MySql/OSharp.EntityFrameworkCore.MySql.csproj index e0823f1b..d4bad59b 100644 --- a/src/OSharp.EntityFrameworkCore.MySql/OSharp.EntityFrameworkCore.MySql.csproj +++ b/src/OSharp.EntityFrameworkCore.MySql/OSharp.EntityFrameworkCore.MySql.csproj @@ -12,13 +12,13 @@ - + - + - + diff --git a/src/OSharp.EntityFrameworkCore.Oracle/OSharp.EntityFrameworkCore.Oracle.csproj b/src/OSharp.EntityFrameworkCore.Oracle/OSharp.EntityFrameworkCore.Oracle.csproj index d30781ad..e2cca3b9 100644 --- a/src/OSharp.EntityFrameworkCore.Oracle/OSharp.EntityFrameworkCore.Oracle.csproj +++ b/src/OSharp.EntityFrameworkCore.Oracle/OSharp.EntityFrameworkCore.Oracle.csproj @@ -12,13 +12,13 @@ - + - + - + diff --git a/src/OSharp.EntityFrameworkCore.PostgreSql/OSharp.EntityFrameworkCore.PostgreSql.csproj b/src/OSharp.EntityFrameworkCore.PostgreSql/OSharp.EntityFrameworkCore.PostgreSql.csproj index 6c6bcd04..d6607d2e 100644 --- a/src/OSharp.EntityFrameworkCore.PostgreSql/OSharp.EntityFrameworkCore.PostgreSql.csproj +++ b/src/OSharp.EntityFrameworkCore.PostgreSql/OSharp.EntityFrameworkCore.PostgreSql.csproj @@ -12,13 +12,13 @@ - + - + - + diff --git a/src/OSharp.EntityFrameworkCore.SqlServer/OSharp.EntityFrameworkCore.SqlServer.csproj b/src/OSharp.EntityFrameworkCore.SqlServer/OSharp.EntityFrameworkCore.SqlServer.csproj index f72c7609..2b483974 100644 --- a/src/OSharp.EntityFrameworkCore.SqlServer/OSharp.EntityFrameworkCore.SqlServer.csproj +++ b/src/OSharp.EntityFrameworkCore.SqlServer/OSharp.EntityFrameworkCore.SqlServer.csproj @@ -12,13 +12,13 @@ - + - + - + diff --git a/src/OSharp.EntityFrameworkCore.Sqlite/OSharp.EntityFrameworkCore.Sqlite.csproj b/src/OSharp.EntityFrameworkCore.Sqlite/OSharp.EntityFrameworkCore.Sqlite.csproj index 6e8826b1..5f82fb11 100644 --- a/src/OSharp.EntityFrameworkCore.Sqlite/OSharp.EntityFrameworkCore.Sqlite.csproj +++ b/src/OSharp.EntityFrameworkCore.Sqlite/OSharp.EntityFrameworkCore.Sqlite.csproj @@ -12,13 +12,13 @@ - + - + - + diff --git a/src/OSharp.EntityFrameworkCore/OSharp.EntityFrameworkCore.csproj b/src/OSharp.EntityFrameworkCore/OSharp.EntityFrameworkCore.csproj index 07ce5442..d52fd582 100644 --- a/src/OSharp.EntityFrameworkCore/OSharp.EntityFrameworkCore.csproj +++ b/src/OSharp.EntityFrameworkCore/OSharp.EntityFrameworkCore.csproj @@ -13,22 +13,22 @@ - + - - - + + + - - - + + + - - - + + + diff --git a/src/OSharp.EntityFrameworkCore/Repository.cs b/src/OSharp.EntityFrameworkCore/Repository.cs index eb15922f..cfba552f 100644 --- a/src/OSharp.EntityFrameworkCore/Repository.cs +++ b/src/OSharp.EntityFrameworkCore/Repository.cs @@ -734,8 +734,8 @@ public virtual async Task DeleteBatchAsync(Expression> { // 物理删除 count = await _dbSet.Where(predicate).DeleteAsync(_cancellationTokenProvider.Token); - } - + } + await unitOfWork.CommitAsync(_cancellationTokenProvider.Token); return count; } @@ -828,8 +828,8 @@ public virtual async Task UpdateBatchAsync(Expression> //走EF.Plus的时候,是不调用SaveChanges的,需要手动开启事务 await ((DbContextBase)_dbContext).BeginOrUseTransactionAsync(_cancellationTokenProvider.Token); - int count = await _dbSet.Where(predicate).UpdateAsync(updateExpression, _cancellationTokenProvider.Token); - + int count = await _dbSet.Where(predicate).UpdateAsync(updateExpression, _cancellationTokenProvider.Token); + await unitOfWork.CommitAsync(_cancellationTokenProvider.Token); return count; } @@ -937,15 +937,16 @@ private void CheckDataAuth(DataAuthOperation operation, params TEntity[] entitie if (entities.Length == 0 || _dataAuthService == null) { return; - } - + } + bool flag = _dataAuthService.CheckDataAuth(operation, entities); if (!flag) { - throw new OsharpException($"实体 {typeof(TEntity)} 的数据 {entities.ExpandAndToString(m => m.Id.ToString())} 进行 {operation.ToDescription()} 操作时权限不足"); + throw new OsharpException( + $"{operation.ToDescription()}编号为 {entities.ExpandAndToString(m => m.Id.ToString())} 的 {typeof(TEntity).GetDescription()} 时操作权限不足(403)"); } - } - + } + private TEntity[] CheckInsert(params TEntity[] entities) { for (int i = 0; i < entities.Length; i++) @@ -1026,4 +1027,4 @@ private void DeleteInternal(params TEntity[] entities) } #endregion -} +} diff --git a/src/OSharp.Exceptionless/OSharp.Exceptionless.csproj b/src/OSharp.Exceptionless/OSharp.Exceptionless.csproj index 7b1c1960..f82c139b 100644 --- a/src/OSharp.Exceptionless/OSharp.Exceptionless.csproj +++ b/src/OSharp.Exceptionless/OSharp.Exceptionless.csproj @@ -12,7 +12,7 @@ - + diff --git a/src/OSharp.Hangfire/OSharp.Hangfire.csproj b/src/OSharp.Hangfire/OSharp.Hangfire.csproj index f72e6ba0..7e473b73 100644 --- a/src/OSharp.Hangfire/OSharp.Hangfire.csproj +++ b/src/OSharp.Hangfire/OSharp.Hangfire.csproj @@ -11,8 +11,8 @@ - - + + diff --git a/src/OSharp.Hosting.Apis/Areas/Admin/Controllers/Auth/RoleEntityController.cs b/src/OSharp.Hosting.Apis/Areas/Admin/Controllers/Auth/RoleEntityController.cs index 10c87263..b379ca59 100644 --- a/src/OSharp.Hosting.Apis/Areas/Admin/Controllers/Auth/RoleEntityController.cs +++ b/src/OSharp.Hosting.Apis/Areas/Admin/Controllers/Auth/RoleEntityController.cs @@ -105,6 +105,23 @@ public async Task Update(params EntityRoleInputDto[] dtos) return result.ToAjaxResult(); } + /// + /// 设置角色数据权限的过滤条件组 + /// + /// 权限记录identity.api + /// 过滤条件组 + /// JSON操作结果 + [HttpPost] + [ModuleInfo] + [DependOnFunction(nameof(Read))] + [UnitOfWork] + [Description("设置过滤条件")] + public async Task SetFilterGroup(Guid id, [FromBody]FilterGroup group) + { + OperationResult result = await _dataAuthManager.SetFilterGroup(id, group); + return result.ToAjaxResult(); + } + /// /// 删除角色数据权限信息 /// diff --git a/src/OSharp.Hosting.Apis/OSharp.Hosting.Apis.csproj b/src/OSharp.Hosting.Apis/OSharp.Hosting.Apis.csproj index f4ae4fda..293e8a43 100644 --- a/src/OSharp.Hosting.Apis/OSharp.Hosting.Apis.csproj +++ b/src/OSharp.Hosting.Apis/OSharp.Hosting.Apis.csproj @@ -17,16 +17,16 @@ - + - + - + - + diff --git a/src/OSharp.Hosting.Core/Authorization/Dtos/AutoMapperConfiguration.cs b/src/OSharp.Hosting.Core/Authorization/Dtos/AutoMapperConfiguration.cs index 8d66ee5b..c8ff8504 100644 --- a/src/OSharp.Hosting.Core/Authorization/Dtos/AutoMapperConfiguration.cs +++ b/src/OSharp.Hosting.Core/Authorization/Dtos/AutoMapperConfiguration.cs @@ -22,9 +22,6 @@ public class AutoMapperConfiguration : AutoMapperTupleBase /// public override void CreateMap() { - CreateMap() - .ForMember(mr => mr.FilterGroupJson, opt => opt.MapFrom(dto => dto.FilterGroup.ToJsonString(false, false))); - //mapper.CreateMap() // .ForMember(dto => dto.FilterGroup, opt => opt.ResolveUsing(mr => mr.FilterGroupJson?.FromJsonString())); } diff --git a/src/OSharp.Hosting.Core/Authorization/Dtos/EntityRoleOutputDto.cs b/src/OSharp.Hosting.Core/Authorization/Dtos/EntityRoleOutputDto.cs index 0da2b66e..0668a4fd 100644 --- a/src/OSharp.Hosting.Core/Authorization/Dtos/EntityRoleOutputDto.cs +++ b/src/OSharp.Hosting.Core/Authorization/Dtos/EntityRoleOutputDto.cs @@ -35,7 +35,7 @@ public EntityRoleOutputDto(EntityRole entityRole) IsLocked = entityRole.IsLocked; Operation = entityRole.Operation; CreatedTime = entityRole.CreatedTime; - FilterGroup = entityRole.FilterGroupJson.FromJsonString(); + FilterGroup = entityRole.FilterGroup; } /// diff --git a/src/OSharp.Hosting.Core/Identity/Entities/Organization.cs b/src/OSharp.Hosting.Core/Identity/Entities/Organization.cs index 7dc61914..ed2994f1 100644 --- a/src/OSharp.Hosting.Core/Identity/Entities/Organization.cs +++ b/src/OSharp.Hosting.Core/Identity/Entities/Organization.cs @@ -14,7 +14,7 @@ namespace OSharp.Hosting.Identity.Entities; /// [Description("组织机构信息")] [TableNamePrefix("Identity")] -public class Organization : EntityBase +public class Organization : EntityBase, ILockable, ICreatedTime { /// /// 获取或设置 名称 @@ -22,6 +22,12 @@ public class Organization : EntityBase [Required, DisplayName("名称"), StringLength(200)] public string Name { get; set; } + /// + /// 获取或设置 编码 + /// + [Required, DisplayName("编码"), StringLength(200)] + public string Code { get; set; } + /// /// 获取或设置 描述 /// @@ -33,4 +39,16 @@ public class Organization : EntityBase /// [DisplayName("父组织机构编号")] public int? ParentId { get; set; } + + /// + /// 获取或设置 是否锁定当前信息 + /// + [DisplayName("是否锁定")] + public bool IsLocked { get; set; } + + /// + /// 获取或设置 创建时间 + /// + [DisplayName("创建时间")] + public DateTime CreatedTime { get; set; } } diff --git a/src/OSharp.Hosting.Core/Identity/Events/Logout_RemoveRefreshTokenEventHandler.cs b/src/OSharp.Hosting.Core/Identity/Events/Logout_RemoveRefreshTokenEventHandler.cs index 51c1d153..175022de 100644 --- a/src/OSharp.Hosting.Core/Identity/Events/Logout_RemoveRefreshTokenEventHandler.cs +++ b/src/OSharp.Hosting.Core/Identity/Events/Logout_RemoveRefreshTokenEventHandler.cs @@ -1,4 +1,4 @@ -// ----------------------------------------------------------------------- +// ----------------------------------------------------------------------- // // Copyright (c) 2014-2022 OSharp. All rights reserved. // @@ -16,16 +16,14 @@ namespace OSharp.Hosting.Identity.Events; public class Logout_RemoveRefreshTokenEventHandler : EventHandlerBase { - private readonly IPrincipal _principal; - private readonly UserManager _userManager; + private readonly IServiceProvider _provider; /// /// 初始化一个类型的新实例 /// - public Logout_RemoveRefreshTokenEventHandler(UserManager userManager, IPrincipal principal) + public Logout_RemoveRefreshTokenEventHandler(IServiceProvider provider) { - _userManager = userManager; - _principal = principal; + _provider = provider; } /// @@ -45,7 +43,8 @@ public override void Handle(LogoutEventData eventData) /// 是否成功 public override async Task HandleAsync(LogoutEventData eventData, CancellationToken cancelToken = default(CancellationToken)) { - ClaimsIdentity identity = _principal.Identity as ClaimsIdentity; + IPrincipal principal = _provider.GetCurrentUser(); + ClaimsIdentity identity = principal.Identity as ClaimsIdentity; if (identity?.IsAuthenticated != true) { return; @@ -57,6 +56,10 @@ public override void Handle(LogoutEventData eventData) return; } - await _userManager.RemoveRefreshToken(eventData.UserId.ToString(), clientId); + var dataAuthService = _provider.GetService(); + dataAuthService.SetIgnoreDataAuth(typeof(User)); + + var userManager = _provider.GetService>(); + await userManager.RemoveRefreshToken(eventData.UserId.ToString(), clientId); } } diff --git a/src/OSharp.Hosting.Core/OSharp.Hosting.Core.csproj b/src/OSharp.Hosting.Core/OSharp.Hosting.Core.csproj index a902e2ef..e32422f7 100644 --- a/src/OSharp.Hosting.Core/OSharp.Hosting.Core.csproj +++ b/src/OSharp.Hosting.Core/OSharp.Hosting.Core.csproj @@ -12,8 +12,8 @@ - - + + diff --git a/src/OSharp.Identity/Authentication/AuthenticationPackBase.cs b/src/OSharp.Identity/Authentication/AuthenticationPackBase.cs index b12a5800..1cf2a7a4 100644 --- a/src/OSharp.Identity/Authentication/AuthenticationPackBase.cs +++ b/src/OSharp.Identity/Authentication/AuthenticationPackBase.cs @@ -187,13 +187,13 @@ protected virtual AuthenticationBuilder AddOAuth2(IServiceCollection services, A opts.ClientSecret = options.ClientSecret; }); break; - case "GitHub": - builder.AddGitHub(opts => - { - opts.ClientId = options.ClientId; - opts.ClientSecret = options.ClientSecret; - }); - break; + //case "GitHub": + // builder.AddGitHub(opts => + // { + // opts.ClientId = options.ClientId; + // opts.ClientSecret = options.ClientSecret; + // }); + // break; } } diff --git a/src/OSharp.Identity/Authentication/JwtBearer/JwtBearerService.cs b/src/OSharp.Identity/Authentication/JwtBearer/JwtBearerService.cs index 158217af..4f8d8297 100644 --- a/src/OSharp.Identity/Authentication/JwtBearer/JwtBearerService.cs +++ b/src/OSharp.Identity/Authentication/JwtBearer/JwtBearerService.cs @@ -7,6 +7,9 @@ // 2019-06-15 13:26 // ----------------------------------------------------------------------- +using OSharp.Authorization; + + namespace OSharp.Authentication.JwtBearer; /// @@ -116,6 +119,10 @@ private async Task CreateToken(string userId, string userName, Req }; var (token, expires) = CreateToken(claims, _jwtOptions, JwtTokenType.RefreshToken, refreshToken); string refreshTokenStr = token; + //关闭数据权限检查 + var dataAuthService = _provider.GetService(); + dataAuthService.SetIgnoreDataAuth(typeof(TUser)); + IUnitOfWork unitOfWork = _provider.GetUnitOfWork(true); UserManager userManager = _provider.GetService>(); refreshToken = new RefreshToken() { ClientId = clientId, Value = refreshTokenStr, EndUtcTime = expires }; @@ -200,4 +207,4 @@ private enum JwtTokenType RefreshToken } -} \ No newline at end of file +} diff --git a/src/OSharp.Identity/Authentication/UserClaimsProvider.cs b/src/OSharp.Identity/Authentication/UserClaimsProvider.cs index 67f30d9d..06ae5d19 100644 --- a/src/OSharp.Identity/Authentication/UserClaimsProvider.cs +++ b/src/OSharp.Identity/Authentication/UserClaimsProvider.cs @@ -59,7 +59,7 @@ public async Task CreateClaims(string userId) /// 刷新后的Identity public async Task> RefreshIdentity(ClaimsIdentity identity) { - if (identity != null && identity.IsAuthenticated) + if (identity is { IsAuthenticated: true }) { IOnlineUserProvider onlineUserProvider = _provider.GetService(); OnlineUser onlineUser = await onlineUserProvider.GetOrCreate(identity.Name); diff --git a/src/OSharp.Identity/Identity/IdentityPackBase.cs b/src/OSharp.Identity/Identity/IdentityPackBase.cs index 6d0940d4..c568df78 100644 --- a/src/OSharp.Identity/Identity/IdentityPackBase.cs +++ b/src/OSharp.Identity/Identity/IdentityPackBase.cs @@ -1,4 +1,4 @@ -// ----------------------------------------------------------------------- +// ----------------------------------------------------------------------- // // Copyright (c) 2014-2018 OSharp. All rights reserved. // diff --git a/src/OSharp.Identity/OSharp.Identity.csproj b/src/OSharp.Identity/OSharp.Identity.csproj index 0791fcfa..3cec36c0 100644 --- a/src/OSharp.Identity/OSharp.Identity.csproj +++ b/src/OSharp.Identity/OSharp.Identity.csproj @@ -17,20 +17,17 @@ - - - - - + + - - + + - - + + diff --git a/src/OSharp.Log4Net/OSharp.Log4Net.csproj b/src/OSharp.Log4Net/OSharp.Log4Net.csproj index 8d84f50f..f113a07f 100644 --- a/src/OSharp.Log4Net/OSharp.Log4Net.csproj +++ b/src/OSharp.Log4Net/OSharp.Log4Net.csproj @@ -11,7 +11,7 @@ - + diff --git a/src/OSharp.MiniProfiler/OSharp.MiniProfiler.csproj b/src/OSharp.MiniProfiler/OSharp.MiniProfiler.csproj index f696a267..bc1eda93 100644 --- a/src/OSharp.MiniProfiler/OSharp.MiniProfiler.csproj +++ b/src/OSharp.MiniProfiler/OSharp.MiniProfiler.csproj @@ -11,8 +11,8 @@ - - + + diff --git a/src/OSharp.NLog/OSharp.NLog.csproj b/src/OSharp.NLog/OSharp.NLog.csproj index c9d3f7b5..e637e706 100644 --- a/src/OSharp.NLog/OSharp.NLog.csproj +++ b/src/OSharp.NLog/OSharp.NLog.csproj @@ -12,7 +12,7 @@ - + diff --git a/src/OSharp.Redis/OSharp.Redis.csproj b/src/OSharp.Redis/OSharp.Redis.csproj index 57ee2f8b..77d51c56 100644 --- a/src/OSharp.Redis/OSharp.Redis.csproj +++ b/src/OSharp.Redis/OSharp.Redis.csproj @@ -11,13 +11,13 @@ - + - + - + diff --git a/src/OSharp.Swagger/OSharp.Swagger.csproj b/src/OSharp.Swagger/OSharp.Swagger.csproj index 910342da..7ad52d3e 100644 --- a/src/OSharp.Swagger/OSharp.Swagger.csproj +++ b/src/OSharp.Swagger/OSharp.Swagger.csproj @@ -19,7 +19,7 @@ - + diff --git a/src/OSharp.Utils/Caching/DistributedCacheExtensions.cs b/src/OSharp.Utils/Caching/DistributedCacheExtensions.cs index 8a95e313..2504c55f 100644 --- a/src/OSharp.Utils/Caching/DistributedCacheExtensions.cs +++ b/src/OSharp.Utils/Caching/DistributedCacheExtensions.cs @@ -8,6 +8,7 @@ // ----------------------------------------------------------------------- using System; +using System.Threading; using System.Threading.Tasks; using Microsoft.Extensions.Caching.Distributed; @@ -46,7 +47,7 @@ public static void Set(this IDistributedCache cache, string key, object value, D /// /// 异步将对象存入缓存中 /// - public static async Task SetAsync(this IDistributedCache cache, string key, object value, DistributedCacheEntryOptions options = null) + public static async Task SetAsync(this IDistributedCache cache, string key, object value, DistributedCacheEntryOptions options = null, CancellationToken token = default) { Check.NotNullOrEmpty(key, nameof(key)); Check.NotNull(value, nameof(value)); @@ -54,11 +55,11 @@ public static async Task SetAsync(this IDistributedCache cache, string key, obje string json = value.ToJsonString(); if (options == null) { - await cache.SetStringAsync(key, json); + await cache.SetStringAsync(key, json, token); } else { - await cache.SetStringAsync(key, json, options); + await cache.SetStringAsync(key, json, options, token); } } @@ -79,7 +80,7 @@ public static void Set(this IDistributedCache cache, string key, object value, i /// /// 异步将对象存入缓存中,使用指定时长 /// - public static Task SetAsync(this IDistributedCache cache, string key, object value, int cacheSeconds) + public static Task SetAsync(this IDistributedCache cache, string key, object value, int cacheSeconds, CancellationToken token = default) { Check.NotNullOrEmpty(key, nameof(key)); Check.NotNull(value, nameof(value)); @@ -87,9 +88,9 @@ public static Task SetAsync(this IDistributedCache cache, string key, object val DistributedCacheEntryOptions options = new DistributedCacheEntryOptions(); options.SetAbsoluteExpiration(TimeSpan.FromSeconds(cacheSeconds)); - return cache.SetAsync(key, value, options); + return cache.SetAsync(key, value, options, token); } - + /// /// 获取指定键的缓存项 /// @@ -106,9 +107,9 @@ public static TResult Get(this IDistributedCache cache, string key) /// /// 异步获取指定键的缓存项 /// - public static async Task GetAsync(this IDistributedCache cache, string key) + public static async Task GetAsync(this IDistributedCache cache, string key, CancellationToken token = default) { - string json = await cache.GetStringAsync(key); + string json = await cache.GetStringAsync(key, token); if (json == null) { return default(TResult); @@ -138,9 +139,13 @@ public static TResult Get(this IDistributedCache cache, string key, Fun /// /// 异步获取指定键的缓存项,不存在则从指定委托获取,并回存到缓存中再返回 /// - public static async Task GetAsync(this IDistributedCache cache, string key, Func> getAsyncFunc, DistributedCacheEntryOptions options = null) + public static async Task GetAsync(this IDistributedCache cache, + string key, + Func> getAsyncFunc, + DistributedCacheEntryOptions options = null, + CancellationToken token = default) { - TResult result = await cache.GetAsync(key); + TResult result = await cache.GetAsync(key, token); if (!Equals(result, default(TResult))) { return result; @@ -150,7 +155,30 @@ public static async Task GetAsync(this IDistributedCache cache { return default(TResult); } - await cache.SetAsync(key, result, options); + await cache.SetAsync(key, result, options, token); + return result; + } + + /// + /// 异步获取指定键的缓存项,不存在则从指定委托获取,并回存到缓存中再返回 + /// + public static async Task GetAsync(this IDistributedCache cache, + string key, + Func> getAsyncFunc, + DistributedCacheEntryOptions options = null, + CancellationToken token = default) + { + TResult result = await cache.GetAsync(key, token); + if (!Equals(result, default(TResult))) + { + return result; + } + result = await getAsyncFunc(token); + if (Equals(result, default(TResult))) + { + return default(TResult); + } + await cache.SetAsync(key, result, options, token); return result; } @@ -169,15 +197,35 @@ public static TResult Get(this IDistributedCache cache, string key, Fun /// /// 异步获取指定键的缓存项,不存在则从指定委托获取,并回存到缓存中再返回 /// - public static Task GetAsync(this IDistributedCache cache, string key, Func> getAsyncFunc, int cacheSeconds) + public static Task GetAsync(this IDistributedCache cache, + string key, + Func> getAsyncFunc, + int cacheSeconds, + CancellationToken token = default) + { + Check.GreaterThan(cacheSeconds, nameof(cacheSeconds), 0); + + DistributedCacheEntryOptions options = new DistributedCacheEntryOptions(); + options.SetAbsoluteExpiration(TimeSpan.FromSeconds(cacheSeconds)); + return cache.GetAsync(key, getAsyncFunc, options, token); + } + + /// + /// 异步获取指定键的缓存项,不存在则从指定委托获取,并回存到缓存中再返回 + /// + public static Task GetAsync(this IDistributedCache cache, + string key, + Func> getAsyncFunc, + int cacheSeconds, + CancellationToken token = default) { Check.GreaterThan(cacheSeconds, nameof(cacheSeconds), 0); DistributedCacheEntryOptions options = new DistributedCacheEntryOptions(); options.SetAbsoluteExpiration(TimeSpan.FromSeconds(cacheSeconds)); - return cache.GetAsync(key, getAsyncFunc, options); + return cache.GetAsync(key, getAsyncFunc, options, token); } - + /// /// 移除指定键的缓存项 /// @@ -193,14 +241,14 @@ public static void Remove(this IDistributedCache cache, params string[] keys) /// /// 移除指定键的缓存项 /// - public static async Task RemoveAsync(this IDistributedCache cache, params string[] keys) + public static async Task RemoveAsync(this IDistributedCache cache, CancellationToken token = default, params string[] keys) { Check.NotNull(keys, nameof(keys)); foreach (string key in keys) { - await cache.RemoveAsync(key); + await cache.RemoveAsync(key, token); } } - + } } diff --git a/src/OSharp.Utils/Extensions/StringExtensions.cs b/src/OSharp.Utils/Extensions/StringExtensions.cs index 733b5e1b..45ad3261 100644 --- a/src/OSharp.Utils/Extensions/StringExtensions.cs +++ b/src/OSharp.Utils/Extensions/StringExtensions.cs @@ -1,4 +1,4 @@ -// ----------------------------------------------------------------------- +// ----------------------------------------------------------------------- // // Copyright (c) 2014 OSharp. All rights reserved. // @@ -327,7 +327,7 @@ public static bool IsIdentityCardId(this string value) /// 是否按严格格式验证 public static bool IsMobileNumber(this string value, bool isRestrict = false) { - string pattern = isRestrict ? @"^[1][3-8]\d{9}$" : @"^[1]\d{10}$"; + string pattern = isRestrict ? @"^1[3-9]\d{9}$" : @"^1\d{10}$"; return value.IsMatch(pattern); } @@ -956,4 +956,4 @@ public static double GetSimilarityWith(this string source, string target, bool i #endregion } -} \ No newline at end of file +} diff --git a/src/OSharp.Utils/Localized/LocalizedDescriptionAttribute.cs b/src/OSharp.Utils/Localized/LocalizedDescriptionAttribute.cs new file mode 100644 index 00000000..3f122645 --- /dev/null +++ b/src/OSharp.Utils/Localized/LocalizedDescriptionAttribute.cs @@ -0,0 +1,44 @@ +// ----------------------------------------------------------------------- +// +// Copyright (c) 2014-2024 OSharp. All rights reserved. +// +// http://www.osharp.org +// gmf +// 2024-09-06 10:09 +// ----------------------------------------------------------------------- + +using System; +using System.ComponentModel; +using System.Globalization; +using System.Resources; + + +namespace OSharp.Localized +{ + /// + /// 本地化描述类特性 + /// + [AttributeUsage(AttributeTargets.All)] + public class LocalizedDescriptionAttribute : DescriptionAttribute + { + private readonly string _resourceKey; + private readonly ResourceManager _resourceManager; + + public LocalizedDescriptionAttribute(string resourceKey, Type resourceType) + { + _resourceKey = resourceKey; + _resourceManager = new ResourceManager(resourceType); + } + + /// Gets the description stored in this attribute. + /// The description stored in this attribute. + public override string Description + { + get + { + var description = _resourceManager.GetString(_resourceKey, CultureInfo.CurrentCulture); + return string.IsNullOrEmpty(description) ? $"[{_resourceKey}]" : description; + } + } + } +} diff --git a/src/OSharp.Utils/OSharp.Utils.csproj b/src/OSharp.Utils/OSharp.Utils.csproj index 845481ae..7dd268a4 100644 --- a/src/OSharp.Utils/OSharp.Utils.csproj +++ b/src/OSharp.Utils/OSharp.Utils.csproj @@ -15,27 +15,27 @@ - - + + - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + diff --git a/src/OSharp.Utils/Reflection/TypeExtensions.cs b/src/OSharp.Utils/Reflection/TypeExtensions.cs index 8c078e88..26fc47a5 100644 --- a/src/OSharp.Utils/Reflection/TypeExtensions.cs +++ b/src/OSharp.Utils/Reflection/TypeExtensions.cs @@ -1,4 +1,4 @@ -// ----------------------------------------------------------------------- +// ----------------------------------------------------------------------- // // Copyright (c) 2014-2015 OSharp. All rights reserved. // @@ -21,6 +21,7 @@ using OSharp.Data; using OSharp.Extensions; +using OSharp.Localized; namespace OSharp.Reflection @@ -104,6 +105,11 @@ public static string GetDescription(this Type type, bool inherit = true) /// 返回Description特性描述信息,如不存在则返回成员的名称 public static string GetDescription(this MemberInfo member, bool inherit = true) { + LocalizedDescriptionAttribute localizedDesc = member.GetAttribute(inherit); + if (localizedDesc != null) + { + return localizedDesc.Description; + } DescriptionAttribute desc = member.GetAttribute(inherit); if (desc != null) { @@ -443,4 +449,4 @@ private static void ProcessGenericType(StringBuilder builder, Type type, Type[] #endregion } -} \ No newline at end of file +} diff --git a/src/OSharp.Wpf/OSharp.Wpf.csproj b/src/OSharp.Wpf/OSharp.Wpf.csproj index 6ebe38d0..f0cde2a8 100644 --- a/src/OSharp.Wpf/OSharp.Wpf.csproj +++ b/src/OSharp.Wpf/OSharp.Wpf.csproj @@ -17,18 +17,18 @@ - - - + + + - + - + - + diff --git a/src/OSharp/Authorization/DataAuthService.cs b/src/OSharp/Authorization/DataAuthService.cs index e7cb4d3c..7f32d315 100644 --- a/src/OSharp/Authorization/DataAuthService.cs +++ b/src/OSharp/Authorization/DataAuthService.cs @@ -45,6 +45,8 @@ public DataAuthService(IServiceProvider provider) /// protected ScopedDictionary ScopedDictionary => _provider.GetService(); + protected IList IgnoreDataAuthTypes { get; } = new List(); + /// /// 获取指定实体的数据权限过滤表达式 /// @@ -111,7 +113,7 @@ public Expression> GetDataFilter(DataAuthOperation operation, F /// 是否有权限 public bool CheckDataAuth(DataAuthOperation operation, params TEntity[] entities) { - if (entities.Length == 0) + if (entities.Length == 0 || IgnoreDataAuthTypes.Contains(typeof(TEntity))) { return true; } @@ -121,4 +123,13 @@ public bool CheckDataAuth(DataAuthOperation operation, params TEntity[] bool has = entities.All(func); return has; } -} \ No newline at end of file + + /// + /// 设置当前请求中忽略数据权限验证的实体类型 + /// + /// 实体类型 + public void SetIgnoreDataAuth(Type entityType) + { + IgnoreDataAuthTypes.AddIfNotExist(entityType); + } +} diff --git a/src/OSharp/Authorization/IDataAuthService.cs b/src/OSharp/Authorization/IDataAuthService.cs index d1a3d2ce..5445b233 100644 --- a/src/OSharp/Authorization/IDataAuthService.cs +++ b/src/OSharp/Authorization/IDataAuthService.cs @@ -31,4 +31,10 @@ public interface IDataAuthService /// 待检测的实体数据 /// 是否有权限 bool CheckDataAuth(DataAuthOperation operation, params TEntity[] entities); -} \ No newline at end of file + + /// + /// 设置当前请求中忽略数据权限验证的实体类型 + /// + /// 实体类型 + void SetIgnoreDataAuth(Type entityType); +} diff --git a/src/OSharp/Core/Systems/KeyValueStore.cs b/src/OSharp/Core/Systems/KeyValueStore.cs index 2c1de32f..2ab9b16e 100644 --- a/src/OSharp/Core/Systems/KeyValueStore.cs +++ b/src/OSharp/Core/Systems/KeyValueStore.cs @@ -46,7 +46,7 @@ public KeyValueStore(IServiceProvider provider) Type type = typeof(TSetting); foreach (PropertyInfo property in type.GetProperties(BindingFlags.Public | BindingFlags.Instance).Where(m => m.PropertyType == typeof(IKeyValue))) { - string key = ((KeyValue)property.GetValue(setting)).Key; + string key = ((KeyValue)property.GetValue(setting))?.Key; IKeyValue keyValue = GetByKey(key); if (keyValue != null) { @@ -78,7 +78,7 @@ public async Task SaveSetting(ISetting setting) public IKeyValue[] GetByRootKey(string rootKey) { string[] keys = GetKeys(rootKey); - return keys.Select(key => GetByKey(key)).Where(value => value != null).ToArray(); + return keys.Select(GetByKey).Where(value => value != null).ToArray(); } /// @@ -103,7 +103,7 @@ public IKeyValue GetByKey(string key) /// 检查谓语表达式 /// 更新的键值对信息编号 /// 键值对信息是否存在 - public Task CheckExists(Expression> predicate, Guid id = default(Guid)) + public Task CheckExists(Expression> predicate, Guid id = default) { return KeyValueRepository.CheckExistsAsync(predicate, id); } @@ -158,10 +158,10 @@ public async Task CreateOrUpdate(params IKeyValue[] dtos) } } - unitOfWork.Commit(); + await unitOfWork.CommitAsync(); - string[] cacheKeys = removeKeys.Select(m => GetCacheKey(m)).ToArray(); - await Cache.RemoveAsync(cacheKeys); + string[] cacheKeys = removeKeys.Select(GetCacheKey).ToArray(); + await Cache.RemoveAsync(default, cacheKeys); return OperationResult.Success; } @@ -194,10 +194,10 @@ public async Task Delete(params Guid[] ids) removeKeys.AddIf(pair.Key, count > 0); } - unitOfWork.Commit(); + await unitOfWork.CommitAsync(); - string[] cacheKeys = removeKeys.Select(m => GetCacheKey(m)).ToArray(); - await Cache.RemoveAsync(cacheKeys); + string[] cacheKeys = removeKeys.Select(GetCacheKey).ToArray(); + await Cache.RemoveAsync(default, cacheKeys); return OperationResult.Success; } @@ -224,4 +224,4 @@ private static string GetCacheKey(string key) { return $"Systems:KeyValues:{key}"; } -} \ No newline at end of file +} diff --git a/src/OSharp/Dependency/ScopedDictionary.cs b/src/OSharp/Dependency/ScopedDictionary.cs index c5ab220b..6c0081f5 100644 --- a/src/OSharp/Dependency/ScopedDictionary.cs +++ b/src/OSharp/Dependency/ScopedDictionary.cs @@ -42,4 +42,4 @@ public void Dispose() Identity = null; this.Clear(); } -} \ No newline at end of file +} diff --git a/src/OSharp/OSharp.csproj b/src/OSharp/OSharp.csproj index 96064968..885342d7 100644 --- a/src/OSharp/OSharp.csproj +++ b/src/OSharp/OSharp.csproj @@ -13,7 +13,7 @@ - + diff --git a/tests/Liuliu.Demo.Core.Tests/Liuliu.Demo.Core.Tests.csproj b/tests/Liuliu.Demo.Core.Tests/Liuliu.Demo.Core.Tests.csproj index d22da2aa..5aeb3bf2 100644 --- a/tests/Liuliu.Demo.Core.Tests/Liuliu.Demo.Core.Tests.csproj +++ b/tests/Liuliu.Demo.Core.Tests/Liuliu.Demo.Core.Tests.csproj @@ -7,8 +7,8 @@ - - + + diff --git a/tests/OSharp.AspNetCore.Tests/OSharp.AspNetCore.Tests.csproj b/tests/OSharp.AspNetCore.Tests/OSharp.AspNetCore.Tests.csproj index cd28058f..53ec0f43 100644 --- a/tests/OSharp.AspNetCore.Tests/OSharp.AspNetCore.Tests.csproj +++ b/tests/OSharp.AspNetCore.Tests/OSharp.AspNetCore.Tests.csproj @@ -12,7 +12,7 @@ - + diff --git a/tests/OSharp.AutoMapper.Tests/OSharp.AutoMapper.Tests.csproj b/tests/OSharp.AutoMapper.Tests/OSharp.AutoMapper.Tests.csproj index 6c6f4dc2..4bd9912c 100644 --- a/tests/OSharp.AutoMapper.Tests/OSharp.AutoMapper.Tests.csproj +++ b/tests/OSharp.AutoMapper.Tests/OSharp.AutoMapper.Tests.csproj @@ -7,7 +7,7 @@ - + diff --git a/tests/OSharp.Tests/OSharp.Tests.csproj b/tests/OSharp.Tests/OSharp.Tests.csproj index 17215158..be199819 100644 --- a/tests/OSharp.Tests/OSharp.Tests.csproj +++ b/tests/OSharp.Tests/OSharp.Tests.csproj @@ -6,7 +6,7 @@ - + diff --git a/tests/OSharp.UnitTest.Infrastructure/OSharp.UnitTest.Infrastructure.csproj b/tests/OSharp.UnitTest.Infrastructure/OSharp.UnitTest.Infrastructure.csproj index 99f34341..9ee991ee 100644 --- a/tests/OSharp.UnitTest.Infrastructure/OSharp.UnitTest.Infrastructure.csproj +++ b/tests/OSharp.UnitTest.Infrastructure/OSharp.UnitTest.Infrastructure.csproj @@ -6,14 +6,14 @@ - - - + + + all runtime; build; native; contentfiles; analyzers; buildtransitive - - + + all runtime; build; native; contentfiles; analyzers; buildtransitive @@ -21,7 +21,7 @@ - +