1
0
mirror of https://github.com/bitwarden/server.git synced 2025-04-07 14:08:13 -05:00

dep. history and favorites apis. backwards compat

This commit is contained in:
Kyle Spearrin 2017-04-12 14:42:19 -04:00
parent c6ef3dc283
commit 09048cf98f
10 changed files with 25 additions and 166 deletions

View File

@ -85,15 +85,12 @@ namespace Bit.Api.Controllers
return new ListResponseModel<CipherDetailsResponseModel>(responses); return new ListResponseModel<CipherDetailsResponseModel>(responses);
} }
//[Obsolete] [Obsolete]
//[HttpGet("history")] [HttpGet("history")]
//public async Task<CipherHistoryResponseModel> Get(DateTime since) public Task<CipherHistoryResponseModel> Get(DateTime since)
//{ {
// var userId = _userService.GetProperUserId(User).Value; return Task.FromResult(new CipherHistoryResponseModel());
// var history = await _cipherRepository.GetManySinceRevisionDateAndUserIdWithDeleteHistoryAsync( }
// since, userId);
// return new CipherHistoryResponseModel(history.Item1, history.Item2, userId);
//}
[HttpPost("import")] [HttpPost("import")]
public async Task PostImport([FromBody]ImportRequestModel model) public async Task PostImport([FromBody]ImportRequestModel model)
@ -108,20 +105,20 @@ namespace Bit.Api.Controllers
model.FolderRelationships); model.FolderRelationships);
} }
//[HttpPut("{id}/favorite")] [Obsolete]
//[HttpPost("{id}/favorite")] [HttpPut("{id}/favorite")]
//public async Task Favorite(string id) [HttpPost("{id}/favorite")]
//{ public async Task Favorite(string id)
// var cipher = await _cipherRepository.GetByIdAsync(new Guid(id), _userService.GetProperUserId(User).Value); {
// if(cipher == null) var userId = _userService.GetProperUserId(User).Value;
// { var cipher = await _cipherRepository.GetByIdAsync(new Guid(id), userId);
// throw new NotFoundException(); if(cipher == null)
// } {
throw new NotFoundException();
}
// cipher.Favorite = !cipher.Favorite; await _cipherService.UpdatePartialAsync(new Guid(id), userId, cipher.FolderId, !cipher.Favorite);
}
// await _cipherService.SaveAsync(cipher);
//}
[HttpPut("{id}/partial")] [HttpPut("{id}/partial")]
[HttpPost("{id}/partial")] [HttpPost("{id}/partial")]

View File

