Skip to content

Commit

Permalink
Added missing Audits and Usages events. #4
Browse files Browse the repository at this point in the history
  • Loading branch information
jezzsantos committed Apr 28, 2024
1 parent 1ed1fa5 commit fbb3183
Show file tree
Hide file tree
Showing 14 changed files with 178 additions and 47 deletions.
45 changes: 45 additions & 0 deletions src/Application.Interfaces/Audits.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions src/Application.Interfaces/Audits.resx
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,19 @@
<data name="SingleSignOnApplication_Authenticate_Succeeded" xml:space="preserve">
<value>Authentication.Passed</value>
</data>
<data name="CSRFMiddleware_CSRFProtection_Failed" xml:space="preserve">
<value>CSRFProtection.Failed</value>
</data>
<data name="EndUserApplication_PlatformFeatureAssigned" xml:space="preserve">
<value>EndUser.PlatformFeatureAssigned</value>
</data>
<data name="EndUserApplication_PlatformFeatureUnassigned" xml:space="preserve">
<value>EndUser.PlatformFeatureUnassigned</value>
</data>
<data name="EndUserApplication_TenantFeatureAssigned" xml:space="preserve">
<value>EndUser.TenantFeatureAssigned</value>
</data>
<data name="EndUserApplication_TenantFeatureUnassigned" xml:space="preserve">
<value>EndUser.TenantFeatureUnassigned</value>
</data>
</root>
43 changes: 30 additions & 13 deletions src/Application.Interfaces/UsageConstants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@ public static class Components
public static class Properties
{
public const string AuditCode = "Code";
public const string AvatarUrl = "AvatarUrl";
public const string CallId = "CallId";
public const string CarMake = "Make";
public const string CarModel = "Model";
public const string CarYear = "Year";
public const string Component = "Component";
public const string Duration = "Duration";
public const string EmailAddress = "EmailAddress";
Expand All @@ -26,12 +30,15 @@ public static class Properties
public const string Id = "ResourceId";
public const string IpAddress = "IpAddress";
public const string MetricEventName = "Metric";
public const string Name = "Name";
public const string Path = "Path";
public const string UserIdOverride = "UserIdOverride";
public const string ReferredBy = "ReferredBy";
public const string ResourceId = "ResourceId";
public const string Started = "Started";
public const string TenantId = "TenantId";
public const string Timestamp = "Timestamp";
public const string Timezone = "Timezone";
public const string UsedById = "UserId";
public const string UserAgent = "UserAgent";
}
Expand All @@ -40,19 +47,29 @@ public static class Events
{
public static class UsageScenarios
{
public const string Audit = "Audited";
public const string BookingCancelled = "Booking Cancelled";
public const string BookingCreated = "Booking Created";
public const string GuestInvited = "User Guest Invited";
public const string MachineRegistered = "Machine Registered";
public const string Measurement = "Measured";
public const string PersonRegistrationConfirmed = "User Registered";
public const string PersonRegistrationCreated = "User Registration Created";
public const string PersonReRegistered = "User Registration ReAttempted";
public const string UserExtendedLogin = "User Extended Login";
public const string UserLogin = "User Login";
public const string UserLogout = "User Logout";
public const string UserPasswordReset = "User Password Reset";
public static class Core
{
public const string BookingCancelled = "Booking Cancelled";
public const string BookingCreated = "Booking Created";
public const string CarRegistered = "Car Registered";
}

public static class Generic
{
public const string Audit = "Audited";
public const string GuestInvited = "User Guest Invited";
public const string MachineRegistered = "Machine Registered";
public const string Measurement = "Measured";
public const string PersonRegistrationConfirmed = "User Registered";
public const string PersonRegistrationCreated = "User Registration Created";
public const string PersonReRegistered = "User Registration ReAttempted";
public const string UserExtendedLogin = "User Extended Login";
public const string UserLogin = "User Login";
public const string UserLogout = "User Logout";
public const string UserPasswordForgotten = "User Password Forgotten";
public const string UserPasswordReset = "User Password Reset";
public const string UserProfileChanged = "User Profile Updated";
}
}

public static class Web
Expand Down
4 changes: 2 additions & 2 deletions src/BookingsApplication/BookingsApplication.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public async Task<Result<Error>> CancelBookingAsync(ICallerContext caller, strin
}

_recorder.TraceInformation(caller.ToCall(), "Booking {Id} was cancelled", booking.Id);
_recorder.TrackUsage(caller.ToCall(), UsageConstants.Events.UsageScenarios.BookingCancelled,
_recorder.TrackUsage(caller.ToCall(), UsageConstants.Events.UsageScenarios.Core.BookingCancelled,
new Dictionary<string, object>
{
{ UsageConstants.Properties.Id, booking.Id },
Expand Down Expand Up @@ -112,7 +112,7 @@ public async Task<Result<Booking, Error>> MakeBookingAsync(ICallerContext caller

booking = saved.Value;
_recorder.TraceInformation(caller.ToCall(), "Booking {Id} was created", booking.Id);
_recorder.TrackUsage(caller.ToCall(), UsageConstants.Events.UsageScenarios.BookingCreated,
_recorder.TrackUsage(caller.ToCall(), UsageConstants.Events.UsageScenarios.Core.BookingCreated,
new Dictionary<string, object>
{
{ UsageConstants.Properties.Id, booking.Id },
Expand Down
8 changes: 8 additions & 0 deletions src/CarsApplication/CarsApplication.cs
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,14 @@ public async Task<Result<Car, Error>> RegisterCarAsync(ICallerContext caller, st
return saved.Match<Result<Car, Error>>(c =>
{
_recorder.TraceInformation(caller.ToCall(), "Car {Id} was registered", c.Value.Id);
_recorder.TrackUsage(caller.ToCall(), UsageConstants.Events.UsageScenarios.Core.CarRegistered,
new Dictionary<string, object>
{
{ UsageConstants.Properties.Id, car.Id },
{ UsageConstants.Properties.CarMake, car.Manufacturer.Value.Make.Text },
{ UsageConstants.Properties.CarModel, car.Manufacturer.Value.Model.Text },
{ UsageConstants.Properties.CarYear, car.Manufacturer.Value.Year.Number }
});
return c.Value.ToCar();
}, error => error);
}
Expand Down
6 changes: 3 additions & 3 deletions src/EndUsersApplication/EndUsersApplication.cs
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ public async Task<Result<RegisteredEndUser, Error>> RegisterMachineAsync(ICaller

machine = saved.Value;
_recorder.TraceInformation(caller.ToCall(), "Registered machine: {Id}", machine.Id);
_recorder.TrackUsage(caller.ToCall(), UsageConstants.Events.UsageScenarios.MachineRegistered);
_recorder.TrackUsage(caller.ToCall(), UsageConstants.Events.UsageScenarios.Generic.MachineRegistered);

if (caller.IsAuthenticated)
{
Expand Down Expand Up @@ -290,7 +290,7 @@ public async Task<Result<RegisteredEndUser, Error>> RegisterPersonAsync(ICallerC

_recorder.TraceInformation(caller.ToCall(),
"Attempted re-registration of user: {Id}, with email {EmailAddress}", unregisteredUser.Id, email);
_recorder.TrackUsage(caller.ToCall(), UsageConstants.Events.UsageScenarios.PersonReRegistered,
_recorder.TrackUsage(caller.ToCall(), UsageConstants.Events.UsageScenarios.Generic.PersonReRegistered,
new Dictionary<string, object>
{
{ UsageConstants.Properties.Id, unregisteredUser.Id },
Expand Down Expand Up @@ -339,7 +339,7 @@ public async Task<Result<RegisteredEndUser, Error>> RegisterPersonAsync(ICallerC
_recorder.AuditAgainst(caller.ToCall(), person.Id,
Audits.EndUsersApplication_User_Registered_TermsAccepted,
"EndUser {Id} accepted their terms and conditions", person.Id);
_recorder.TrackUsage(caller.ToCall(), UsageConstants.Events.UsageScenarios.PersonRegistrationCreated);
_recorder.TrackUsage(caller.ToCall(), UsageConstants.Events.UsageScenarios.Generic.PersonRegistrationCreated);

var defaultOrganizationId = person.DefaultMembership.OrganizationId;
var serviceCaller = Caller.CreateAsMaintenance(caller.CallId);
Expand Down
4 changes: 2 additions & 2 deletions src/EndUsersApplication/InvitationsApplication.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public async Task<Result<Invitation, Error>> InviteGuestAsync(ICallerContext cal

invitee = saved.Value;
_recorder.TraceInformation(caller.ToCall(), "Guest {Id} was invited", invitee.Id);
_recorder.TrackUsage(caller.ToCall(), UsageConstants.Events.UsageScenarios.GuestInvited,
_recorder.TrackUsage(caller.ToCall(), UsageConstants.Events.UsageScenarios.Generic.GuestInvited,
new Dictionary<string, object>
{
{ nameof(EndUserRoot.Id), invitee.Id },
Expand Down Expand Up @@ -103,7 +103,7 @@ public async Task<Result<Error>> ResendGuestInvitationAsync(ICallerContext calle
}

_recorder.TraceInformation(caller.ToCall(), "Guest {Id} was re-invited", invitee.Id);
_recorder.TrackUsage(caller.ToCall(), UsageConstants.Events.UsageScenarios.GuestInvited,
_recorder.TrackUsage(caller.ToCall(), UsageConstants.Events.UsageScenarios.Generic.GuestInvited,
new Dictionary<string, object>
{
{ nameof(EndUserRoot.Id), invitee.Id },
Expand Down
9 changes: 7 additions & 2 deletions src/IdentityApplication/PasswordCredentialsApplication.cs
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,11 @@ await _notificationsService.NotifyPasswordResetUnknownUserCourtesyAsync(caller,

credentials = saved.Value;
_recorder.TraceInformation(caller.ToCall(), "Password reset initiated for {Id}", credentials.UserId);
_recorder.TrackUsage(caller.ToCall(), UsageConstants.Events.UsageScenarios.Generic.UserPasswordForgotten,
new Dictionary<string, object>
{
{ nameof(PasswordCredential.Id), credentials.UserId }
});

return Result.Ok;
}
Expand Down Expand Up @@ -350,7 +355,7 @@ public async Task<Result<Error>> CompletePasswordResetAsync(ICallerContext calle

credentials = saved.Value;
_recorder.TraceInformation(caller.ToCall(), "Password was reset for {Id}", credentials.UserId);
_recorder.TrackUsage(caller.ToCall(), UsageConstants.Events.UsageScenarios.UserPasswordReset,
_recorder.TrackUsage(caller.ToCall(), UsageConstants.Events.UsageScenarios.Generic.UserPasswordReset,
new Dictionary<string, object>
{
{ nameof(credentials.Id), credentials.UserId }
Expand Down Expand Up @@ -414,7 +419,7 @@ public async Task<Result<Error>> ConfirmPersonRegistrationAsync(ICallerContext c
_recorder.TraceInformation(caller.ToCall(), "Password credentials for {UserId} have been verified",
credential.UserId);
_recorder.TrackUsage(caller.ToCall(),
UsageConstants.Events.UsageScenarios.PersonRegistrationConfirmed,
UsageConstants.Events.UsageScenarios.Generic.PersonRegistrationConfirmed,
new Dictionary<string, object>
{
{ nameof(credential.Id), credential.UserId }
Expand Down
4 changes: 2 additions & 2 deletions src/Infrastructure.Hosting.Common/Recording/HostRecorder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ public void AuditAgainst(ICallContext? context, string againstId, string auditCo
AugmentMessageTemplateAndArguments(context, $"Audit: {auditCode}, against {againstId}, {messageTemplate}",
templateArgs);
TraceInformation(safeContext, augmentedMessageTemplate, augmentedArguments);
TrackUsageFor(safeContext, againstId, UsageConstants.Events.UsageScenarios.Audit,
TrackUsageFor(safeContext, againstId, UsageConstants.Events.UsageScenarios.Generic.Audit,
new Dictionary<string, object>
{
{ UsageConstants.Properties.UsedById, againstId },
Expand Down Expand Up @@ -202,7 +202,7 @@ public void Measure(ICallContext? context, string eventName, Dictionary<string,
TraceInformation(safeContext, $"Measure: {eventName}");
var usageContext = additional ?? new Dictionary<string, object>();
usageContext.Add(UsageConstants.Properties.MetricEventName, eventName.ToLowerInvariant());
TrackUsage(safeContext, UsageConstants.Events.UsageScenarios.Measurement, usageContext);
TrackUsage(safeContext, UsageConstants.Events.UsageScenarios.Generic.Measurement, usageContext);
_metricsReporter.Measure(safeContext, eventName, additional ?? new Dictionary<string, object>());
}

Expand Down
Loading

0 comments on commit fbb3183

Please sign in to comment.