1
0
mirror of https://github.com/bitwarden/server.git synced 2024-11-23 12:25:16 +01:00

default collection on org create

This commit is contained in:
Kyle Spearrin 2017-08-30 21:25:46 -04:00
parent 20779014b0
commit e43c3baf6e
6 changed files with 28 additions and 14 deletions

View File

@ -153,7 +153,7 @@ namespace Bit.Api.Controllers
throw new BadRequestException("Invalid license"); 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); return new OrganizationResponseModel(result.Item1);
} }

View File

@ -1,4 +1,5 @@
using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations;
using Bit.Core.Utilities;
namespace Bit.Core.Models.Api namespace Bit.Core.Models.Api
{ {
@ -6,5 +7,8 @@ namespace Bit.Core.Models.Api
{ {
[Required] [Required]
public string Key { get; set; } public string Key { get; set; }
[EncryptedString]
[StringLength(1000)]
public string CollectionName { get; set; }
} }
} }

View File

@ -3,6 +3,7 @@ using Bit.Core.Enums;
using Bit.Core.Models.Business; using Bit.Core.Models.Business;
using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations;
using System.Collections.Generic; using System.Collections.Generic;
using Bit.Core.Utilities;
namespace Bit.Core.Models.Api namespace Bit.Core.Models.Api
{ {
@ -25,6 +26,9 @@ namespace Bit.Core.Models.Api
public short AdditionalSeats { get; set; } public short AdditionalSeats { get; set; }
[Range(0, 99)] [Range(0, 99)]
public short? AdditionalStorageGb { get; set; } public short? AdditionalStorageGb { get; set; }
[EncryptedString]
[StringLength(1000)]
public string CollectionName { get; set; }
public virtual OrganizationSignup ToOrganizationSignup(User user) public virtual OrganizationSignup ToOrganizationSignup(User user)
{ {
@ -38,7 +42,8 @@ namespace Bit.Core.Models.Api
AdditionalSeats = AdditionalSeats, AdditionalSeats = AdditionalSeats,
AdditionalStorageGb = AdditionalStorageGb.GetValueOrDefault(0), AdditionalStorageGb = AdditionalStorageGb.GetValueOrDefault(0),
BillingEmail = BillingEmail, BillingEmail = BillingEmail,
BusinessName = BusinessName BusinessName = BusinessName,
CollectionName = CollectionName
}; };
} }

View File

@ -13,5 +13,6 @@ namespace Bit.Core.Models.Business
public short AdditionalSeats { get; set; } public short AdditionalSeats { get; set; }
public short AdditionalStorageGb { get; set; } public short AdditionalStorageGb { get; set; }
public string PaymentToken { get; set; } public string PaymentToken { get; set; }
public string CollectionName { get; set; }
} }
} }

View File

@ -18,7 +18,8 @@ namespace Bit.Core.Services
Task AdjustSeatsAsync(Guid organizationId, int seatAdjustment); Task AdjustSeatsAsync(Guid organizationId, int seatAdjustment);
Task VerifyBankAsync(Guid organizationId, int amount1, int amount2); Task VerifyBankAsync(Guid organizationId, int amount1, int amount2);
Task<Tuple<Organization, OrganizationUser>> SignUpAsync(OrganizationSignup organizationSignup); Task<Tuple<Organization, OrganizationUser>> SignUpAsync(OrganizationSignup organizationSignup);
Task<Tuple<Organization, OrganizationUser>> SignUpAsync(OrganizationLicense license, User owner, string ownerKey); Task<Tuple<Organization, OrganizationUser>> SignUpAsync(OrganizationLicense license, User owner,
string ownerKey, string collectionName);
Task UpdateLicenseAsync(Guid organizationId, OrganizationLicense license); Task UpdateLicenseAsync(Guid organizationId, OrganizationLicense license);
Task DeleteAsync(Organization organization); Task DeleteAsync(Organization organization);
Task DisableAsync(Guid organizationId, DateTime? expirationDate); Task DisableAsync(Guid organizationId, DateTime? expirationDate);

View File

@ -537,11 +537,11 @@ namespace Bit.Core.Services
RevisionDate = DateTime.UtcNow 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<Tuple<Organization, OrganizationUser>> SignUpAsync( public async Task<Tuple<Organization, OrganizationUser>> SignUpAsync(
OrganizationLicense license, User owner, string ownerKey) OrganizationLicense license, User owner, string ownerKey, string collectionName)
{ {
if(license == null || !_licensingService.VerifyLicense(license)) if(license == null || !_licensingService.VerifyLicense(license))
{ {
@ -584,7 +584,7 @@ namespace Bit.Core.Services
RevisionDate = DateTime.UtcNow 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"; var dir = $"{_globalSettings.LicenseDirectory}/organization";
Directory.CreateDirectory(dir); Directory.CreateDirectory(dir);
@ -594,7 +594,7 @@ namespace Bit.Core.Services
} }
private async Task<Tuple<Organization, OrganizationUser>> SignUpAsync(Organization organization, private async Task<Tuple<Organization, OrganizationUser>> SignUpAsync(Organization organization,
Guid ownerId, string ownerKey, bool withPayment) Guid ownerId, string ownerKey, string collectionName, bool withPayment)
{ {
try try
{ {
@ -614,14 +614,17 @@ namespace Bit.Core.Services
await _organizationUserRepository.CreateAsync(orgUser); await _organizationUserRepository.CreateAsync(orgUser);
var defaultCollection = new Collection if(!string.IsNullOrWhiteSpace(collectionName))
{ {
Name = "Default Collection", var defaultCollection = new Collection
OrganizationId = organization.Id, {
CreationDate = organization.CreationDate, Name = collectionName,
RevisionDate = organization.CreationDate OrganizationId = organization.Id,
}; CreationDate = organization.CreationDate,
await _collectionRepository.CreateAsync(defaultCollection); RevisionDate = organization.CreationDate
};
await _collectionRepository.CreateAsync(defaultCollection);
}
// push // push
var deviceIds = await GetUserDeviceIdsAsync(orgUser.UserId.Value); var deviceIds = await GetUserDeviceIdsAsync(orgUser.UserId.Value);