mirror of
https://github.com/bitwarden/server.git
synced 2025-02-18 02:11:22 +01:00
Added favorites to ciphers and exposed PUT favorite cipher API
This commit is contained in:
parent
ed0c6ad795
commit
4f59f38326
@ -70,6 +70,20 @@ namespace Bit.Api.Controllers
|
|||||||
model.FolderRelationships);
|
model.FolderRelationships);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[HttpPut("{id}/favorite")]
|
||||||
|
public async Task Favorite(string id)
|
||||||
|
{
|
||||||
|
var cipher = await _cipherRepository.GetByIdAsync(new Guid(id), new Guid(_userManager.GetUserId(User)));
|
||||||
|
if(cipher == null)
|
||||||
|
{
|
||||||
|
throw new NotFoundException();
|
||||||
|
}
|
||||||
|
|
||||||
|
cipher.Favorite = !cipher.Favorite;
|
||||||
|
|
||||||
|
await _cipherRepository.ReplaceAsync(cipher);
|
||||||
|
}
|
||||||
|
|
||||||
[HttpDelete("{id}")]
|
[HttpDelete("{id}")]
|
||||||
public async Task Delete(string id)
|
public async Task Delete(string id)
|
||||||
{
|
{
|
||||||
|
@ -10,6 +10,7 @@ namespace Bit.Api.Models
|
|||||||
{
|
{
|
||||||
[StringLength(36)]
|
[StringLength(36)]
|
||||||
public string FolderId { get; set; }
|
public string FolderId { get; set; }
|
||||||
|
public bool Favorite { get; set; }
|
||||||
[Required]
|
[Required]
|
||||||
[EncryptedString]
|
[EncryptedString]
|
||||||
[StringLength(300)]
|
[StringLength(300)]
|
||||||
@ -40,6 +41,7 @@ namespace Bit.Api.Models
|
|||||||
public Cipher ToCipher(Cipher existingSite)
|
public Cipher ToCipher(Cipher existingSite)
|
||||||
{
|
{
|
||||||
existingSite.FolderId = string.IsNullOrWhiteSpace(FolderId) ? null : (Guid?)new Guid(FolderId);
|
existingSite.FolderId = string.IsNullOrWhiteSpace(FolderId) ? null : (Guid?)new Guid(FolderId);
|
||||||
|
existingSite.Favorite = Favorite;
|
||||||
existingSite.Data = JsonConvert.SerializeObject(new SiteDataModel(this), new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore });
|
existingSite.Data = JsonConvert.SerializeObject(new SiteDataModel(this), new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore });
|
||||||
existingSite.Type = Core.Enums.CipherType.Site;
|
existingSite.Type = Core.Enums.CipherType.Site;
|
||||||
|
|
||||||
|
@ -16,6 +16,7 @@ namespace Bit.Api.Models
|
|||||||
Id = cipher.Id.ToString();
|
Id = cipher.Id.ToString();
|
||||||
FolderId = cipher.FolderId?.ToString();
|
FolderId = cipher.FolderId?.ToString();
|
||||||
Type = cipher.Type;
|
Type = cipher.Type;
|
||||||
|
Favorite = cipher.Favorite;
|
||||||
Data = cipher.Data;
|
Data = cipher.Data;
|
||||||
RevisionDate = cipher.RevisionDate;
|
RevisionDate = cipher.RevisionDate;
|
||||||
|
|
||||||
@ -35,6 +36,7 @@ namespace Bit.Api.Models
|
|||||||
public string Id { get; set; }
|
public string Id { get; set; }
|
||||||
public string FolderId { get; set; }
|
public string FolderId { get; set; }
|
||||||
public Core.Enums.CipherType Type { get; set; }
|
public Core.Enums.CipherType Type { get; set; }
|
||||||
|
public bool Favorite { get; set; }
|
||||||
public dynamic Data { get; set; }
|
public dynamic Data { get; set; }
|
||||||
public DateTime RevisionDate { get; set; }
|
public DateTime RevisionDate { get; set; }
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
using System;
|
using System;
|
||||||
using Bit.Core.Domains;
|
using Bit.Core.Domains;
|
||||||
using Newtonsoft.Json;
|
|
||||||
|
|
||||||
namespace Bit.Api.Models
|
namespace Bit.Api.Models
|
||||||
{
|
{
|
||||||
@ -23,6 +22,7 @@ namespace Bit.Api.Models
|
|||||||
|
|
||||||
Id = cipher.Id.ToString();
|
Id = cipher.Id.ToString();
|
||||||
FolderId = cipher.FolderId?.ToString();
|
FolderId = cipher.FolderId?.ToString();
|
||||||
|
Favorite = cipher.Favorite;
|
||||||
Name = data.Name;
|
Name = data.Name;
|
||||||
Uri = data.Uri;
|
Uri = data.Uri;
|
||||||
Username = data.Username;
|
Username = data.Username;
|
||||||
@ -33,6 +33,7 @@ namespace Bit.Api.Models
|
|||||||
|
|
||||||
public string Id { get; set; }
|
public string Id { get; set; }
|
||||||
public string FolderId { get; set; }
|
public string FolderId { get; set; }
|
||||||
|
public bool Favorite { get; set; }
|
||||||
public string Name { get; set; }
|
public string Name { get; set; }
|
||||||
public string Uri { get; set; }
|
public string Uri { get; set; }
|
||||||
public string Username { get; set; }
|
public string Username { get; set; }
|
||||||
|
@ -9,6 +9,7 @@ namespace Bit.Core.Domains
|
|||||||
public Guid UserId { get; set; }
|
public Guid UserId { get; set; }
|
||||||
public Guid? FolderId { get; set; }
|
public Guid? FolderId { get; set; }
|
||||||
public Enums.CipherType Type { get; set; }
|
public Enums.CipherType Type { get; set; }
|
||||||
|
public bool Favorite { get; set; }
|
||||||
public string Data { get; set; }
|
public string Data { get; set; }
|
||||||
public DateTime CreationDate { get; internal set; } = DateTime.UtcNow;
|
public DateTime CreationDate { get; internal set; } = DateTime.UtcNow;
|
||||||
public DateTime RevisionDate { get; internal set; } = DateTime.UtcNow;
|
public DateTime RevisionDate { get; internal set; } = DateTime.UtcNow;
|
||||||
|
@ -138,6 +138,7 @@ namespace Bit.Core.Repositories.SqlServer
|
|||||||
-- Do not update [UserId]
|
-- Do not update [UserId]
|
||||||
-- Do not update [FolderId]
|
-- Do not update [FolderId]
|
||||||
-- Do not update [Type]
|
-- Do not update [Type]
|
||||||
|
-- Do not update [Favorite]
|
||||||
[Data] = TC.[Data],
|
[Data] = TC.[Data],
|
||||||
-- Do not update [CreationDate]
|
-- Do not update [CreationDate]
|
||||||
[RevisionDate] = TC.[RevisionDate]
|
[RevisionDate] = TC.[RevisionDate]
|
||||||
|
Loading…
Reference in New Issue
Block a user