Отдавать в /api/request-type-access список SharePoint-списков типа
Доступ здесь настраивает только видимость в UI approval-route — права SharePoint остаются ручным шагом, и раньше администратору приходилось отдельно смотреть, в какие списки данных (архив + текущая партиция) заводить чтение для email. Теперь RequestTypeAccessDto несёт готовую серию (переиспользует ListPartitionService), и админка показывает её колонкой в таблице. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,5 +1,18 @@
|
||||
using Tnsu.ApprovalRoute.Application.ListPartitioning;
|
||||
|
||||
namespace Tnsu.ApprovalRoute.Application.RequestTypeAccesses;
|
||||
|
||||
public sealed record RequestTypeAccessDto(int Id, int RequestTypeId, string Email);
|
||||
/// <param name="SharePointLists">
|
||||
/// Вся серия SharePoint-списков данных (архив + текущая партиция) типа заявки —
|
||||
/// именно на них нужно выдать email'у право чтения, иначе поиск по порталу
|
||||
/// продолжит отдавать только его собственные заявки: доступ здесь настраивает
|
||||
/// видимость в UI approval-route, но не права SharePoint, которые остаются
|
||||
/// отдельным ручным шагом.
|
||||
/// </param>
|
||||
public sealed record RequestTypeAccessDto(
|
||||
int Id,
|
||||
int RequestTypeId,
|
||||
string Email,
|
||||
IReadOnlyList<RequestListPartitionDto> SharePointLists);
|
||||
|
||||
public sealed record CreateRequestTypeAccessRequest(int RequestTypeId, string Email);
|
||||
|
||||
+33
-4
@@ -3,26 +3,53 @@ using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Tnsu.ApprovalRoute.Application.Common.Errors;
|
||||
using Tnsu.ApprovalRoute.Application.Common.Interfaces;
|
||||
using Tnsu.ApprovalRoute.Application.ListPartitioning;
|
||||
using Tnsu.ApprovalRoute.Domain.Entities;
|
||||
using Tnsu.ApprovalRoute.Infrastructure.Persistence;
|
||||
|
||||
namespace Tnsu.ApprovalRoute.Application.RequestTypeAccesses;
|
||||
|
||||
public sealed class RequestTypeAccessService(
|
||||
ApprovalRouteDbContext db, ICurrentUser currentUser, ILogger<RequestTypeAccessService> logger)
|
||||
ApprovalRouteDbContext db,
|
||||
ListPartitionService partitions,
|
||||
ICurrentUser currentUser,
|
||||
ILogger<RequestTypeAccessService> logger)
|
||||
{
|
||||
public async Task<Result<IReadOnlyList<RequestTypeAccessDto>>> ListAsync(
|
||||
int? requestTypeId, CancellationToken cancellationToken)
|
||||
{
|
||||
var items = await db.RequestTypeAccesses.AsNoTracking()
|
||||
var entities = await db.RequestTypeAccesses.AsNoTracking()
|
||||
.Where(x => requestTypeId == null || x.RequestTypeId == requestTypeId)
|
||||
.OrderBy(x => x.RequestTypeId).ThenBy(x => x.Email)
|
||||
.Select(x => new RequestTypeAccessDto(x.Id, x.RequestTypeId, x.Email))
|
||||
.ToListAsync(cancellationToken);
|
||||
|
||||
// Партиции запрашиваются РАЗ на тип заявки, а не на строку — иначе список
|
||||
// из N email по одному типу заново обходил бы SharePoint N раз подряд.
|
||||
var listsByType = new Dictionary<int, IReadOnlyList<RequestListPartitionDto>>();
|
||||
var items = new List<RequestTypeAccessDto>(entities.Count);
|
||||
foreach (var e in entities)
|
||||
{
|
||||
var lists = await GetListsCachedAsync(listsByType, e.RequestTypeId, cancellationToken);
|
||||
items.Add(new RequestTypeAccessDto(e.Id, e.RequestTypeId, e.Email, lists));
|
||||
}
|
||||
|
||||
return Result.Ok<IReadOnlyList<RequestTypeAccessDto>>(items);
|
||||
}
|
||||
|
||||
private async Task<IReadOnlyList<RequestListPartitionDto>> GetListsCachedAsync(
|
||||
Dictionary<int, IReadOnlyList<RequestListPartitionDto>> cache,
|
||||
int requestTypeId,
|
||||
CancellationToken cancellationToken)
|
||||
{
|
||||
if (cache.TryGetValue(requestTypeId, out var cached))
|
||||
return cached;
|
||||
|
||||
var result = await partitions.ListAsync(requestTypeId, cancellationToken);
|
||||
var lists = result.IsSuccess ? result.Value : Array.Empty<RequestListPartitionDto>();
|
||||
cache[requestTypeId] = lists;
|
||||
return lists;
|
||||
}
|
||||
|
||||
/// <summary>Список email'ов с доступом к типу заявок — дёргает Power Automate.</summary>
|
||||
public async Task<Result<IReadOnlyList<string>>> ListEmailsAsync(int requestTypeId, CancellationToken cancellationToken)
|
||||
{
|
||||
@@ -58,7 +85,9 @@ public sealed class RequestTypeAccessService(
|
||||
"Доступ к типу заявки {RequestTypeId} выдан {Email} пользователем {Author}",
|
||||
entity.RequestTypeId, entity.Email, currentUser.Email);
|
||||
|
||||
return Result.Ok(new RequestTypeAccessDto(entity.Id, entity.RequestTypeId, entity.Email));
|
||||
var listsResult = await partitions.ListAsync(entity.RequestTypeId, cancellationToken);
|
||||
var lists = listsResult.IsSuccess ? listsResult.Value : Array.Empty<RequestListPartitionDto>();
|
||||
return Result.Ok(new RequestTypeAccessDto(entity.Id, entity.RequestTypeId, entity.Email, lists));
|
||||
}
|
||||
|
||||
public async Task<Result> DeleteAsync(int id, CancellationToken cancellationToken)
|
||||
|
||||
Reference in New Issue
Block a user