Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,19 @@ public MappingProfile()
{
CreateMap<DialogEntity, DialogDto>()
.ForMember(dest => dest.Status, opt => opt.MapFrom(src => src.StatusId))
.ForMember(dest => dest.SystemLabel, opt => opt.MapFrom(src => src.EndUserContext.SystemLabelId))
.ForMember(dest => dest.SystemLabel, opt => opt
.MapFrom(src => src.EndUserContext != null
? src.EndUserContext.SystemLabelId
: SystemLabel.Values.Default))
.ForMember(dest => dest.FromPartyTransmissionsCount, opt => opt
.MapFrom(src => (int)src.FromPartyTransmissionsCount))
.ForMember(dest => dest.FromServiceOwnerTransmissionsCount, opt => opt
.MapFrom(src => (int)src.FromServiceOwnerTransmissionsCount))
.ForMember(dest => dest.SeenSinceLastUpdate, opt => opt.Ignore());

CreateMap<DialogEndUserContext, DialogEndUserContextDto>()
.ForMember(dest => dest.SystemLabels, opt => opt.MapFrom(src => new List<SystemLabel.Values> { src.SystemLabelId }));
.ForMember(dest => dest.SystemLabels, opt => opt
.MapFrom(src => new List<SystemLabel.Values> { src.SystemLabelId }));

CreateMap<DialogSeenLog, DialogSeenLogDto>()
.ForMember(dest => dest.SeenAt, opt => opt.MapFrom(src => src.CreatedAt));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,15 @@ public MappingProfile()
.Count(x => x.Urls
.Any(url => url.ConsumerTypeId == AttachmentUrlConsumerType.Values.Gui))))
.ForMember(dest => dest.Content, opt => opt.MapFrom(src => src.Content.Where(x => x.Type.OutputInList)))
.ForMember(dest => dest.SystemLabel, opt => opt.MapFrom(src => src.EndUserContext.SystemLabelId))
.ForMember(dest => dest.SystemLabel, opt => opt
.MapFrom(src => src.EndUserContext != null
? src.EndUserContext.SystemLabelId
: SystemLabel.Values.Default))
.ForMember(dest => dest.Status, opt => opt.MapFrom(src => src.StatusId));

CreateMap<DialogEndUserContext, DialogEndUserContextDto>()
.ForMember(dest => dest.SystemLabels, opt => opt.MapFrom(src => new List<SystemLabel.Values> { src.SystemLabelId }));
.ForMember(dest => dest.SystemLabels, opt => opt
.MapFrom(src => new List<SystemLabel.Values> { src.SystemLabelId }));

