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

model validation

This commit is contained in:
Kyle Spearrin 2017-03-28 22:03:57 -04:00
parent 472a4ade8f
commit 73b23a53ea
2 changed files with 14 additions and 10 deletions

View File

@ -58,7 +58,7 @@ namespace Bit.Api.Controllers
public async Task Invite(string orgId, [FromBody]OrganizationUserInviteRequestModel model)
{
var userId = _userService.GetProperUserId(User);
var result = await _organizationService.InviteUserAsync(new Guid(orgId), userId.Value, model.Email, model.Type,
var result = await _organizationService.InviteUserAsync(new Guid(orgId), userId.Value, model.Email, model.Type.Value,
model.Subvaults?.Select(s => s.ToSubvaultUser()));
}

View File

@ -1,40 +1,48 @@
using Bit.Core.Models.Table;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
namespace Bit.Core.Models.Api
{
public class OrganizationUserInviteRequestModel
{
[Required]
[EmailAddress]
public string Email { get; set; }
public Enums.OrganizationUserType Type { get; set; }
[Required]
public Enums.OrganizationUserType? Type { get; set; }
public IEnumerable<OrganizationUserSubvaultRequestModel> Subvaults { get; set; }
}
public class OrganizationUserAcceptRequestModel
{
[Required]
public string Token { get; set; }
}
public class OrganizationUserConfirmRequestModel
{
[Required]
public string Key { get; set; }
}
public class OrganizationUserUpdateRequestModel
{
public Enums.OrganizationUserType Type { get; set; }
[Required]
public Enums.OrganizationUserType? Type { get; set; }
public IEnumerable<OrganizationUserSubvaultRequestModel> Subvaults { get; set; }
public OrganizationUser ToOrganizationUser(OrganizationUser existingUser)
{
existingUser.Type = Type;
existingUser.Type = Type.Value;
return existingUser;
}
}
public class OrganizationUserSubvaultRequestModel
{
[Required]
public string SubvaultId { get; set; }
public bool Admin { get; set; }
public bool ReadOnly { get; set; }
@ -44,14 +52,10 @@ namespace Bit.Core.Models.Api
var subvault = new SubvaultUser
{
Admin = Admin,
ReadOnly = ReadOnly
ReadOnly = ReadOnly,
SubvaultId = new Guid(SubvaultId)
};
if(!string.IsNullOrWhiteSpace(SubvaultId))
{
subvault.SubvaultId = new Guid(SubvaultId);
}
return subvault;
}
}