mirror of
https://github.com/bitwarden/server.git
synced 2025-04-13 09:08:17 -05:00
backwards compat apis on Uri
This commit is contained in:
parent
c8aabf0b40
commit
2b276e9986
@ -6,6 +6,8 @@ namespace Bit.Core.Models.Api
|
||||
{
|
||||
public class CipherFieldModel
|
||||
{
|
||||
public CipherFieldModel() { }
|
||||
|
||||
public CipherFieldModel(CipherFieldData data)
|
||||
{
|
||||
Type = data.Type;
|
||||
|
@ -4,14 +4,22 @@ using Bit.Core.Enums;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Bit.Core.Models.Data;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace Bit.Core.Models.Api
|
||||
{
|
||||
public class CipherLoginModel
|
||||
{
|
||||
public CipherLoginModel() { }
|
||||
|
||||
public CipherLoginModel(CipherLoginData data)
|
||||
{
|
||||
Uris = data.Uris.Select(u => new LoginApiUriModel(u));
|
||||
Uris = data.Uris?.Select(u => new CipherLoginUriModel(u))?.ToList();
|
||||
if(!Uris?.Any() ?? true)
|
||||
{
|
||||
Uri = data.Uri;
|
||||
}
|
||||
|
||||
Username = data.Username;
|
||||
Password = data.Password;
|
||||
Totp = data.Totp;
|
||||
@ -24,15 +32,20 @@ namespace Bit.Core.Models.Api
|
||||
get => Uris?.FirstOrDefault()?.Uri;
|
||||
set
|
||||
{
|
||||
if(Uris == null)
|
||||
if(string.IsNullOrWhiteSpace(value))
|
||||
{
|
||||
Uris = new List<LoginApiUriModel>();
|
||||
return;
|
||||
}
|
||||
|
||||
Uris.Append(new LoginApiUriModel(value));
|
||||
if(Uris == null)
|
||||
{
|
||||
Uris = new List<CipherLoginUriModel>();
|
||||
}
|
||||
|
||||
Uris.Add(new CipherLoginUriModel(value));
|
||||
}
|
||||
}
|
||||
public IEnumerable<LoginApiUriModel> Uris { get; set; }
|
||||
public List<CipherLoginUriModel> Uris { get; set; }
|
||||
[EncryptedString]
|
||||
[StringLength(1000)]
|
||||
public string Username { get; set; }
|
||||
@ -43,17 +56,16 @@ namespace Bit.Core.Models.Api
|
||||
[StringLength(1000)]
|
||||
public string Totp { get; set; }
|
||||
|
||||
public class LoginApiUriModel
|
||||
public class CipherLoginUriModel
|
||||
{
|
||||
public LoginApiUriModel() { }
|
||||
public CipherLoginUriModel() { }
|
||||
|
||||
public LoginApiUriModel(string uri)
|
||||
public CipherLoginUriModel(string uri)
|
||||
{
|
||||
Uri = uri;
|
||||
Match = UriMatchType.BaseDomain;
|
||||
}
|
||||
|
||||
public LoginApiUriModel(CipherLoginData.LoginDataUriModel uri)
|
||||
public CipherLoginUriModel(CipherLoginData.CipherLoginUriData uri)
|
||||
{
|
||||
Uri = uri.Uri;
|
||||
Match = uri.Match;
|
||||
@ -62,7 +74,7 @@ namespace Bit.Core.Models.Api
|
||||
[EncryptedString]
|
||||
[StringLength(10000)]
|
||||
public string Uri { get; set; }
|
||||
public UriMatchType Match { get; set; }
|
||||
public UriMatchType? Match { get; set; }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -8,6 +8,7 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Core.Models.Data;
|
||||
using Bit.Core.Models.Data;
|
||||
using Newtonsoft.Json.Linq;
|
||||
|
||||
namespace Bit.Core.Models.Api
|
||||
{
|
||||
@ -60,8 +61,10 @@ namespace Bit.Core.Models.Api
|
||||
switch(existingCipher.Type)
|
||||
{
|
||||
case CipherType.Login:
|
||||
existingCipher.Data = JsonConvert.SerializeObject(new CipherLoginData(this),
|
||||
new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore });
|
||||
var loginObj = JObject.FromObject(new CipherLoginData(this),
|
||||
new JsonSerializer { NullValueHandling = NullValueHandling.Ignore });
|
||||
loginObj[nameof(CipherLoginData.Uri)]?.Parent?.Remove();
|
||||
existingCipher.Data = loginObj.ToString(Formatting.None);
|
||||
break;
|
||||
case CipherType.Card:
|
||||
existingCipher.Data = JsonConvert.SerializeObject(new CipherCardData(this),
|
||||
|
@ -54,7 +54,7 @@ namespace Bit.Core.Models.Api
|
||||
|
||||
Name = cipherData.Name;
|
||||
Notes = cipherData.Notes;
|
||||
Fields = cipherData.Fields.Select(f => new CipherFieldModel(f));
|
||||
Fields = cipherData.Fields?.Select(f => new CipherFieldModel(f));
|
||||
RevisionDate = cipher.RevisionDate;
|
||||
OrganizationId = cipher.OrganizationId?.ToString();
|
||||
Attachments = AttachmentResponseModel.FromCipher(cipher, globalSettings);
|
||||
|
@ -12,7 +12,7 @@ namespace Bit.Core.Models.Data
|
||||
{
|
||||
Name = cipher.Name;
|
||||
Notes = cipher.Notes;
|
||||
Fields = cipher.Fields.Select(f => new CipherFieldData(f));
|
||||
Fields = cipher.Fields?.Select(f => new CipherFieldData(f));
|
||||
}
|
||||
|
||||
public string Name { get; set; }
|
||||
|
@ -7,34 +7,41 @@ namespace Bit.Core.Models.Data
|
||||
{
|
||||
public class CipherLoginData : CipherData
|
||||
{
|
||||
private string _uri;
|
||||
|
||||
public CipherLoginData() { }
|
||||
|
||||
public CipherLoginData(CipherRequestModel cipher)
|
||||
: base(cipher)
|
||||
{
|
||||
Uris = cipher.Login.Uris?.Where(u => u != null).Select(u => new LoginDataUriModel(u));
|
||||
Uris = cipher.Login.Uris?.Where(u => u != null).Select(u => new CipherLoginUriData(u));
|
||||
Username = cipher.Login.Username;
|
||||
Password = cipher.Login.Password;
|
||||
Totp = cipher.Login.Totp;
|
||||
}
|
||||
|
||||
public IEnumerable<LoginDataUriModel> Uris { get; set; }
|
||||
public string Uri
|
||||
{
|
||||
get => Uris?.FirstOrDefault()?.Uri ?? _uri;
|
||||
set { _uri = value; }
|
||||
}
|
||||
public IEnumerable<CipherLoginUriData> Uris { get; set; }
|
||||
public string Username { get; set; }
|
||||
public string Password { get; set; }
|
||||
public string Totp { get; set; }
|
||||
|
||||
public class LoginDataUriModel
|
||||
public class CipherLoginUriData
|
||||
{
|
||||
public LoginDataUriModel() { }
|
||||
public CipherLoginUriData() { }
|
||||
|
||||
public LoginDataUriModel(CipherLoginModel.LoginApiUriModel uri)
|
||||
public CipherLoginUriData(CipherLoginModel.CipherLoginUriModel uri)
|
||||
{
|
||||
Uri = uri.Uri;
|
||||
Match = uri.Match;
|
||||
}
|
||||
|
||||
public string Uri { get; set; }
|
||||
public UriMatchType Match { get; set; }
|
||||
public UriMatchType? Match { get; set; }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user