CreateMap<DialogSeenLog, DialogSeenLogDto>()
.ForMember(dest => dest.SeenAt, opt => opt.MapFrom(src => src.CreatedAt));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,11 +191,15 @@ public async Task<SearchDialogResult> Handle(SearchDialogQuery request, Cancella
.WhereIf(request.DueAfter.HasValue, x => request.DueAfter <= x.DueAt)
.WhereIf(request.DueBefore.HasValue, x => x.DueAt <= request.DueBefore)
.WhereIf(request.Process is not null, x => EF.Functions.ILike(x.Process!, request.Process!))
.WhereIf(!request.SystemLabel.IsNullOrEmpty(), x => request.SystemLabel!.Contains(x.EndUserContext.SystemLabelId))
.WhereIf(
!request.SystemLabel.IsNullOrEmpty(),
x => request.SystemLabel!.Contains(
x.EndUserContext != null
? x.EndUserContext.SystemLabelId
: SystemLabel.Values.Default))
.WhereIf(request.Search is not null, x =>
x.Content.Any(x => x.Value.Localizations.AsQueryable().Any(searchExpression)) ||
x.SearchTags.Any(x => EF.Functions.ILike(x.Value, request.Search!))
)
x.SearchTags.Any(x => EF.Functions.ILike(x.Value, request.Search!)))
.WhereIf(request.ExcludeApiOnly == true, x => !x.IsApiOnly)
.Where(x => !x.VisibleFrom.HasValue || _clock.UtcNowOffset > x.VisibleFrom)
.Where(x => !x.ExpiresAt.HasValue || x.ExpiresAt > _clock.UtcNowOffset)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ private async Task UpdateDialogs(
var userInfo = await _userRegistry.GetCurrentUserInformation(cancellationToken);
foreach (var (dto, entity) in updateSets)
{
entity.EndUserContext.UpdateLabel(newLabel, userInfo.UserId.ExternalIdWithPrefix);
entity.UpdateSystemLabel(userInfo.UserId.ExternalIdWithPrefix, newLabel);
_unitOfWork.EnableConcurrencyCheck(entity.EndUserContext, dto.EndUserContextRevision);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public sealed class SetSystemLabelCommand : IRequest<SetSystemLabelResult>
{
public Guid DialogId { get; set; }
public Guid? IfMatchEndUserContextRevision { get; set; }
public IReadOnlyCollection<SystemLabel.Values> SystemLabels { get; set; } = Array.Empty<SystemLabel.Values>();
public IReadOnlyCollection<SystemLabel.Values> SystemLabels { get; set; } = [];
}

public sealed record SetSystemLabelSuccess(Guid Revision);
Expand Down Expand Up @@ -64,21 +64,16 @@ public async Task<SetSystemLabelResult> Handle(

var currentUserInformation = await _userRegistry.GetCurrentUserInformation(cancellationToken);

var newLabel = request.SystemLabels.Count switch // The domain model currently only supports one system label
{
0 => SystemLabel.Values.Default,
1 => request.SystemLabels.First(),
_ => throw new UnreachableException() // Should be caught in validator
};
var newLabel = request.SystemLabels.SingleOrDefault(SystemLabel.Values.Default);

dialog.EndUserContext.UpdateLabel(newLabel, currentUserInformation.UserId.ExternalIdWithPrefix);
dialog.UpdateSystemLabel(currentUserInformation.UserId.ExternalIdWithPrefix, newLabel);

var saveResult = await _unitOfWork
.EnableConcurrencyCheck(dialog.EndUserContext, request.IfMatchEndUserContextRevision)
.SaveChangesAsync(cancellationToken);

return saveResult.Match<SetSystemLabelResult>(
_ => new SetSystemLabelSuccess(dialog.EndUserContext.Revision),
_ => new SetSystemLabelSuccess(dialog.EndUserContext?.Revision ?? dialog.Id),
domainError => domainError,
concurrencyError => concurrencyError);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public async Task<SearchLabelAssignmentLogResult> Handle(SearchLabelAssignmentLo
var dialog = await _dialogDbContext.Dialogs
.AsNoTracking()
.Include(x => x.EndUserContext)
.ThenInclude(x => x.LabelAssignmentLogs)
.ThenInclude(x => x!.LabelAssignmentLogs)
.ThenInclude(x => x.PerformedBy)
.ThenInclude(x => x.ActorNameEntity)
.FirstOrDefaultAsync(x => x.Id == request.DialogId, cancellationToken: cancellationToken);
Expand All @@ -62,6 +62,6 @@ public async Task<SearchLabelAssignmentLogResult> Handle(SearchLabelAssignmentLo
return new Forbidden(Constants.AltinnAuthLevelTooLow);
}

return _mapper.Map<List<LabelAssignmentLogDto>>(dialog.EndUserContext.LabelAssignmentLogs);
return _mapper.Map<List<LabelAssignmentLogDto>>(dialog.EndUserContext?.LabelAssignmentLogs ?? []);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using Digdir.Domain.Dialogporten.Application.Features.V1.ServiceOwner.Common;
using Digdir.Domain.Dialogporten.Domain.Actors;
using Digdir.Domain.Dialogporten.Domain.Common;
using Digdir.Domain.Dialogporten.Domain.DialogEndUserContexts.Entities;
using Digdir.Domain.Dialogporten.Domain.Dialogs.Entities;
using Digdir.Domain.Dialogporten.Domain.Dialogs.Entities.Transmissions;
using Digdir.Domain.Dialogporten.Domain.DialogServiceOwnerContexts.Entities;
Expand Down Expand Up @@ -89,7 +90,7 @@ public async Task<CreateDialogResult> Handle(CreateDialogCommand request, Cancel
return new Conflict(nameof(dialog.IdempotentKey), $"'{dialog.IdempotentKey}' already exists with DialogId '{dialogId}'");
}

CreateDialogEndUserContext(request, dialog);
UpdateSystemLabel(request, dialog);
CreateDialogServiceOwnerContext(request, dialog);

var activityTypes = dialog.Activities
Expand Down Expand Up @@ -150,23 +151,17 @@ is DialogTransmissionType.Values.Submission
return dialogId == Guid.Empty ? null : dialogId;
}

private void CreateDialogEndUserContext(CreateDialogCommand request, DialogEntity dialog)
private void UpdateSystemLabel(CreateDialogCommand request, DialogEntity dialog)
{
dialog.EndUserContext = new();
if (!request.Dto.SystemLabel.HasValue)
{
return;
}

if (!_user.TryGetOrganizationNumber(out var organizationNumber))
{
_domainContext.AddError(new DomainFailure(nameof(organizationNumber), "Cannot find organization number for current user."));
return;
}

dialog.EndUserContext.UpdateLabel(
request.Dto.SystemLabel.Value,
dialog.UpdateSystemLabel(
$"{NorwegianOrganizationIdentifier.PrefixWithSeparator}{organizationNumber}",
request.Dto.SystemLabel,
ActorType.Values.ServiceOwner);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ public async Task<UpdateDialogResult> Handle(UpdateDialogCommand request, Cancel

if (!request.IsSilentUpdate)
{
UpdateLabel(dialog);
UpdateSystemLabel(dialog);
}

var saveResult = await _unitOfWork
Expand All @@ -184,17 +184,17 @@ public async Task<UpdateDialogResult> Handle(UpdateDialogCommand request, Cancel
concurrencyError => concurrencyError);
}

private void UpdateLabel(DialogEntity dialog)
private void UpdateSystemLabel(DialogEntity dialog)
{
if (!_user.TryGetOrganizationNumber(out var organizationNumber))
{
_domainContext.AddError(new DomainFailure(nameof(organizationNumber), "Cannot find organization number for current user."));
return;
}

dialog.EndUserContext.UpdateLabel(
SystemLabel.Values.Default,
dialog.UpdateSystemLabel(
$"{NorwegianOrganizationIdentifier.PrefixWithSeparator}{organizationNumber}",
SystemLabel.Values.Default,
ActorType.Values.ServiceOwner);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,7 @@ public async Task<GetDialogResult> Handle(GetDialogQuery request, CancellationTo
.ThenInclude(x => x.SeenBy)
.ThenInclude(x => x.ActorNameEntity)
.Include(x => x.EndUserContext)
.Include(x => x.ServiceOwnerContext)
.ThenInclude(x => x.ServiceOwnerLabels.OrderBy(x => x.Value))
.Include(x => x.ServiceOwnerContext!.ServiceOwnerLabels.OrderBy(x => x.Value))
.IgnoreQueryFilters()
.WhereIf(!_userResourceRegistry.IsCurrentUserServiceOwnerAdmin(), x => resourceIds.Contains(x.ServiceResource))
.FirstOrDefaultAsync(x => x.Id == request.DialogId, cancellationToken);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,19 @@ public MappingProfile()
{
CreateMap<DialogEntity, DialogDto>()
.ForMember(dest => dest.Status, opt => opt.MapFrom(src => src.StatusId))
.ForMember(dest => dest.SystemLabel, opt => opt.MapFrom(src => src.EndUserContext.SystemLabelId))
.ForMember(dest => dest.SystemLabel, opt => opt
.MapFrom(src => src.EndUserContext != null
? src.EndUserContext.SystemLabelId
: SystemLabel.Values.Default))
.ForMember(dest => dest.FromPartyTransmissionsCount, opt => opt
.MapFrom(src => (int)src.FromPartyTransmissionsCount))
.ForMember(dest => dest.FromServiceOwnerTransmissionsCount, opt => opt
.MapFrom(src => (int)src.FromServiceOwnerTransmissionsCount))
.ForMember(dest => dest.SeenSinceLastUpdate, opt => opt.Ignore());

CreateMap<DialogEndUserContext, DialogEndUserContextDto>()
.ForMember(dest => dest.SystemLabels, opt => opt.MapFrom(src => new List<SystemLabel.Values> { src.SystemLabelId }));
.ForMember(dest => dest.SystemLabels, opt => opt
.MapFrom(src => new List<SystemLabel.Values> { src.SystemLabelId }));

CreateMap<DialogServiceOwnerContext, DialogServiceOwnerContextDto>();
CreateMap<DialogServiceOwnerLabel, DialogServiceOwnerLabelDto>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,15 @@ public MappingProfile()
.Count(x => x.Urls
.Any(url => url.ConsumerTypeId == AttachmentUrlConsumerType.Values.Gui))))
.ForMember(dest => dest.Content, opt => opt.MapFrom(src => src.Content.Where(x => x.Type.OutputInList)))
.ForMember(dest => dest.SystemLabel, opt => opt.MapFrom(src => src.EndUserContext.SystemLabelId))
.ForMember(dest => dest.SystemLabel, opt => opt
.MapFrom(src => src.EndUserContext != null
? src.EndUserContext.SystemLabelId
: SystemLabel.Values.Default))
.ForMember(dest => dest.Status, opt => opt.MapFrom(src => src.StatusId));

CreateMap<DialogEndUserContext, DialogEndUserContextDto>()
.ForMember(dest => dest.SystemLabels, opt => opt.MapFrom(src => new List<SystemLabel.Values> { src.SystemLabelId }));
.ForMember(dest => dest.SystemLabels, opt => opt
.MapFrom(src => new List<SystemLabel.Values> { src.SystemLabelId }));

CreateMap<DialogServiceOwnerContext, DialogServiceOwnerContextDto>();
CreateMap<DialogServiceOwnerLabel, ServiceOwnerLabelDto>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ public async Task<SearchDialogResult> Handle(SearchDialogQuery request, Cancella
.Include(x => x.Content)
.ThenInclude(x => x.Value.Localizations)
.Include(x => x.ServiceOwnerContext)
.ThenInclude(x => x.ServiceOwnerLabels)
.ThenInclude(x => x!.ServiceOwnerLabels)
.WhereIf(!request.ServiceResource.IsNullOrEmpty(),
x => request.ServiceResource!.Contains(x.ServiceResource))
.WhereIf(!request.Party.IsNullOrEmpty(), x => request.Party!.Contains(x.Party))
Expand All @@ -230,14 +230,19 @@ public async Task<SearchDialogResult> Handle(SearchDialogQuery request, Cancella
.WhereIf(request.Process is not null, x => EF.Functions.ILike(x.Process!, request.Process!))
.WhereIf(request.VisibleAfter.HasValue, x => request.VisibleAfter <= x.VisibleFrom)
.WhereIf(request.VisibleBefore.HasValue, x => x.VisibleFrom <= request.VisibleBefore)
.WhereIf(!request.SystemLabel.IsNullOrEmpty(), x => request.SystemLabel!.Contains(x.EndUserContext.SystemLabelId))
.WhereIf(
!request.SystemLabel.IsNullOrEmpty(),
x => request.SystemLabel!.Contains(
x.EndUserContext != null
? x.EndUserContext.SystemLabelId
: SystemLabel.Values.Default))
.WhereIf(request.Search is not null, x =>
x.Content.Any(x => x.Value.Localizations.AsQueryable().Any(searchExpression)) ||
x.SearchTags.Any(x => EF.Functions.ILike(x.Value, request.Search!))
)
x.SearchTags.Any(x => EF.Functions.ILike(x.Value, request.Search!)))
.WhereIf(request.Deleted == DeletedFilter.Exclude, x => !x.Deleted)
.WhereIf(request.Deleted == DeletedFilter.Only, x => x.Deleted)
.WhereIf(formattedServiceOwnerLabels is not null && formattedServiceOwnerLabels.Count != 0, x =>
x.ServiceOwnerContext != null &&
formattedServiceOwnerLabels!
.All(formattedLabel =>
x.ServiceOwnerContext.ServiceOwnerLabels
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public async Task<BulkSetSystemLabelResult> Handle(BulkSetSystemLabelCommand req
await _unitOfWork.BeginTransactionAsync(cancellationToken);
foreach (var dialog in dialogs)
{
dialog.EndUserContext.UpdateLabel(newLabel, userInfo.UserId.ExternalIdWithPrefix);
dialog.UpdateSystemLabel(userInfo.UserId.ExternalIdWithPrefix, newLabel);
_unitOfWork.EnableConcurrencyCheck(dialog.EndUserContext, request.Dto.Dialogs.Single(x => x.DialogId == dialog.Id).EndUserContextRevision);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public sealed class SetSystemLabelCommand : IRequest<SetSystemLabelResult>
public Guid DialogId { get; set; }
public string EndUserId { get; set; } = null!; // // See ServiceOwnerOnBehalfOfPersonMiddleware
public Guid? IfMatchEndUserContextRevision { get; set; }
public IReadOnlyCollection<SystemLabel.Values> SystemLabels { get; set; } = Array.Empty<SystemLabel.Values>();
public IReadOnlyCollection<SystemLabel.Values> SystemLabels { get; set; } = [];
}

public sealed record SetSystemLabelSuccess(Guid Revision);
Expand Down Expand Up @@ -65,21 +65,16 @@ public async Task<SetSystemLabelResult> Handle(

var currentUserInformation = await _userRegistry.GetCurrentUserInformation(cancellationToken);

var newLabel = request.SystemLabels.Count switch // The domain model currently only supports one system label
{
0 => SystemLabel.Values.Default,
1 => request.SystemLabels.First(),
_ => throw new UnreachableException() // Should be caught in validator
};
var newLabel = request.SystemLabels.SingleOrDefault(SystemLabel.Values.Default);

dialog.EndUserContext.UpdateLabel(newLabel, currentUserInformation.UserId.ExternalIdWithPrefix);
dialog.UpdateSystemLabel(currentUserInformation.UserId.ExternalIdWithPrefix, newLabel);

var saveResult = await _unitOfWork
.EnableConcurrencyCheck(dialog.EndUserContext, request.IfMatchEndUserContextRevision)
.SaveChangesAsync(cancellationToken);
.EnableConcurrencyCheck(dialog.EndUserContext, request.IfMatchEndUserContextRevision)
.SaveChangesAsync(cancellationToken);

return saveResult.Match<SetSystemLabelResult>(
_ => new SetSystemLabelSuccess(dialog.EndUserContext.Revision),
_ => new SetSystemLabelSuccess(dialog.EndUserContext?.Revision ?? dialog.Id),
domainError => domainError,
concurrencyError => concurrencyError);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,15 @@ public sealed class DialogEndUserContext : IEntity, IVersionableEntity
[AggregateChild]
public IReadOnlyCollection<LabelAssignmentLog> LabelAssignmentLogs => _labelAssignmentLogs.AsReadOnly();

public void UpdateLabel(SystemLabel.Values newLabel, string userId, ActorType.Values actorType = ActorType.Values.PartyRepresentative)
public void UpdateSystemLabel(string userId,
SystemLabel.Values? newLabel,
ActorType.Values actorType = ActorType.Values.PartyRepresentative)
{
if (!newLabel.HasValue)
{
return;
}

var currentLabel = SystemLabelId;
if (newLabel == currentLabel)
{
Expand Down Expand Up @@ -58,7 +65,7 @@ public void UpdateLabel(SystemLabel.Values newLabel, string userId, ActorType.Va
{
_labelAssignmentLogs.Add(new()
{
Name = newLabel.ToNamespacedName(),
Name = newLabel.Value.ToNamespacedName(),
Action = "set",
PerformedBy = new()
{
Expand All @@ -68,6 +75,12 @@ public void UpdateLabel(SystemLabel.Values newLabel, string userId, ActorType.Va
});
}

SystemLabelId = newLabel;
SystemLabelId = newLabel.Value;
}

public bool IsDefault()
{
return SystemLabelId is SystemLabel.Values.Default
&& LabelAssignmentLogs.Count == 0;
}
}
Loading
Loading