1
0
mirror of https://github.com/bitwarden/server.git synced 2025-07-01 08:02:49 -05:00

organization signup apis and data model changes

This commit is contained in:
Kyle Spearrin
2017-03-03 00:07:11 -05:00
parent b18b6a44ef
commit 29e3605576
20 changed files with 371 additions and 131 deletions

View File

@ -15,18 +15,24 @@ namespace Bit.Api.Controllers
public class OrganizationsController : Controller
{
private readonly IOrganizationRepository _organizationRepository;
private readonly IOrganizationUserRepository _organizationUserRepository;
private readonly IOrganizationService _organizationService;
private readonly IUserService _userService;
public OrganizationsController(
IOrganizationRepository organizationRepository,
IOrganizationUserRepository organizationUserRepository,
IOrganizationService organizationService,
IUserService userService)
{
_organizationRepository = organizationRepository;
_organizationUserRepository = organizationUserRepository;
_organizationService = organizationService;
_userService = userService;
}
[HttpGet("{id}")]
public async Task<OrganizationResponseModel> Get(string id)
public async Task<OrganizationExtendedResponseModel> Get(string id)
{
var userId = _userService.GetProperUserId(User).Value;
var organization = await _organizationRepository.GetByIdAsync(new Guid(id), userId);
@ -35,7 +41,13 @@ namespace Bit.Api.Controllers
throw new NotFoundException();
}
return new OrganizationResponseModel(organization);
var organizationUser = await _organizationUserRepository.GetByOrganizationAsync(new Guid(id), userId);
if(organizationUser == null)
{
throw new NotFoundException();
}
return new OrganizationExtendedResponseModel(organization, organizationUser);
}
[HttpGet("")]
@ -48,12 +60,12 @@ namespace Bit.Api.Controllers
}
[HttpPost("")]
public async Task<OrganizationResponseModel> Post([FromBody]OrganizationCreateRequestModel model)
public async Task<OrganizationExtendedResponseModel> Post([FromBody]OrganizationCreateRequestModel model)
{
var userId = _userService.GetProperUserId(User).Value;
var organization = model.ToOrganization(_userService.GetProperUserId(User).Value);
await _organizationRepository.ReplaceAsync(organization);
return new OrganizationResponseModel(organization);
var user = await _userService.GetUserByPrincipalAsync(User);
var organizationSignup = model.ToOrganizationSignup(user);
var result = await _organizationService.SignUpAsync(organizationSignup);
return new OrganizationExtendedResponseModel(result.Item1, result.Item2);
}
[HttpPut("{id}")]

View File

@ -1,5 +1,6 @@
using Bit.Core.Domains;
using Bit.Core.Enums;
using Bit.Core.Models.Business;
using System;
namespace Bit.Api.Models
@ -7,19 +8,18 @@ namespace Bit.Api.Models
public class OrganizationCreateRequestModel
{
public string Name { get; set; }
public PlanType Plan { get; set; }
// TODO: Billing info for paid plans.
public PlanType PlanType { get; set; }
public string Key { get; set; }
public virtual Organization ToOrganization(Guid userId)
public virtual OrganizationSignup ToOrganizationSignup(User user)
{
var organization = new Organization
return new OrganizationSignup
{
UserId = userId,
Owner = user,
OwnerKey = Key,
Name = Name,
Plan = Plan
Plan = PlanType
};
return organization;
}
}
}

View File

@ -24,8 +24,8 @@ namespace Bit.Api.Models
JsonConvert.DeserializeObject<List<GlobalEquivalentDomainsType>>(user.ExcludedGlobalEquivalentDomains) :
new List<GlobalEquivalentDomainsType>();
var globalDomains = new List<GlobalDomains>();
var domainsToInclude = excluded ? Core.Utilities.EquivalentDomains.Global :
Core.Utilities.EquivalentDomains.Global.Where(d => !excludedGlobalEquivalentDomains.Contains(d.Key));
var domainsToInclude = excluded ? Core.Utilities.StaticStore.GlobalDomains :
Core.Utilities.StaticStore.GlobalDomains.Where(d => !excludedGlobalEquivalentDomains.Contains(d.Key));
foreach(var domain in domainsToInclude)
{
globalDomains.Add(new GlobalDomains(domain.Key, domain.Value, excludedGlobalEquivalentDomains, excluded));

View File

@ -1,13 +1,12 @@
using System;
using Bit.Core.Domains;
using Bit.Core.Enums;
namespace Bit.Api.Models
{
public class OrganizationResponseModel : ResponseModel
{
public OrganizationResponseModel(Organization organization)
: base("organization")
public OrganizationResponseModel(Organization organization, string obj = "organization")
: base(obj)
{
if(organization == null)
{
@ -17,12 +16,32 @@ namespace Bit.Api.Models
Id = organization.Id.ToString();
Name = organization.Name;
Plan = organization.Plan;
PlanType = organization.PlanType;
PlanTrial = organization.PlanTrial;
MaxUsers = organization.MaxUsers;
}
public string Id { get; set; }
public string Name { get; set; }
public PlanType Plan { get; set; }
public string Plan { get; set; }
public Core.Enums.PlanType PlanType { get; set; }
public bool PlanTrial { get; set; }
public short MaxUsers { get; set; }
}
public class OrganizationExtendedResponseModel : OrganizationResponseModel
{
public OrganizationExtendedResponseModel(Organization organization, OrganizationUser organizationUser)
: base(organization, "organizationExtended")
{
if(organizationUser == null)
{
throw new ArgumentNullException(nameof(organizationUser));
}
Key = organizationUser.Key;
}
public string Key { get; set; }
}
}

View File

@ -180,6 +180,7 @@ namespace Bit.Api
services.AddScoped<IPushService, PushSharpPushService>();
services.AddScoped<IDeviceService, DeviceService>();
services.AddScoped<IBlockIpService, AzureQueueBlockIpService>();
services.AddScoped<IOrganizationService, OrganizationService>();
// Cors
services.AddCors(config =>