mirror of
https://github.com/bitwarden/server.git
synced 2024-11-25 12:45:18 +01:00
model validation
This commit is contained in:
parent
472a4ade8f
commit
73b23a53ea
@ -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()));
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user