diff --git a/src/Core/Dirt/Enums/EventType.cs b/src/Core/Dirt/Enums/EventType.cs index 3de7e9894b7f..0a0c6bfe0cda 100644 --- a/src/Core/Dirt/Enums/EventType.cs +++ b/src/Core/Dirt/Enums/EventType.cs @@ -147,4 +147,6 @@ public enum EventType : int Send_Created_File = 2503, Send_Created_File_WithEmailVerification = 2504, Send_Created_File_WithPasswordProtection = 2505, + Send_Edited_Text = 2506, + Send_Edited_File = 2507, } diff --git a/src/Core/Tools/SendFeatures/Commands/NonAnonymousSendCommand.cs b/src/Core/Tools/SendFeatures/Commands/NonAnonymousSendCommand.cs index d99146451d25..150846644251 100644 --- a/src/Core/Tools/SendFeatures/Commands/NonAnonymousSendCommand.cs +++ b/src/Core/Tools/SendFeatures/Commands/NonAnonymousSendCommand.cs @@ -52,17 +52,20 @@ public async Task SaveSendAsync(Send send) // Make sure user can save Sends await _sendValidationService.ValidateUserCanSaveAsync(send.UserId, send); + // New Send if (send.Id == default(Guid)) { await _sendRepository.CreateAsync(send); await _pushNotificationService.PushSyncSendCreateAsync(send); await LogSendCreatedEventAsync(send); } + // Edit existing Send else { send.RevisionDate = DateTime.UtcNow; await _sendRepository.UpsertAsync(send); await _pushNotificationService.PushSyncSendUpdateAsync(send); + await LogSendUpdatedEventAsync(send); } } @@ -76,6 +79,23 @@ private async Task LogSendCreatedEventAsync(Send send) await _eventService.LogUserEventAsync(send.UserId.Value, ResolveSendCreatedEventType(send)); } + private async Task LogSendUpdatedEventAsync(Send send) + { + if (!send.UserId.HasValue || !_featureService.IsEnabled(FeatureFlagKeys.SendEventLogging)) + { + return; + } + + if (send.Type == SendType.Text) + { + await _eventService.LogUserEventAsync(send.UserId.Value, EventType.Send_Edited_Text); + } + else + { + await _eventService.LogUserEventAsync(send.UserId.Value, EventType.Send_Edited_File); + } + } + private static EventType ResolveSendCreatedEventType(Send send) { // send.AuthType is populated by SendRequestModel.ToSendBase before SaveSendAsync runs diff --git a/test/Core.Test/Tools/Services/NonAnonymousSendCommandTests.cs b/test/Core.Test/Tools/Services/NonAnonymousSendCommandTests.cs index 955347a519ad..f092d780bc84 100644 --- a/test/Core.Test/Tools/Services/NonAnonymousSendCommandTests.cs +++ b/test/Core.Test/Tools/Services/NonAnonymousSendCommandTests.cs @@ -1518,8 +1518,31 @@ public async Task SaveSendAsync_NewSend_FlagOff_DoesNotLogEvent() await _eventService.DidNotReceiveWithAnyArgs().LogUserEventAsync(default, default); } + [Theory] + [InlineData(SendType.Text, EventType.Send_Edited_Text)] + [InlineData(SendType.File, EventType.Send_Edited_File)] + public async Task SaveSendAsync_ExistingSend_FlagOn_LogsExpectedEventType( + SendType sendType, EventType expectedEventType) + { + var userId = Guid.NewGuid(); + var send = new Send + { + Id = Guid.NewGuid(), + Type = sendType, + UserId = userId, + }; + + _featureService.IsEnabled(FeatureFlagKeys.SendEventLogging).Returns(true); + _sendValidationService.ValidateUserCanSaveAsync(userId, send).Returns(Task.CompletedTask); + + await _nonAnonymousSendCommand.SaveSendAsync(send); + + await _sendRepository.Received(1).UpsertAsync(send); + await _eventService.Received(1).LogUserEventAsync(userId, expectedEventType); + } + [Fact] - public async Task SaveSendAsync_ExistingSend_FlagOn_DoesNotLogEvent() + public async Task SaveSendAsync_ExistingSend_FlagOff_DoesNotLogEvent() { var userId = Guid.NewGuid(); var send = new Send @@ -1529,7 +1552,7 @@ public async Task SaveSendAsync_ExistingSend_FlagOn_DoesNotLogEvent() UserId = userId, }; - _featureService.IsEnabled(FeatureFlagKeys.SendEventLogging).Returns(true); + _featureService.IsEnabled(FeatureFlagKeys.SendEventLogging).Returns(false); _sendValidationService.ValidateUserCanSaveAsync(userId, send).Returns(Task.CompletedTask); await _nonAnonymousSendCommand.SaveSendAsync(send);