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

deprecated logins api and moved to ciphers

This commit is contained in:
Kyle Spearrin
2017-09-20 23:52:45 -04:00
parent 3fdf2eb4ad
commit 12650a0ada
6 changed files with 171 additions and 77 deletions

View File

@ -9,7 +9,7 @@ namespace Bit.Core.Models.Api
[StringLength(300)]
public string MasterPasswordHash { get; set; }
[Required]
public IEnumerable<LoginWithIdRequestModel> Ciphers { get; set; }
public IEnumerable<CipherWithIdRequestModel> Ciphers { get; set; }
[Required]
public IEnumerable<FolderWithIdRequestModel> Folders { get; set; }
[Required]

View File

@ -6,6 +6,7 @@ using Bit.Core.Enums;
using Newtonsoft.Json;
using System.Collections.Generic;
using System.Linq;
using Core.Models.Data;
namespace Bit.Core.Models.Api
{
@ -13,11 +14,10 @@ namespace Bit.Core.Models.Api
{
public CipherType Type { get; set; }
[Required]
[StringLength(36)]
public string Id { get; set; }
[StringLength(36)]
public string OrganizationId { get; set; }
public string FolderId { get; set; }
public bool Favorite { get; set; }
[Required]
[EncryptedString]
[StringLength(1000)]
@ -40,7 +40,28 @@ namespace Bit.Core.Models.Api
public IEnumerable<FieldDataModel> Fields { get; set; }
public Dictionary<string, string> Attachments { get; set; }
public virtual Cipher ToCipher(Cipher existingCipher)
public CipherDetails ToCipherDetails(Guid userId)
{
var cipher = new CipherDetails
{
Type = Type,
UserId = string.IsNullOrWhiteSpace(OrganizationId) ? (Guid?)userId : null,
OrganizationId = string.IsNullOrWhiteSpace(OrganizationId) ? (Guid?)null : new Guid(OrganizationId),
Edit = true
};
ToCipherDetails(cipher);
return cipher;
}
public CipherDetails ToCipherDetails(CipherDetails existingCipher)
{
existingCipher.FolderId = string.IsNullOrWhiteSpace(FolderId) ? null : (Guid?)new Guid(FolderId);
existingCipher.Favorite = Favorite;
ToCipher(existingCipher);
return existingCipher;
}
public Cipher ToCipher(Cipher existingCipher)
{
switch(existingCipher.Type)
{
@ -71,6 +92,46 @@ namespace Bit.Core.Models.Api
existingCipher.SetAttachments(attachments);
return existingCipher;
}
public CipherDetails ToOrganizationCipherDetails(Guid orgId)
{
return ToCipherDetails(new CipherDetails
{
Type = Type,
OrganizationId = orgId,
Edit = true
});
}
public Cipher ToOrganizationCipher()
{
if(string.IsNullOrWhiteSpace(OrganizationId))
{
throw new ArgumentNullException(nameof(OrganizationId));
}
return ToCipher(new Cipher
{
Type = Type,
OrganizationId = new Guid(OrganizationId)
});
}
}
public class CipherWithIdRequestModel : CipherRequestModel
{
[Required]
[StringLength(36)]
public string Id { get; set; }
public Cipher ToCipher(Guid userId)
{
return ToCipherDetails(new CipherDetails
{
UserId = userId,
Id = new Guid(Id)
});
}
}
public class CipherShareRequestModel : IValidatableObject

View File

@ -89,18 +89,4 @@ namespace Bit.Core.Models.Api
return existingLogin;
}
}
public class LoginWithIdRequestModel : LoginRequestModel
{
public Guid Id { get; set; }
public Cipher ToCipher(Guid userId)
{
return ToCipherDetails(new CipherDetails
{
UserId = userId,
Id = Id
});
}
}
}

View File

@ -8,7 +8,7 @@ namespace Bit.Core.Models.Api
{
public class CipherMiniResponseModel : ResponseModel
{
public CipherMiniResponseModel(Cipher cipher, GlobalSettings globalSettings, string obj = "cipherMini")
public CipherMiniResponseModel(Cipher cipher, GlobalSettings globalSettings, bool orgUseTotp, string obj = "cipherMini")
: base(obj)
{
if(cipher == null)
@ -21,6 +21,7 @@ namespace Bit.Core.Models.Api
RevisionDate = cipher.RevisionDate;
OrganizationId = cipher.OrganizationId?.ToString();
Attachments = AttachmentResponseModel.FromCipher(cipher, globalSettings);
OrganizationUseTotp = orgUseTotp;
switch(cipher.Type)
{
@ -37,24 +38,23 @@ namespace Bit.Core.Models.Api
public Enums.CipherType Type { get; set; }
public dynamic Data { get; set; }
public IEnumerable<AttachmentResponseModel> Attachments { get; set; }
public bool OrganizationUseTotp { get; set; }
public DateTime RevisionDate { get; set; }
}
public class CipherResponseModel : CipherMiniResponseModel
{
public CipherResponseModel(CipherDetails cipher, GlobalSettings globalSettings, string obj = "cipher")
: base(cipher, globalSettings, obj)
: base(cipher, globalSettings, cipher.OrganizationUseTotp, obj)
{
FolderId = cipher.FolderId?.ToString();
Favorite = cipher.Favorite;
Edit = cipher.Edit;
OrganizationUseTotp = cipher.OrganizationUseTotp;
}
public string FolderId { get; set; }
public bool Favorite { get; set; }
public bool Edit { get; set; }
public bool OrganizationUseTotp { get; set; }
}
public class CipherDetailsResponseModel : CipherResponseModel
@ -87,7 +87,7 @@ namespace Bit.Core.Models.Api
{
public CipherMiniDetailsResponseModel(Cipher cipher, GlobalSettings globalSettings,
IDictionary<Guid, IGrouping<Guid, CollectionCipher>> collectionCiphers, string obj = "cipherMiniDetails")
: base(cipher, globalSettings, obj)
: base(cipher, globalSettings, false, obj)
{
if(collectionCiphers.ContainsKey(cipher.Id))
{