From f55708d74830814d20f748202b96c2e7c0f5c118 Mon Sep 17 00:00:00 2001 From: Addison Beck Date: Wed, 11 Aug 2021 12:44:30 -0400 Subject: [PATCH] built out the organization edit event from the admin portal (#1508) * built out the organization edit event from the admin portal * removed unneeded override * added some space * fixed the space --- src/Admin/Controllers/OrganizationsController.cs | 15 ++++++++------- src/Admin/Models/OrganizationEditModel.cs | 1 + src/Admin/Views/Organizations/Edit.cshtml | 3 +++ src/Core/Enums/ReferenceEventType.cs | 4 ++-- src/Core/Models/Business/ReferenceEvent.cs | 4 ++++ src/Core/Services/IUserService.cs | 1 + 6 files changed, 19 insertions(+), 9 deletions(-) diff --git a/src/Admin/Controllers/OrganizationsController.cs b/src/Admin/Controllers/OrganizationsController.cs index 5398352af5..b7054c28ef 100644 --- a/src/Admin/Controllers/OrganizationsController.cs +++ b/src/Admin/Controllers/OrganizationsController.cs @@ -27,6 +27,7 @@ namespace Bit.Admin.Controllers private readonly IApplicationCacheService _applicationCacheService; private readonly GlobalSettings _globalSettings; private readonly IReferenceEventService _referenceEventService; + private readonly IUserService _userService; public OrganizationsController( IOrganizationRepository organizationRepository, @@ -38,7 +39,8 @@ namespace Bit.Admin.Controllers IPaymentService paymentService, IApplicationCacheService applicationCacheService, GlobalSettings globalSettings, - IReferenceEventService referenceEventService) + IReferenceEventService referenceEventService, + IUserService userService) { _organizationRepository = organizationRepository; _organizationUserRepository = organizationUserRepository; @@ -50,6 +52,7 @@ namespace Bit.Admin.Controllers _applicationCacheService = applicationCacheService; _globalSettings = globalSettings; _referenceEventService = referenceEventService; + _userService = userService; } public async Task Index(string name = null, string userEmail = null, bool? paid = null, @@ -137,15 +140,13 @@ namespace Bit.Admin.Controllers public async Task Edit(Guid id, OrganizationEditModel model) { var organization = await _organizationRepository.GetByIdAsync(id); - if (organization == null) - { - return RedirectToAction("Index"); - } - model.ToOrganization(organization); await _organizationRepository.ReplaceAsync(organization); await _applicationCacheService.UpsertOrganizationAbilityAsync(organization); - await _referenceEventService.RaiseEventAsync(new ReferenceEvent(ReferenceEventType.SalesAssisted, organization)); + await _referenceEventService.RaiseEventAsync(new ReferenceEvent(ReferenceEventType.OrganizationEditedByAdmin, organization) { + EventRaisedByUser = _userService.GetUserName(User), + SalesAssistedTrialStarted = model.SalesAssistedTrialStarted, + }); return RedirectToAction("Edit", new { id }); } diff --git a/src/Admin/Models/OrganizationEditModel.cs b/src/Admin/Models/OrganizationEditModel.cs index 2a65d3234a..6b6f65cc99 100644 --- a/src/Admin/Models/OrganizationEditModel.cs +++ b/src/Admin/Models/OrganizationEditModel.cs @@ -107,6 +107,7 @@ namespace Bit.Admin.Models public string LicenseKey { get; set; } [Display(Name = "Expiration Date")] public DateTime? ExpirationDate { get; set; } + public bool SalesAssistedTrialStarted { get; set; } public Organization ToOrganization(Organization existingOrganization) { diff --git a/src/Admin/Views/Organizations/Edit.cshtml b/src/Admin/Views/Organizations/Edit.cshtml index 1452103fa4..1418304c67 100644 --- a/src/Admin/Views/Organizations/Edit.cshtml +++ b/src/Admin/Views/Organizations/Edit.cshtml @@ -34,6 +34,8 @@ // Licensing document.getElementById('@(nameof(Model.LicenseKey))').value = '@Model.RandomLicenseKey'; document.getElementById('@(nameof(Model.ExpirationDate))').value = '@Model.FourteenDayExpirationDate'; + document.getElementById('@(nameof(Model.SalesAssistedTrialStarted))').value = true; + }); document.getElementById('@(nameof(Model.PlanType))').addEventListener('change', () => { @@ -83,6 +85,7 @@ @await Html.PartialAsync("_BillingInformation", new BillingInformationModel { BillingInfo = Model.BillingInfo, OrganizationId = Model.Organization.Id })
+

General

diff --git a/src/Core/Enums/ReferenceEventType.cs b/src/Core/Enums/ReferenceEventType.cs index 819bce1547..b2c1b32abc 100644 --- a/src/Core/Enums/ReferenceEventType.cs +++ b/src/Core/Enums/ReferenceEventType.cs @@ -38,7 +38,7 @@ namespace Bit.Core.Enums GroupCreated, [EnumMember(Value = "collection-created")] CollectionCreated, - [EnumMember(Value = "sales-assisted")] - SalesAssisted + [EnumMember(Value = "organization-edited-by-admin")] + OrganizationEditedByAdmin } } diff --git a/src/Core/Models/Business/ReferenceEvent.cs b/src/Core/Models/Business/ReferenceEvent.cs index d3bbf3020e..1952e13746 100644 --- a/src/Core/Models/Business/ReferenceEvent.cs +++ b/src/Core/Models/Business/ReferenceEvent.cs @@ -57,5 +57,9 @@ namespace Bit.Core.Models.Business public int? MaxAccessCount { get; set; } public bool? HasPassword { get; set; } + + public string EventRaisedByUser { get; set; } + + public bool SalesAssistedTrialStarted { get; set; } } } diff --git a/src/Core/Services/IUserService.cs b/src/Core/Services/IUserService.cs index cf6a338d54..c36f917b46 100644 --- a/src/Core/Services/IUserService.cs +++ b/src/Core/Services/IUserService.cs @@ -73,5 +73,6 @@ namespace Bit.Core.Services Task GenerateEnterprisePortalSignInTokenAsync(User user); Task GenerateSignInTokenAsync(User user, string purpose); Task RotateApiKeyAsync(User user); + string GetUserName(ClaimsPrincipal principal); } }