Skip to content

Commit

Permalink
chore: Actor cleanup (#913)
Browse files Browse the repository at this point in the history
  • Loading branch information
oskogstad authored Jul 22, 2024
1 parent 5c0799b commit 22459cd
Show file tree
Hide file tree
Showing 28 changed files with 82 additions and 38 deletions.
16 changes: 13 additions & 3 deletions docs/schema/V1/schema.verified.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,16 @@ type Activity {
extendedType: URL
type: ActivityType!
relatedActivityId: UUID
performedBy: String
performedBy: Actor!
description: [Localization!]!
}

type Actor {
actorType: ActorType
actorId: String
actorName: String
}

type ApiAction {
id: UUID!
action: String!
Expand Down Expand Up @@ -173,8 +179,7 @@ type SearchDialogsPayload {
type SeenLog {
id: UUID!
seenAt: DateTime!
endUserIdHash: String!
endUserName: String
seenBy: Actor!
isCurrentEndUser: Boolean!
}

Expand Down Expand Up @@ -224,6 +229,11 @@ enum ActivityType {
FORWARDED
}

enum ActorType {
PARTY_REPRESENTATIVE
SERVICE_OWNER
}

enum ApplyPolicy {
BEFORE_RESOLVER
AFTER_RESOLVER
Expand Down
3 changes: 2 additions & 1 deletion docs/schema/V1/swagger.verified.json
Original file line number Diff line number Diff line change
Expand Up @@ -1887,7 +1887,8 @@
"$ref": "#/components/schemas/GetDialogSeenLogActorDtoSO"
},
"isViaServiceOwner": {
"type": "boolean"
"type": "boolean",
"nullable": true
}
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public static class IdentifierMasker
private const int SaltSize = 16;
private static readonly byte[] Salt = RandomNumberGenerator.GetBytes(SaltSize);

public static string? Hash(string? plaintext)
private static string? Hash(string? plaintext)
{
if (string.IsNullOrWhiteSpace(plaintext))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,9 @@ public sealed class GetDialogActivityDto

public DialogActivityType.Values Type { get; set; }

public DateTimeOffset? DeletedAt { get; set; }

public Guid? RelatedActivityId { get; set; }

public GetDialogActivityActorDto PerformedBy { get; set; } = new();
public GetDialogActivityActorDto PerformedBy { get; set; } = null!;
public List<LocalizationDto> Description { get; set; } = [];
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public sealed class GetDialogDialogSeenLogDto
public Guid Id { get; set; }
public DateTimeOffset SeenAt { get; set; }

public GetDialogDialogSeenLogActorDto SeenBy { get; set; } = new();
public GetDialogDialogSeenLogActorDto SeenBy { get; set; } = null!;

public bool? IsViaServiceOwner { get; set; }
public bool IsCurrentEndUser { get; set; }
Expand Down Expand Up @@ -73,7 +73,7 @@ public sealed class GetDialogDialogActivityDto

public Guid? RelatedActivityId { get; set; }

public GetDialogDialogActivityActorDto PerformedBy { get; set; } = new();
public GetDialogDialogActivityActorDto PerformedBy { get; set; } = null!;
public List<LocalizationDto> Description { get; set; } = [];
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
using Digdir.Domain.Dialogporten.Application.Externals;
using Digdir.Domain.Dialogporten.Application.Externals.AltinnAuthorization;
using Digdir.Domain.Dialogporten.Domain.Dialogs.Entities;
using Digdir.Domain.Dialogporten.Domain.Parties;
using MediatR;
using Microsoft.EntityFrameworkCore;
using OneOf;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ public MappingProfile()
.ForMember(dest => dest.SeenAt, opt => opt.MapFrom(src => src.CreatedAt));

CreateMap<DialogActor, GetDialogDialogSeenLogActorDto>()
.ForMember(dest => dest.ActorId, opt => opt.MapFrom(src => src.Id))
.ForMember(dest => dest.ActorId, opt => opt.MapFrom(src => IdentifierMasker.GetMaybeMaskedIdentifier(src.ActorId)));

CreateMap<DialogActivity, GetDialogDialogActivityDto>()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public sealed class SearchDialogDialogActivityDto

public Guid? RelatedActivityId { get; set; }

public SearchDialogDialogActivityActorDto PerformedBy { get; set; } = new();
public SearchDialogDialogActivityActorDto PerformedBy { get; set; } = null!;
public List<LocalizationDto> Description { get; set; } = [];
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public sealed class GetDialogActivityDto

public Guid? RelatedActivityId { get; set; }

public GetDialogActivityActorDto PerformedBy { get; set; } = new();
public GetDialogActivityActorDto PerformedBy { get; set; } = null!;
public List<LocalizationDto> Description { get; set; } = [];
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ public sealed class GetDialogSeenLogDto

public GetDialogSeenLogActorDto SeenBy { get; set; } = null!;

public bool IsViaServiceOwner { get; set; }
public bool? IsViaServiceOwner { get; set; }
}

public sealed class GetDialogSeenLogActorDto
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public async Task<SearchDialogSeenLogResult> Handle(SearchDialogSeenLogQuery req
var dialog = await _db.Dialogs
.AsNoTracking()
.Include(x => x.SeenLog)
.ThenInclude(x => x.SeenBy)
.ThenInclude(x => x.SeenBy)
.IgnoreQueryFilters()
.Where(x => resourceIds.Contains(x.ServiceResource))
.FirstOrDefaultAsync(x => x.Id == request.DialogId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,20 @@ public async Task<CreateDialogResult> Handle(CreateDialogCommand request, Cancel

foreach (var activity in request.Activities)
{
if (activity.PerformedBy.ActorId is null) continue;
if (activity.PerformedBy.ActorId is null)
{
continue;
}

activity.PerformedBy.ActorName = await _partyNameRegistry.GetName(activity.PerformedBy.ActorId, cancellationToken);
if (activity.PerformedBy.ActorName == null)

if (!string.IsNullOrWhiteSpace(activity.PerformedBy.ActorName))
{
return new DomainError(new DomainFailure(nameof(activity.PerformedBy.ActorId), $"Unable to look up actor id: {activity.PerformedBy.ActorId}"));
continue;
}

var domainFailure = new DomainFailure(nameof(activity.PerformedBy.ActorId), $"Unable to look up name for actor id: {activity.PerformedBy.ActorId}");
return new DomainError(domainFailure);
}

var dialog = _mapper.Map<DialogEntity>(request);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,7 @@ public CreateDialogDialogActivityDtoValidator(
.NotEqual(x => x.Id)
.When(x => x.RelatedActivityId.HasValue);
RuleFor(x => x.PerformedBy)
.NotNull()
.SetValidator(actorValidator);
RuleFor(x => x.Description)
.NotEmpty()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public sealed class CreateDialogDialogActivityDto

public Guid? RelatedActivityId { get; set; }

public CreateDialogDialogActivityActorDto PerformedBy { get; set; } = new();
public CreateDialogDialogActivityActorDto PerformedBy { get; set; } = null!;
public List<LocalizationDto> Description { get; set; } = [];
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,7 @@ public UpdateDialogDialogActivityDtoValidator(
.NotEqual(x => x.Id)
.When(x => x.RelatedActivityId.HasValue);
RuleFor(x => x.PerformedBy)
.NotNull()
.SetValidator(actorValidator);
RuleFor(x => x.Description)
.NotEmpty()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public class UpdateDialogDialogActivityDto

public Guid? RelatedActivityId { get; set; }

public UpdateDialogDialogActivityActorDto PerformedBy { get; set; } = new();
public UpdateDialogDialogActivityActorDto PerformedBy { get; set; } = null!;
public List<LocalizationDto> Description { get; set; } = [];
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public sealed class GetDialogDialogActivityDto

public Guid? RelatedActivityId { get; set; }

public GetDialogDialogActivityActorDto PerformedBy { get; set; } = new();
public GetDialogDialogActivityActorDto PerformedBy { get; set; } = null!;
public List<LocalizationDto> Description { get; set; } = [];
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public async Task<GetDialogResult> Handle(GetDialogQuery request, CancellationTo
{
var logDto = _mapper.Map<GetDialogDialogSeenLogDto>(log);
// TODO: Set when #386 is implemented
// logDto.IsAuthenticatedUser = log.EndUserId == userPid;
// logDto.IsCurrentEndUser = log.EndUserId == userPid;
return logDto;
})
.ToList();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ public MappingProfile()
.ForMember(dest => dest.Status, opt => opt.MapFrom(src => src.StatusId))
.ForMember(dest => dest.SeenSinceLastUpdate, opt => opt.Ignore());

CreateMap<DialogSeenLog, GetDialogDialogSeenLogDto>();
CreateMap<DialogSeenLog, GetDialogDialogSeenLogDto>()
.ForMember(dest => dest.SeenAt, opt => opt.MapFrom(src => src.CreatedAt));

CreateMap<DialogActor, GetDialogDialogSeenLogActorDto>();

CreateMap<DialogActivity, GetDialogDialogActivityDto>()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public sealed class SearchDialogDialogActivityDto

public Guid? RelatedActivityId { get; set; }

public SearchDialogDialogActivityActorDto PerformedBy { get; set; } = new();
public SearchDialogDialogActivityActorDto PerformedBy { get; set; } = null!;
public List<LocalizationDto> Description { get; set; } = [];
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using Digdir.Domain.Dialogporten.Application.Externals.AltinnAuthorization;
using Digdir.Domain.Dialogporten.Domain.Dialogs.Entities;
using Digdir.Domain.Dialogporten.Domain.Localizations;
using Digdir.Domain.Dialogporten.Domain.Parties;
using MediatR;
using Microsoft.EntityFrameworkCore;
using OneOf;
Expand Down Expand Up @@ -182,7 +183,6 @@ public async Task<SearchDialogResult> Handle(SearchDialogQuery request, Cancella
foreach (var seenRecord in paginatedList.Items.SelectMany(x => x.SeenSinceLastUpdate))
{
seenRecord.IsCurrentEndUser = seenRecord.SeenBy.ActorId == request.EndUserId;

}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ public MappingProfile()
CreateMap<LocalizationDto, Localization>();

CreateMap<GetDialogDialogSeenLogDto, SeenLog>();
CreateMap<GetDialogDialogSeenLogActorDto, Actor>();

CreateMap<SearchDialogDialogSeenLogDto, SeenLog>();
CreateMap<SearchDialogDialogSeenLogActorDto, Actor>();

CreateMap<GetDialogContentDto, Content>()
.ForMember(dest => dest.Type, opt => opt.MapFrom(src => src.Type));
Expand All @@ -21,7 +24,12 @@ public MappingProfile()

CreateMap<GetDialogDialogActivityDto, Activity>()
.ForMember(dest => dest.Type, opt => opt.MapFrom(src => src.Type));
CreateMap<GetDialogDialogActivityActorDto, Actor>()
.ForMember(dest => dest.ActorType, opt => opt.MapFrom(src => src.ActorType));

CreateMap<SearchDialogDialogActivityDto, Activity>()
.ForMember(dest => dest.Type, opt => opt.MapFrom(src => src.Type));
CreateMap<SearchDialogDialogActivityActorDto, Actor>()
.ForMember(dest => dest.ActorType, opt => opt.MapFrom(src => src.ActorType));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,7 @@ public sealed class SeenLog
public Guid Id { get; set; }
public DateTimeOffset SeenAt { get; set; }

public string EndUserIdHash { get; set; } = null!;

public string? EndUserName { get; set; }
public Actor SeenBy { get; set; } = null!;

public bool IsCurrentEndUser { get; set; }
}
Expand All @@ -45,10 +43,24 @@ public sealed class Activity

public Guid? RelatedActivityId { get; set; }

public string? PerformedBy { get; set; }
public Actor PerformedBy { get; set; } = null!;

public List<Localization> Description { get; set; } = [];
}

public sealed class Actor
{
public ActorType? ActorType { get; set; }
public string? ActorId { get; set; }
public string? ActorName { get; set; }
}

public enum ActorType
{
PartyRepresentative = 1,
ServiceOwner = 2
}

public enum ActivityType
{
[GraphQLDescription("Refers to a submission made by a party that has been received by the service provider.")]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using Altinn.Authorization.ABAC.Xacml.JsonProfile;
using System.Security.Claims;
using System.Text.Json;
using Digdir.Domain.Dialogporten.Application.Common.Authorization;
using Digdir.Domain.Dialogporten.Application.Common.Extensions;
using Digdir.Domain.Dialogporten.Application.Externals.AltinnAuthorization;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@ public partial class AddActor : Migration
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.Sql("""
DELETE FROM public."DialogActivity"
""");
migrationBuilder.Sql("""
DELETE FROM public."DialogSeenLog"
""");

migrationBuilder.DropForeignKey(
name: "FK_LocalizationSet_DialogSeenLog_DialogSeenLogId",
table: "LocalizationSet");
Expand Down Expand Up @@ -47,15 +54,13 @@ protected override void Up(MigrationBuilder migrationBuilder)
name: "SeenById",
table: "DialogSeenLog",
type: "uuid",
nullable: false,
defaultValue: new Guid("00000000-0000-0000-0000-000000000000"));
nullable: false);

migrationBuilder.AddColumn<Guid>(
name: "PerformedById",
table: "DialogActivity",
type: "uuid",
nullable: false,
defaultValue: new Guid("00000000-0000-0000-0000-000000000000"));
nullable: false);

migrationBuilder.CreateTable(
name: "DialogActorType",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using Digdir.Domain.Dialogporten.Application.Features.V1.EndUser.DialogActivities.Queries.Get;
using Digdir.Domain.Dialogporten.Application.Features.V1.ServiceOwner.Dialogs.Commands.Create;
using Digdir.Domain.Dialogporten.Application.Integration.Tests.Common;
using Digdir.Domain.Dialogporten.Domain.Dialogs.Entities.Activities;
using Digdir.Domain.Dialogporten.Domain.Parties;
using Digdir.Tool.Dialogporten.GenerateFakeData;
using FluentAssertions;
Expand Down Expand Up @@ -84,7 +85,7 @@ public async Task Get_ActivityLog_Should_Not_Return_User_Ids_Unhashed()
private async Task<(CreateDialogCommand, CreateDialogResult)> GenerateDialogWithActivity()
{
var createDialogCommand = DialogGenerator.GenerateSimpleFakeDialog();
var activity = DialogGenerator.GenerateFakeDialogActivity();
var activity = DialogGenerator.GenerateFakeDialogActivity(type: DialogActivityType.Values.Information);
activity.PerformedBy.ActorId = DialogGenerator.GenerateRandomParty(forcePerson: true);
activity.PerformedBy.ActorName = null;
createDialogCommand.Activities.Add(activity);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using Digdir.Domain.Dialogporten.Application.Common;
using Digdir.Domain.Dialogporten.Application.Features.V1.EndUser.Dialogs.Queries.Get;
using Digdir.Domain.Dialogporten.Application.Features.V1.EndUser.Dialogs.Queries.Search;
using Digdir.Domain.Dialogporten.Application.Features.V1.EndUser.DialogSeenLogs.Queries.Get;
Expand Down
Loading

0 comments on commit 22459cd

Please sign in to comment.