From 5dd1a9410a2250a1773f00a0e6379a8d35a80511 Mon Sep 17 00:00:00 2001 From: cyprain-okeke <108260115+cyprain-okeke@users.noreply.github.com> Date: Fri, 22 Mar 2024 21:01:22 +0100 Subject: [PATCH] [AC-1864] Event type for initiation path (#3869) * initial commit Signed-off-by: Cy Okeke * handle the upgrade path reference Signed-off-by: Cy Okeke * code improvement Signed-off-by: Cy Okeke * resolve pr comment Signed-off-by: Cy Okeke * change the comment Signed-off-by: Cy Okeke * move the private method down Signed-off-by: Cy Okeke * code review changes Signed-off-by: Cy Okeke --------- Signed-off-by: Cy Okeke --- .../UpgradeOrganizationPlanCommand.cs | 25 +++++++++++++++++++ .../Tools/Models/Business/ReferenceEvent.cs | 11 ++++++++ 2 files changed, 36 insertions(+) diff --git a/src/Core/OrganizationFeatures/OrganizationSubscriptions/UpgradeOrganizationPlanCommand.cs b/src/Core/OrganizationFeatures/OrganizationSubscriptions/UpgradeOrganizationPlanCommand.cs index 0023484bf..bd198ded3 100644 --- a/src/Core/OrganizationFeatures/OrganizationSubscriptions/UpgradeOrganizationPlanCommand.cs +++ b/src/Core/OrganizationFeatures/OrganizationSubscriptions/UpgradeOrganizationPlanCommand.cs @@ -279,6 +279,7 @@ public class UpgradeOrganizationPlanCommand : IUpgradeOrganizationPlanCommand if (success) { + var upgradePath = GetUpgradePath(existingPlan.Product, newPlan.Product); await _referenceEventService.RaiseEventAsync( new ReferenceEvent(ReferenceEventType.UpgradePlan, organization, _currentContext) { @@ -287,6 +288,8 @@ public class UpgradeOrganizationPlanCommand : IUpgradeOrganizationPlanCommand OldPlanName = existingPlan.Name, OldPlanType = existingPlan.Type, Seats = organization.Seats, + SignupInitiationPath = "Upgrade in-product", + PlanUpgradePath = upgradePath, Storage = organization.MaxStorageGb, // TODO: add reference events for SmSeats and Service Accounts - see AC-1481 }); @@ -338,4 +341,26 @@ public class UpgradeOrganizationPlanCommand : IUpgradeOrganizationPlanCommand { return await _organizationRepository.GetByIdAsync(id); } + + private static string GetUpgradePath(ProductType oldProductType, ProductType newProductType) + { + var oldDescription = _upgradePath.TryGetValue(oldProductType, out var description) + ? description + : $"{oldProductType:G}"; + + var newDescription = _upgradePath.TryGetValue(newProductType, out description) + ? description + : $"{newProductType:G}"; + + return $"{oldDescription} → {newDescription}"; + } + + private static readonly Dictionary _upgradePath = new() + { + [ProductType.Free] = "2-person org", + [ProductType.Families] = "Families", + [ProductType.TeamsStarter] = "Teams Starter", + [ProductType.Teams] = "Teams", + [ProductType.Enterprise] = "Enterprise" + }; } diff --git a/src/Core/Tools/Models/Business/ReferenceEvent.cs b/src/Core/Tools/Models/Business/ReferenceEvent.cs index 03a0b3e1d..5e68b8cce 100644 --- a/src/Core/Tools/Models/Business/ReferenceEvent.cs +++ b/src/Core/Tools/Models/Business/ReferenceEvent.cs @@ -243,4 +243,15 @@ public class ReferenceEvent /// the value should be . /// public string SignupInitiationPath { get; set; } + + /// + /// The upgrade applied to an account. The current plan is listed first, + /// followed by the plan they are migrating to. For example, + /// "Teams Starter → Teams, Enterprise". + /// + /// + /// when the event was not originated by an application, + /// or when a downgrade occurred. + /// + public string PlanUpgradePath { get; set; } }