forked from ddrilling/AsbCloudServer
#7205798 fix
This commit is contained in:
parent
6ac073d59a
commit
408429a0b5
@ -5,7 +5,6 @@ using AsbCloudApp.Repositories;
|
|||||||
using AsbCloudDb;
|
using AsbCloudDb;
|
||||||
using AsbCloudDb.Model;
|
using AsbCloudDb.Model;
|
||||||
using AsbCloudInfrastructure.EfCache;
|
using AsbCloudInfrastructure.EfCache;
|
||||||
using DocumentFormat.OpenXml.Drawing;
|
|
||||||
using Mapster;
|
using Mapster;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
using System;
|
using System;
|
||||||
@ -51,31 +50,31 @@ namespace AsbCloudInfrastructure.Repository
|
|||||||
|
|
||||||
public async Task<IEnumerable<UserRoleDto>> GetAllAsync(CancellationToken token)
|
public async Task<IEnumerable<UserRoleDto>> GetAllAsync(CancellationToken token)
|
||||||
{
|
{
|
||||||
var dtos = await GetCacheUserRoleAsync(token)
|
var entities = await GetCacheUserRoleAsync(token)
|
||||||
.ConfigureAwait(false);
|
.ConfigureAwait(false);
|
||||||
|
|
||||||
if (dtos is null)
|
if (entities is null)
|
||||||
return Enumerable.Empty<UserRoleDto>();
|
return Enumerable.Empty<UserRoleDto>();
|
||||||
|
|
||||||
return dtos.Select(Convert);
|
return entities.Select(Convert);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public UserRoleDto? GetOrDefault(int id)
|
public UserRoleDto? GetOrDefault(int id)
|
||||||
{
|
{
|
||||||
var dto = GetCacheUserRole().FirstOrDefault(x => x.Id == id);
|
var entity = GetCacheUserRole().FirstOrDefault(x => x.Id == id);
|
||||||
if (dto is null)
|
if (entity is null)
|
||||||
return null;
|
return null;
|
||||||
return Convert(dto);
|
return Convert(entity);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<UserRoleDto?> GetOrDefaultAsync(int id, CancellationToken token)
|
public async Task<UserRoleDto?> GetOrDefaultAsync(int id, CancellationToken token)
|
||||||
{
|
{
|
||||||
var dto = (await GetCacheUserRoleAsync(token)
|
var entity = (await GetCacheUserRoleAsync(token)
|
||||||
.ConfigureAwait(false)).FirstOrDefault(r => r.Id == id);
|
.ConfigureAwait(false)).FirstOrDefault(r => r.Id == id);
|
||||||
if (dto is null)
|
if (entity is null)
|
||||||
return null;
|
return null;
|
||||||
return Convert(dto);
|
return Convert(entity);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<IEnumerable<UserRoleDto>> GetByNamesAsync(IEnumerable<string> names, CancellationToken token)
|
public async Task<IEnumerable<UserRoleDto>> GetByNamesAsync(IEnumerable<string> names, CancellationToken token)
|
||||||
@ -83,13 +82,13 @@ namespace AsbCloudInfrastructure.Repository
|
|||||||
if (names?.Any() != true)
|
if (names?.Any() != true)
|
||||||
return Enumerable.Empty<UserRoleDto>();
|
return Enumerable.Empty<UserRoleDto>();
|
||||||
|
|
||||||
var dtos = (await GetCacheUserRoleAsync(token))
|
var entities = (await GetCacheUserRoleAsync(token))
|
||||||
.Where(r => names.Contains(r.Caption));
|
.Where(r => names.Contains(r.Caption));
|
||||||
|
|
||||||
if (dtos?.Count() != names.Count())
|
if (entities?.Count() != names.Count())
|
||||||
throw new ArgumentInvalidException("Invalid role names", nameof(names));
|
throw new ArgumentInvalidException("Invalid role names", nameof(names));
|
||||||
|
|
||||||
return dtos.Select(Convert);
|
return entities.Select(Convert);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<int> UpdateAsync(UserRoleDto dto, CancellationToken token)
|
public async Task<int> UpdateAsync(UserRoleDto dto, CancellationToken token)
|
||||||
@ -129,12 +128,11 @@ namespace AsbCloudInfrastructure.Repository
|
|||||||
|
|
||||||
public async Task<int> DeleteAsync(int id, CancellationToken token)
|
public async Task<int> DeleteAsync(int id, CancellationToken token)
|
||||||
{
|
{
|
||||||
var dto = (await GetCacheUserRoleAsync(token)).FirstOrDefault(r => r.Id == id);
|
var entity = (await GetCacheUserRoleAsync(token)).FirstOrDefault(r => r.Id == id);
|
||||||
|
|
||||||
if (dto is not null)
|
if (entity is not null)
|
||||||
{
|
{
|
||||||
var entity = Convert(dto);
|
var removeEntity = dbContext.UserRoles.Remove(entity);
|
||||||
var removeEntity = dbContext.UserRoles.Remove(Convert(entity));
|
|
||||||
await dbContext.SaveChangesAsync(token);
|
await dbContext.SaveChangesAsync(token);
|
||||||
DropCacheUserRole();
|
DropCacheUserRole();
|
||||||
return removeEntity?.Entity?.Id ?? 0;
|
return removeEntity?.Entity?.Id ?? 0;
|
||||||
@ -170,12 +168,11 @@ namespace AsbCloudInfrastructure.Repository
|
|||||||
return true;
|
return true;
|
||||||
|
|
||||||
var idPermissionInfo = permissionInfo.Id;
|
var idPermissionInfo = permissionInfo.Id;
|
||||||
var dtos = GetCacheUserRole()
|
var entities = GetCacheUserRole()
|
||||||
.Where(r => rolesIds.Contains(r.Id));
|
.Where(r => rolesIds.Contains(r.Id));
|
||||||
var roles = dtos.Select(Convert);
|
|
||||||
|
|
||||||
foreach (var role in roles)
|
foreach (var role in entities)
|
||||||
if (HasPermission(Convert(role), idPermissionInfo))
|
if (HasPermission(role, idPermissionInfo))
|
||||||
return true;
|
return true;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -190,10 +187,9 @@ namespace AsbCloudInfrastructure.Repository
|
|||||||
|
|
||||||
foreach (var relation in userRole.RelationUserRoleUserRoles)
|
foreach (var relation in userRole.RelationUserRoleUserRoles)
|
||||||
{
|
{
|
||||||
var dto = GetCacheUserRole()
|
var entity = GetCacheUserRole()
|
||||||
.First(p => p.Id == relation.IdInclude);
|
.First(p => p.Id == relation.IdInclude);
|
||||||
var includedRole = Convert(dto);
|
if (HasPermission(entity, idPermission, --recursionLevel))
|
||||||
if (HasPermission(Convert(includedRole), idPermission, --recursionLevel))
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
@ -65,7 +65,7 @@ namespace ConsoleApp1
|
|||||||
=> new TelemetryTracker(CacheDb, ConfigurationService);
|
=> new TelemetryTracker(CacheDb, ConfigurationService);
|
||||||
|
|
||||||
public static TelemetryService MakeTelemetryService()
|
public static TelemetryService MakeTelemetryService()
|
||||||
=> new TelemetryService(Context, MakeTelemetryTracker(), TimezoneService, CacheDb);
|
=> new TelemetryService(Context, MakeTelemetryTracker(), TimezoneService);
|
||||||
|
|
||||||
public static WellService MakeWellService()
|
public static WellService MakeWellService()
|
||||||
=> new WellService(Context, CacheDb, MakeTelemetryService(), TimezoneService);
|
=> new WellService(Context, CacheDb, MakeTelemetryService(), TimezoneService);
|
||||||
|
Loading…
Reference in New Issue
Block a user