@ -1,30 +1,16 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq;
using Bit.Core.Models.Table;
namespace Bit.Core.Models.Api namespace Bit.Core.Models.Api
{ {
[Obsolete]
public class CipherHistoryResponseModel : ResponseModel public class CipherHistoryResponseModel : ResponseModel
{ {
public CipherHistoryResponseModel(IEnumerable<Cipher> revisedCiphers, IEnumerable<Guid> deletedIds, Guid userId) public CipherHistoryResponseModel()
: base("cipherHistory") : base("cipherHistory")
{ { }
if(revisedCiphers == null)
{
throw new ArgumentNullException(nameof(revisedCiphers));
}
if(deletedIds == null) public IEnumerable<CipherResponseModel> Revised { get; set; } = new List<CipherResponseModel>();
{ public IEnumerable<string> Deleted { get; set; } = new List<string>();
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; }
} }
} }

View File

@ -13,8 +13,6 @@ namespace Bit.Core.Repositories
Task<ICollection<CipherDetails>> GetManyByUserIdAsync(Guid userId); Task<ICollection<CipherDetails>> GetManyByUserIdAsync(Guid userId);
Task<ICollection<CipherDetails>> GetManyByUserIdHasSubvaultsAsync(Guid userId); Task<ICollection<CipherDetails>> GetManyByUserIdHasSubvaultsAsync(Guid userId);
Task<ICollection<CipherDetails>> GetManyByTypeAndUserIdAsync(Enums.CipherType type, 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 CreateAsync(CipherDetails cipher);
Task ReplaceAsync(CipherDetails cipher); Task ReplaceAsync(CipherDetails cipher);
Task UpsertAsync(CipherDetails cipher); Task UpsertAsync(CipherDetails cipher);

View File

@ -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) public async Task CreateAsync(CipherDetails cipher)
{ {
cipher.SetNewId(); cipher.SetNewId();

View File

@ -68,7 +68,6 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Build Include="dbo\Tables\Device.sql" /> <Build Include="dbo\Tables\Device.sql" />
<Build Include="dbo\Tables\History.sql" />
<Build Include="dbo\Tables\Cipher.sql" /> <Build Include="dbo\Tables\Cipher.sql" />
<Build Include="dbo\Tables\FolderCipher.sql" /> <Build Include="dbo\Tables\FolderCipher.sql" />
<Build Include="dbo\Tables\Grant.sql" /> <Build Include="dbo\Tables\Grant.sql" />
@ -85,7 +84,6 @@
<Build Include="dbo\Tables\SubvaultUser.sql" /> <Build Include="dbo\Tables\SubvaultUser.sql" />
<Build Include="dbo\Views\SubvaultUserView.sql" /> <Build Include="dbo\Views\SubvaultUserView.sql" />
<Build Include="dbo\Views\DeviceView.sql" /> <Build Include="dbo\Views\DeviceView.sql" />
<Build Include="dbo\Views\HistoryView.sql" />
<Build Include="dbo\Views\FolderView.sql" /> <Build Include="dbo\Views\FolderView.sql" />
<Build Include="dbo\Views\CipherView.sql" /> <Build Include="dbo\Views\CipherView.sql" />
<Build Include="dbo\Views\OrganizationUserView.sql" /> <Build Include="dbo\Views\OrganizationUserView.sql" />
@ -123,7 +121,6 @@
<Build Include="dbo\Stored Procedures\Device_ReadById.sql" /> <Build Include="dbo\Stored Procedures\Device_ReadById.sql" />
<Build Include="dbo\Stored Procedures\Organization_DeleteById.sql" /> <Build Include="dbo\Stored Procedures\Organization_DeleteById.sql" />
<Build Include="dbo\Stored Procedures\Device_ReadByIdentifierUserId.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\Organization_ReadById.sql" />
<Build Include="dbo\Stored Procedures\Device_ReadByUserId.sql" /> <Build Include="dbo\Stored Procedures\Device_ReadByUserId.sql" />
<Build Include="dbo\Stored Procedures\CipherDetails_ReadByTypeUserId.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\Device_Update.sql" />
<Build Include="dbo\Stored Procedures\CipherDetails_ReadByUserId.sql" /> <Build Include="dbo\Stored Procedures\CipherDetails_ReadByUserId.sql" />
<Build Include="dbo\Stored Procedures\OrganizationUser_Create.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\CipherDetails_ReadByUserIdHasSubvault.sql" />
<Build Include="dbo\Stored Procedures\OrganizationUser_DeleteById.sql" /> <Build Include="dbo\Stored Procedures\OrganizationUser_DeleteById.sql" />
<Build Include="dbo\Stored Procedures\User_Create.sql" /> <Build Include="dbo\Stored Procedures\User_Create.sql" />

View File

@ -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

View File

@ -1,13 +0,0 @@
CREATE PROCEDURE [dbo].[History_ReadById]
@Id BIGINT
AS
BEGIN
SET NOCOUNT ON
SELECT
*
FROM
[dbo].[HistoryView]
WHERE
[Id] = @Id
END

View File

@ -26,21 +26,6 @@ BEGIN
SET NOCOUNT ON 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) DECLARE @UserId UNIQUEIDENTIFIER = (SELECT TOP 1 [UserId] FROM INSERTED)
UPDATE UPDATE
@ -61,21 +46,6 @@ BEGIN
SET NOCOUNT ON 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) DECLARE @UserId UNIQUEIDENTIFIER = (SELECT TOP 1 [UserId] FROM INSERTED)
UPDATE UPDATE
@ -96,21 +66,6 @@ BEGIN
SET NOCOUNT ON 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) DECLARE @UserId UNIQUEIDENTIFIER = (SELECT TOP 1 [UserId] FROM DELETED)
UPDATE UPDATE

View File

@ -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)
);

View File

@ -1,6 +0,0 @@
CREATE VIEW [dbo].[HistoryView]
AS
SELECT
*
FROM
[dbo].[History]