From e43c3baf6ef1634b88c6dc3db499b4183dc42ee3 Mon Sep 17 00:00:00 2001 From: Kyle Spearrin Date: Wed, 30 Aug 2017 21:25:46 -0400 Subject: [PATCH] default collection on org create --- .../Controllers/OrganizationsController.cs | 2 +- .../OrganizationCreateLicenseRequestModel.cs | 4 +++ .../OrganizationCreateRequestModel.cs | 7 +++++- .../Models/Business/OrganizationSignup.cs | 1 + src/Core/Services/IOrganizationService.cs | 3 ++- .../Implementations/OrganizationService.cs | 25 +++++++++++-------- 6 files changed, 28 insertions(+), 14 deletions(-) diff --git a/src/Api/Controllers/OrganizationsController.cs b/src/Api/Controllers/OrganizationsController.cs index b46819e8d..b5db87c4e 100644 --- a/src/Api/Controllers/OrganizationsController.cs +++ b/src/Api/Controllers/OrganizationsController.cs @@ -153,7 +153,7 @@ namespace Bit.Api.Controllers throw new BadRequestException("Invalid license"); } - var result = await _organizationService.SignUpAsync(license, user, model.Key); + var result = await _organizationService.SignUpAsync(license, user, model.Key, model.CollectionName); return new OrganizationResponseModel(result.Item1); } diff --git a/src/Core/Models/Api/Request/Organizations/OrganizationCreateLicenseRequestModel.cs b/src/Core/Models/Api/Request/Organizations/OrganizationCreateLicenseRequestModel.cs index edcc212db..808695f06 100644 --- a/src/Core/Models/Api/Request/Organizations/OrganizationCreateLicenseRequestModel.cs +++ b/src/Core/Models/Api/Request/Organizations/OrganizationCreateLicenseRequestModel.cs @@ -1,4 +1,5 @@ using System.ComponentModel.DataAnnotations; +using Bit.Core.Utilities; namespace Bit.Core.Models.Api { @@ -6,5 +7,8 @@ namespace Bit.Core.Models.Api { [Required] public string Key { get; set; } + [EncryptedString] + [StringLength(1000)] + public string CollectionName { get; set; } } } diff --git a/src/Core/Models/Api/Request/Organizations/OrganizationCreateRequestModel.cs b/src/Core/Models/Api/Request/Organizations/OrganizationCreateRequestModel.cs index 67fe7aede..c7ca92dbf 100644 --- a/src/Core/Models/Api/Request/Organizations/OrganizationCreateRequestModel.cs +++ b/src/Core/Models/Api/Request/Organizations/OrganizationCreateRequestModel.cs @@ -3,6 +3,7 @@ using Bit.Core.Enums; using Bit.Core.Models.Business; using System.ComponentModel.DataAnnotations; using System.Collections.Generic; +using Bit.Core.Utilities; namespace Bit.Core.Models.Api { @@ -25,6 +26,9 @@ namespace Bit.Core.Models.Api public short AdditionalSeats { get; set; } [Range(0, 99)] public short? AdditionalStorageGb { get; set; } + [EncryptedString] + [StringLength(1000)] + public string CollectionName { get; set; } public virtual OrganizationSignup ToOrganizationSignup(User user) { @@ -38,7 +42,8 @@ namespace Bit.Core.Models.Api AdditionalSeats = AdditionalSeats, AdditionalStorageGb = AdditionalStorageGb.GetValueOrDefault(0), BillingEmail = BillingEmail, - BusinessName = BusinessName + BusinessName = BusinessName, + CollectionName = CollectionName }; } diff --git a/src/Core/Models/Business/OrganizationSignup.cs b/src/Core/Models/Business/OrganizationSignup.cs index 76e0136bf..7bb9dc718 100644 --- a/src/Core/Models/Business/OrganizationSignup.cs +++ b/src/Core/Models/Business/OrganizationSignup.cs @@ -13,5 +13,6 @@ namespace Bit.Core.Models.Business public short AdditionalSeats { get; set; } public short AdditionalStorageGb { get; set; } public string PaymentToken { get; set; } + public string CollectionName { get; set; } } } diff --git a/src/Core/Services/IOrganizationService.cs b/src/Core/Services/IOrganizationService.cs index 99ed8bce4..fcd6c51ca 100644 --- a/src/Core/Services/IOrganizationService.cs +++ b/src/Core/Services/IOrganizationService.cs @@ -18,7 +18,8 @@ namespace Bit.Core.Services Task AdjustSeatsAsync(Guid organizationId, int seatAdjustment); Task VerifyBankAsync(Guid organizationId, int amount1, int amount2); Task> SignUpAsync(OrganizationSignup organizationSignup); - Task> SignUpAsync(OrganizationLicense license, User owner, string ownerKey); + Task> SignUpAsync(OrganizationLicense license, User owner, + string ownerKey, string collectionName); Task UpdateLicenseAsync(Guid organizationId, OrganizationLicense license); Task DeleteAsync(Organization organization); Task DisableAsync(Guid organizationId, DateTime? expirationDate); diff --git a/src/Core/Services/Implementations/OrganizationService.cs b/src/Core/Services/Implementations/OrganizationService.cs index 68071427d..1bfa44ae1 100644 --- a/src/Core/Services/Implementations/OrganizationService.cs +++ b/src/Core/Services/Implementations/OrganizationService.cs @@ -537,11 +537,11 @@ namespace Bit.Core.Services RevisionDate = DateTime.UtcNow }; - return await SignUpAsync(organization, signup.Owner.Id, signup.OwnerKey, true); + return await SignUpAsync(organization, signup.Owner.Id, signup.OwnerKey, signup.CollectionName, true); } public async Task> SignUpAsync( - OrganizationLicense license, User owner, string ownerKey) + OrganizationLicense license, User owner, string ownerKey, string collectionName) { if(license == null || !_licensingService.VerifyLicense(license)) { @@ -584,7 +584,7 @@ namespace Bit.Core.Services RevisionDate = DateTime.UtcNow }; - var result = await SignUpAsync(organization, owner.Id, ownerKey, false); + var result = await SignUpAsync(organization, owner.Id, ownerKey, collectionName, false); var dir = $"{_globalSettings.LicenseDirectory}/organization"; Directory.CreateDirectory(dir); @@ -594,7 +594,7 @@ namespace Bit.Core.Services } private async Task> SignUpAsync(Organization organization, - Guid ownerId, string ownerKey, bool withPayment) + Guid ownerId, string ownerKey, string collectionName, bool withPayment) { try { @@ -614,14 +614,17 @@ namespace Bit.Core.Services await _organizationUserRepository.CreateAsync(orgUser); - var defaultCollection = new Collection + if(!string.IsNullOrWhiteSpace(collectionName)) { - Name = "Default Collection", - OrganizationId = organization.Id, - CreationDate = organization.CreationDate, - RevisionDate = organization.CreationDate - }; - await _collectionRepository.CreateAsync(defaultCollection); + var defaultCollection = new Collection + { + Name = collectionName, + OrganizationId = organization.Id, + CreationDate = organization.CreationDate, + RevisionDate = organization.CreationDate + }; + await _collectionRepository.CreateAsync(defaultCollection); + } // push var deviceIds = await GetUserDeviceIdsAsync(orgUser.UserId.Value);