1
0
mirror of https://github.com/bitwarden/server.git synced 2025-06-30 15:42:48 -05:00

apis for creating ciphers with org & collections

This commit is contained in:
Kyle Spearrin
2018-10-19 12:07:31 -04:00
parent e3f94bb67b
commit 96b492fa07
12 changed files with 437 additions and 61 deletions

View File

@ -36,13 +36,14 @@ namespace Bit.Core.Models.Api
public CipherIdentityModel Identity { get; set; }
public CipherSecureNoteModel SecureNote { get; set; }
public CipherDetails ToCipherDetails(Guid userId)
public CipherDetails ToCipherDetails(Guid userId, bool allowOrgIdSet = true)
{
var hasOrgId = !string.IsNullOrWhiteSpace(OrganizationId);
var cipher = new CipherDetails
{
Type = Type,
UserId = string.IsNullOrWhiteSpace(OrganizationId) ? (Guid?)userId : null,
OrganizationId = null,
UserId = !hasOrgId ? (Guid?)userId : null,
OrganizationId = allowOrgIdSet && hasOrgId ? new Guid(OrganizationId) : (Guid?)null,
Edit = true
};
ToCipherDetails(cipher);
@ -142,6 +143,22 @@ namespace Bit.Core.Models.Api
}
}
public class CipherCreateRequestModel : IValidatableObject
{
public IEnumerable<Guid> CollectionIds { get; set; }
[Required]
public CipherRequestModel Cipher { get; set; }
public IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
{
if(!string.IsNullOrWhiteSpace(Cipher.OrganizationId) && (!CollectionIds?.Any() ?? true))
{
yield return new ValidationResult("You must select at least one collection.",
new string[] { nameof(CollectionIds) });
}
}
}
public class CipherShareRequestModel : IValidatableObject
{
[Required]