Skip to content

Commit

Permalink
bug: 修复EntityRole的FilterGroup为null时的异常
Browse files Browse the repository at this point in the history
  • Loading branch information
gmf520 committed Feb 27, 2024
1 parent 3b211ee commit 8e82062
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 27 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// -----------------------------------------------------------------------
// -----------------------------------------------------------------------
// <copyright file="EntityRoleOutputDto.cs" company="OSharp开源团队">
// Copyright (c) 2014-2018 OSharp. All rights reserved.
// </copyright>
Expand Down Expand Up @@ -43,7 +43,7 @@ public EntityRoleOutputDto(EntityRole entityRole)
IsLocked = entityRole.IsLocked;
Operation = entityRole.Operation;
CreatedTime = entityRole.CreatedTime;
FilterGroup = entityRole.FilterGroupJson.FromJsonString<FilterGroup>();
FilterGroup = entityRole.FilterGroup;
}

/// <summary>
Expand Down
6 changes: 5 additions & 1 deletion src/OSharp.Authorization.Datas/DataAuthCacheBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,11 @@ public virtual void BuildCaches()

foreach (var entityRole in entityRoles)
{
FilterGroup filterGroup = entityRole.FilterGroupJson.FromJsonString<FilterGroup>();
FilterGroup filterGroup = entityRole.FilterGroupJson?.FromJsonString<FilterGroup>();
if (filterGroup == null)
{
continue;
}
string key = GetKey(entityRole.RoleName, entityRole.EntityTypeFullName, entityRole.Operation);
string name = GetName(entityRole.RoleName, entityRole.EntityTypeFullName, entityRole.Operation);

Expand Down
24 changes: 1 addition & 23 deletions src/OSharp.Authorization.Datas/DataAuthorizationManagerBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,6 @@ public virtual async Task<OperationResult> CreateEntityRoles(params TEntityRoleI
{
Check2.Validate<TEntityRoleInputDto, Guid>(dtos, nameof(dtos));

DataAuthCacheRefreshEventData eventData = new DataAuthCacheRefreshEventData();
OperationResult result = await EntityRoleRepository.InsertAsync(dtos,
async dto =>
{
Expand All @@ -143,28 +142,7 @@ public virtual async Task<OperationResult> CreateEntityRoles(params TEntityRoleI
throw new OsharpException($"角色“{role.Name}”和实体“{entityInfo.Name}”和操作“{dto.Operation}”的数据权限规则已存在,不能重复添加");
}
},
async (dto, entity) =>
{
if (!dto.IsLocked)
{
TRole role = await RoleRepository.GetAsync(dto.RoleId);
TEntityInfo entityInfo = await EntityInfoRepository.GetAsync(dto.EntityId);
eventData.SetItems.Add(new DataAuthCacheItem()
{
RoleName = role.Name,
EntityTypeFullName = entityInfo.TypeName,
Operation = entity.Operation,
FilterGroup = entity.FilterGroup
});
}
return entity;
});
if (result.Succeeded && eventData.HasData())
{
await EventBus.PublishAsync(eventData);
}

return result;
}
Expand Down Expand Up @@ -211,7 +189,7 @@ public virtual async Task<OperationResult> UpdateEntityRoles(params TEntityRoleI
{
eventData.RemoveItems.Add(cacheItem);
}
else
else if(entity.FilterGroup != null)
{
eventData.SetItems.Add(cacheItem);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public EntityRoleOutputDto(EntityRole entityRole)
IsLocked = entityRole.IsLocked;
Operation = entityRole.Operation;
CreatedTime = entityRole.CreatedTime;
FilterGroup = entityRole.FilterGroupJson.FromJsonString<FilterGroup>();
FilterGroup = entityRole.FilterGroup;
}

/// <summary>
Expand Down

0 comments on commit 8e82062

Please sign in to comment.