1
0
mirror of https://github.com/bitwarden/server.git synced 2025-06-30 23:52:50 -05:00

Move into and read ciphers from org subvaults

This commit is contained in:
Kyle Spearrin
2017-03-21 00:04:39 -04:00
parent 4779794599
commit ed8d5d69a4
22 changed files with 283 additions and 16 deletions

View File

@ -4,6 +4,7 @@ using Bit.Core.Utilities;
using Bit.Core.Models.Table;
using Bit.Core.Enums;
using Newtonsoft.Json;
using System.Collections.Generic;
namespace Bit.Core.Models.Api
{
@ -15,6 +16,8 @@ namespace Bit.Core.Models.Api
[StringLength(36)]
public string Id { get; set; }
[StringLength(36)]
public string OrganizationId { get; set; }
[StringLength(36)]
public string FolderId { get; set; }
[Required]
[EncryptedString]
@ -35,24 +38,35 @@ namespace Bit.Core.Models.Api
public virtual Cipher ToCipher(Guid userId)
{
var cipher = new Cipher
return ToCipher(new Cipher
{
Id = new Guid(Id),
UserId = userId,
//FolderId = string.IsNullOrWhiteSpace(FolderId) ? null : (Guid?)new Guid(FolderId),
UserId = string.IsNullOrWhiteSpace(OrganizationId) ? (Guid?)userId : null,
Type = Type
};
});
}
switch(Type)
public Cipher ToCipher(Cipher existingCipher)
{
existingCipher.OrganizationId = string.IsNullOrWhiteSpace(OrganizationId) ? null : (Guid?)new Guid(OrganizationId);
switch(existingCipher.Type)
{
case CipherType.Login:
cipher.Data = JsonConvert.SerializeObject(new LoginDataModel(this), new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore });
existingCipher.Data = JsonConvert.SerializeObject(new LoginDataModel(this), new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore });
break;
default:
throw new ArgumentException("Unsupported " + nameof(Type) + ".");
}
return cipher;
return existingCipher;
}
}
public class CipherMoveRequestModel
{
public IEnumerable<string> SubvaultIds { get; set; }
[Required]
public CipherRequestModel Cipher { get; set; }
}
}

View File

@ -1,5 +1,8 @@
using System;
using Core.Models.Data;
using System.Collections.Generic;
using Bit.Core.Models.Table;
using System.Linq;
namespace Bit.Core.Models.Api
{
@ -16,6 +19,7 @@ namespace Bit.Core.Models.Api
Id = cipher.Id.ToString();
Type = cipher.Type;
RevisionDate = cipher.RevisionDate;
OrganizationId = cipher.OrganizationId?.ToString();
FolderId = cipher.FolderId?.ToString();
Favorite = cipher.Favorite;
@ -30,10 +34,22 @@ namespace Bit.Core.Models.Api
}
public string Id { get; set; }
public string OrganizationId { get; set; }
public string FolderId { get; set; }
public Enums.CipherType Type { get; set; }
public bool Favorite { get; set; }
public dynamic Data { get; set; }
public DateTime RevisionDate { get; set; }
}
public class CipherDetailsResponseModel : CipherResponseModel
{
public CipherDetailsResponseModel(CipherDetails cipher, IEnumerable<SubvaultCipher> subvaultCipher)
: base(cipher, "cipherDetails")
{
SubvaultIds = subvaultCipher.Select(s => s.SubvaultId);
}
public IEnumerable<Guid> SubvaultIds { get; set; }
}
}

View File

@ -21,6 +21,7 @@ namespace Bit.Core.Models.Api
var data = new LoginDataModel(cipher);
Id = cipher.Id.ToString();
OrganizationId = cipher.OrganizationId?.ToString();
FolderId = cipher.FolderId?.ToString();
Favorite = cipher.Favorite;
Name = data.Name;
@ -32,6 +33,7 @@ namespace Bit.Core.Models.Api
}
public string Id { get; set; }
public string OrganizationId { get; set; }
public string FolderId { get; set; }
public bool Favorite { get; set; }
public string Name { get; set; }

View File

@ -0,0 +1,11 @@
using System;
namespace Bit.Core.Models.Data
{
public class SubvaultUserPermissions
{
public Guid SubvaultId { get; set; }
public bool ReadOnly { get; set; }
public bool Admin { get; set; }
}
}

View File

@ -6,7 +6,7 @@ namespace Bit.Core.Models.Table
public class Cipher : IDataObject<Guid>
{
public Guid Id { get; set; }
public Guid UserId { get; set; }
public Guid? UserId { get; set; }
public Guid? OrganizationId { get; set; }
public Enums.CipherType Type { get; set; }
public string Data { get; set; }

View File

@ -0,0 +1,10 @@
using System;
namespace Bit.Core.Models.Table
{
public class SubvaultCipher
{
public Guid SubvaultId { get; set; }
public Guid CipherId { get; set; }
}
}