mirror of
https://github.com/bitwarden/server.git
synced 2025-04-07 05:58:13 -05:00
dep. history and favorites apis. backwards compat
This commit is contained in:
parent
c6ef3dc283
commit
09048cf98f
@ -85,15 +85,12 @@ namespace Bit.Api.Controllers
|
||||
return new ListResponseModel<CipherDetailsResponseModel>(responses);
|
||||
}
|
||||
|
||||
//[Obsolete]
|
||||
//[HttpGet("history")]
|
||||
//public async Task<CipherHistoryResponseModel> Get(DateTime since)
|
||||
//{
|
||||
// var userId = _userService.GetProperUserId(User).Value;
|
||||
// var history = await _cipherRepository.GetManySinceRevisionDateAndUserIdWithDeleteHistoryAsync(
|
||||
// since, userId);
|
||||
// return new CipherHistoryResponseModel(history.Item1, history.Item2, userId);
|
||||
//}
|
||||
[Obsolete]
|
||||
[HttpGet("history")]
|
||||
public Task<CipherHistoryResponseModel> Get(DateTime since)
|
||||
{
|
||||
return Task.FromResult(new CipherHistoryResponseModel());
|
||||
}
|
||||
|
||||
[HttpPost("import")]
|
||||
public async Task PostImport([FromBody]ImportRequestModel model)
|
||||
@ -108,20 +105,20 @@ namespace Bit.Api.Controllers
|
||||
model.FolderRelationships);
|
||||
}
|
||||
|
||||
//[HttpPut("{id}/favorite")]
|
||||
//[HttpPost("{id}/favorite")]
|
||||
//public async Task Favorite(string id)
|
||||
//{
|
||||
// var cipher = await _cipherRepository.GetByIdAsync(new Guid(id), _userService.GetProperUserId(User).Value);
|
||||
// if(cipher == null)
|
||||
// {
|
||||
// throw new NotFoundException();
|
||||
// }
|
||||
[Obsolete]
|
||||
[HttpPut("{id}/favorite")]
|
||||
[HttpPost("{id}/favorite")]
|
||||
public async Task Favorite(string id)
|
||||
{
|
||||
var userId = _userService.GetProperUserId(User).Value;
|
||||
var cipher = await _cipherRepository.GetByIdAsync(new Guid(id), userId);
|
||||
if(cipher == null)
|
||||
{
|
||||
throw new NotFoundException();
|
||||
}
|
||||
|
||||
// cipher.Favorite = !cipher.Favorite;
|
||||
|
||||
// await _cipherService.SaveAsync(cipher);
|
||||
//}
|
||||
await _cipherService.UpdatePartialAsync(new Guid(id), userId, cipher.FolderId, !cipher.Favorite);
|
||||
}
|
||||
|
||||
[HttpPut("{id}/partial")]
|
||||
[HttpPost("{id}/partial")]
|
||||
|
@ -1,30 +1,16 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Bit.Core.Models.Table;
|
||||
|
||||
namespace Bit.Core.Models.Api
|
||||
{
|
||||
[Obsolete]
|
||||
public class CipherHistoryResponseModel : ResponseModel
|
||||
{
|
||||
public CipherHistoryResponseModel(IEnumerable<Cipher> revisedCiphers, IEnumerable<Guid> deletedIds, Guid userId)
|
||||
public CipherHistoryResponseModel()
|
||||
: base("cipherHistory")
|
||||
{
|
||||
if(revisedCiphers == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(revisedCiphers));
|
||||
}
|
||||
{ }
|
||||
|
||||
if(deletedIds == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(deletedIds));
|
||||
}
|
||||
|
||||
//Revised = revisedCiphers.Select(c => new CipherResponseModel(c));
|
||||
Deleted = deletedIds.Select(id => id.ToString());
|
||||
}
|
||||
|
||||
public IEnumerable<CipherResponseModel> Revised { get; set; }
|
||||
public IEnumerable<string> Deleted { get; set; }
|
||||
public IEnumerable<CipherResponseModel> Revised { get; set; } = new List<CipherResponseModel>();
|
||||
public IEnumerable<string> Deleted { get; set; } = new List<string>();
|
||||
}
|
||||
}
|
||||
|
@ -13,8 +13,6 @@ namespace Bit.Core.Repositories
|
||||
Task<ICollection<CipherDetails>> GetManyByUserIdAsync(Guid userId);
|
||||
Task<ICollection<CipherDetails>> GetManyByUserIdHasSubvaultsAsync(Guid userId);
|
||||
Task<ICollection<CipherDetails>> GetManyByTypeAndUserIdAsync(Enums.CipherType type, Guid userId);
|
||||
Task<Tuple<ICollection<CipherDetails>, ICollection<Guid>>> GetManySinceRevisionDateAndUserIdWithDeleteHistoryAsync(
|
||||
DateTime sinceRevisionDate, Guid userId);
|
||||
Task CreateAsync(CipherDetails cipher);
|
||||
Task ReplaceAsync(CipherDetails cipher);
|
||||
Task UpsertAsync(CipherDetails cipher);
|
||||
|
@ -92,27 +92,6 @@ namespace Bit.Core.Repositories.SqlServer
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<Tuple<ICollection<CipherDetails>, ICollection<Guid>>>
|
||||
GetManySinceRevisionDateAndUserIdWithDeleteHistoryAsync(DateTime sinceRevisionDate, Guid userId)
|
||||
{
|
||||
using(var connection = new SqlConnection(ConnectionString))
|
||||
{
|
||||
var results = await connection.QueryMultipleAsync(
|
||||
$"[{Schema}].[CipherDetails_ReadByRevisionDateUserWithDeleteHistory]",
|
||||
new
|
||||
{
|
||||
SinceRevisionDate = sinceRevisionDate,
|
||||
UserId = userId
|
||||
},
|
||||
commandType: CommandType.StoredProcedure);
|
||||
|
||||
var ciphers = await results.ReadAsync<CipherDetails>();
|
||||
var deletes = await results.ReadAsync<Guid>();
|
||||
|
||||
return new Tuple<ICollection<CipherDetails>, ICollection<Guid>>(ciphers.ToList(), deletes.ToList());
|
||||
}
|
||||
}
|
||||
|
||||
public async Task CreateAsync(CipherDetails cipher)
|
||||
{
|
||||
cipher.SetNewId();
|
||||
|
@ -68,7 +68,6 @@
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Build Include="dbo\Tables\Device.sql" />
|
||||
<Build Include="dbo\Tables\History.sql" />
|
||||
<Build Include="dbo\Tables\Cipher.sql" />
|
||||
<Build Include="dbo\Tables\FolderCipher.sql" />
|
||||
<Build Include="dbo\Tables\Grant.sql" />
|
||||
@ -85,7 +84,6 @@
|
||||
<Build Include="dbo\Tables\SubvaultUser.sql" />
|
||||
<Build Include="dbo\Views\SubvaultUserView.sql" />
|
||||
<Build Include="dbo\Views\DeviceView.sql" />
|
||||
<Build Include="dbo\Views\HistoryView.sql" />
|
||||
<Build Include="dbo\Views\FolderView.sql" />
|
||||
<Build Include="dbo\Views\CipherView.sql" />
|
||||
<Build Include="dbo\Views\OrganizationUserView.sql" />
|
||||
@ -123,7 +121,6 @@
|
||||
<Build Include="dbo\Stored Procedures\Device_ReadById.sql" />
|
||||
<Build Include="dbo\Stored Procedures\Organization_DeleteById.sql" />
|
||||
<Build Include="dbo\Stored Procedures\Device_ReadByIdentifierUserId.sql" />
|
||||
<Build Include="dbo\Stored Procedures\CipherDetails_ReadByRevisionDateUserWithDeleteHistory.sql" />
|
||||
<Build Include="dbo\Stored Procedures\Organization_ReadById.sql" />
|
||||
<Build Include="dbo\Stored Procedures\Device_ReadByUserId.sql" />
|
||||
<Build Include="dbo\Stored Procedures\CipherDetails_ReadByTypeUserId.sql" />
|
||||
@ -131,7 +128,6 @@
|
||||
<Build Include="dbo\Stored Procedures\Device_Update.sql" />
|
||||
<Build Include="dbo\Stored Procedures\CipherDetails_ReadByUserId.sql" />
|
||||
<Build Include="dbo\Stored Procedures\OrganizationUser_Create.sql" />
|
||||
<Build Include="dbo\Stored Procedures\History_ReadById.sql" />
|
||||
<Build Include="dbo\Stored Procedures\CipherDetails_ReadByUserIdHasSubvault.sql" />
|
||||
<Build Include="dbo\Stored Procedures\OrganizationUser_DeleteById.sql" />
|
||||
<Build Include="dbo\Stored Procedures\User_Create.sql" />
|
||||
|
@ -1,24 +0,0 @@
|
||||
CREATE PROCEDURE [dbo].[CipherDetails_ReadByRevisionDateUserWithDeleteHistory]
|
||||
@SinceRevisionDate DATETIME2(7),
|
||||
@UserId UNIQUEIDENTIFIER
|
||||
AS
|
||||
BEGIN
|
||||
SET NOCOUNT ON
|
||||
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
[dbo].[CipherDetails](@UserId) C
|
||||
WHERE
|
||||
[RevisionDate] > @SinceRevisionDate
|
||||
AND [UserId] = @UserId
|
||||
|
||||
SELECT
|
||||
[CipherId]
|
||||
FROM
|
||||
[dbo].[History]
|
||||
WHERE
|
||||
[Date] > @SinceRevisionDate
|
||||
AND [Event] = 2 -- Only cipher delete events.
|
||||
AND [UserId] = @UserId
|
||||
END
|
@ -1,13 +0,0 @@
|
||||
CREATE PROCEDURE [dbo].[History_ReadById]
|
||||
@Id BIGINT
|
||||
AS
|
||||
BEGIN
|
||||
SET NOCOUNT ON
|
||||
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
[dbo].[HistoryView]
|
||||
WHERE
|
||||
[Id] = @Id
|
||||
END
|
@ -26,21 +26,6 @@ BEGIN
|
||||
|
||||
SET NOCOUNT ON
|
||||
|
||||
INSERT INTO [dbo].[History]
|
||||
(
|
||||
[UserId],
|
||||
[CipherId],
|
||||
[Event],
|
||||
[Date]
|
||||
)
|
||||
SELECT
|
||||
[UserId],
|
||||
[Id],
|
||||
0, --Insert
|
||||
[CreationDate]
|
||||
FROM
|
||||
INSERTED
|
||||
|
||||
DECLARE @UserId UNIQUEIDENTIFIER = (SELECT TOP 1 [UserId] FROM INSERTED)
|
||||
|
||||
UPDATE
|
||||
@ -61,21 +46,6 @@ BEGIN
|
||||
|
||||
SET NOCOUNT ON
|
||||
|
||||
INSERT INTO [dbo].[History]
|
||||
(
|
||||
[UserId],
|
||||
[CipherId],
|
||||
[Event],
|
||||
[Date]
|
||||
)
|
||||
SELECT
|
||||
[UserId],
|
||||
[Id],
|
||||
1, --Update
|
||||
[RevisionDate]
|
||||
FROM
|
||||
INSERTED
|
||||
|
||||
DECLARE @UserId UNIQUEIDENTIFIER = (SELECT TOP 1 [UserId] FROM INSERTED)
|
||||
|
||||
UPDATE
|
||||
@ -96,21 +66,6 @@ BEGIN
|
||||
|
||||
SET NOCOUNT ON
|
||||
|
||||
INSERT INTO [dbo].[History]
|
||||
(
|
||||
[UserId],
|
||||
[CipherId],
|
||||
[Event],
|
||||
[Date]
|
||||
)
|
||||
SELECT
|
||||
[UserId],
|
||||
[Id],
|
||||
2, --Delete
|
||||
GETUTCDATE()
|
||||
FROM
|
||||
DELETED
|
||||
|
||||
DECLARE @UserId UNIQUEIDENTIFIER = (SELECT TOP 1 [UserId] FROM DELETED)
|
||||
|
||||
UPDATE
|
||||
|
@ -1,9 +0,0 @@
|
||||
CREATE TABLE [dbo].[History] (
|
||||
[Id] BIGINT IDENTITY (1, 1) NOT NULL,
|
||||
[UserId] UNIQUEIDENTIFIER NULL,
|
||||
[CipherId] UNIQUEIDENTIFIER NOT NULL,
|
||||
[Event] TINYINT NOT NULL,
|
||||
[Date] DATETIME2 (7) NOT NULL,
|
||||
CONSTRAINT [PK_CipherHistory] PRIMARY KEY CLUSTERED ([Id] ASC)
|
||||
);
|
||||
|
@ -1,6 +0,0 @@
|
||||
CREATE VIEW [dbo].[HistoryView]
|
||||
AS
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
[dbo].[History]
|
Loading…
x
Reference in New Issue
Block a user