From 09048cf98ff1115491878da7b70fa1ab4a13b88c Mon Sep 17 00:00:00 2001 From: Kyle Spearrin Date: Wed, 12 Apr 2017 14:42:19 -0400 Subject: [PATCH] dep. history and favorites apis. backwards compat --- src/Api/Controllers/CiphersController.cs | 43 +++++++++--------- .../Response/CipherHistoryResponseModel.cs | 24 +++------- src/Core/Repositories/ICipherRepository.cs | 2 - .../SqlServer/CipherRepository.cs | 21 --------- src/Sql/Sql.sqlproj | 4 -- ...eadByRevisionDateUserWithDeleteHistory.sql | 24 ---------- .../Stored Procedures/History_ReadById.sql | 13 ------ src/Sql/dbo/Tables/Cipher.sql | 45 ------------------- src/Sql/dbo/Tables/History.sql | 9 ---- src/Sql/dbo/Views/HistoryView.sql | 6 --- 10 files changed, 25 insertions(+), 166 deletions(-) delete mode 100644 src/Sql/dbo/Stored Procedures/CipherDetails_ReadByRevisionDateUserWithDeleteHistory.sql delete mode 100644 src/Sql/dbo/Stored Procedures/History_ReadById.sql delete mode 100644 src/Sql/dbo/Tables/History.sql delete mode 100644 src/Sql/dbo/Views/HistoryView.sql diff --git a/src/Api/Controllers/CiphersController.cs b/src/Api/Controllers/CiphersController.cs index 99037c840c..33efeb5fa5 100644 --- a/src/Api/Controllers/CiphersController.cs +++ b/src/Api/Controllers/CiphersController.cs @@ -85,15 +85,12 @@ namespace Bit.Api.Controllers return new ListResponseModel(responses); } - //[Obsolete] - //[HttpGet("history")] - //public async Task 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 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(); - // } - - // cipher.Favorite = !cipher.Favorite; - - // await _cipherService.SaveAsync(cipher); - //} + [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(); + } + + await _cipherService.UpdatePartialAsync(new Guid(id), userId, cipher.FolderId, !cipher.Favorite); + } [HttpPut("{id}/partial")] [HttpPost("{id}/partial")] diff --git a/src/Core/Models/Api/Response/CipherHistoryResponseModel.cs b/src/Core/Models/Api/Response/CipherHistoryResponseModel.cs index 63b48e9735..9b55dbedd3 100644 --- a/src/Core/Models/Api/Response/CipherHistoryResponseModel.cs +++ b/src/Core/Models/Api/Response/CipherHistoryResponseModel.cs @@ -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 revisedCiphers, IEnumerable 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 Revised { get; set; } - public IEnumerable Deleted { get; set; } + public IEnumerable Revised { get; set; } = new List(); + public IEnumerable Deleted { get; set; } = new List(); } } diff --git a/src/Core/Repositories/ICipherRepository.cs b/src/Core/Repositories/ICipherRepository.cs index 041de63ad2..ac57fbd372 100644 --- a/src/Core/Repositories/ICipherRepository.cs +++ b/src/Core/Repositories/ICipherRepository.cs @@ -13,8 +13,6 @@ namespace Bit.Core.Repositories Task> GetManyByUserIdAsync(Guid userId); Task> GetManyByUserIdHasSubvaultsAsync(Guid userId); Task> GetManyByTypeAndUserIdAsync(Enums.CipherType type, Guid userId); - Task, ICollection>> GetManySinceRevisionDateAndUserIdWithDeleteHistoryAsync( - DateTime sinceRevisionDate, Guid userId); Task CreateAsync(CipherDetails cipher); Task ReplaceAsync(CipherDetails cipher); Task UpsertAsync(CipherDetails cipher); diff --git a/src/Core/Repositories/SqlServer/CipherRepository.cs b/src/Core/Repositories/SqlServer/CipherRepository.cs index 636852fda7..add9ff4310 100644 --- a/src/Core/Repositories/SqlServer/CipherRepository.cs +++ b/src/Core/Repositories/SqlServer/CipherRepository.cs @@ -92,27 +92,6 @@ namespace Bit.Core.Repositories.SqlServer } } - public async Task, ICollection>> - 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(); - var deletes = await results.ReadAsync(); - - return new Tuple, ICollection>(ciphers.ToList(), deletes.ToList()); - } - } - public async Task CreateAsync(CipherDetails cipher) { cipher.SetNewId(); diff --git a/src/Sql/Sql.sqlproj b/src/Sql/Sql.sqlproj index fb2afa9724..436d0ac70d 100644 --- a/src/Sql/Sql.sqlproj +++ b/src/Sql/Sql.sqlproj @@ -68,7 +68,6 @@ - @@ -85,7 +84,6 @@ - @@ -123,7 +121,6 @@ - @@ -131,7 +128,6 @@ - diff --git a/src/Sql/dbo/Stored Procedures/CipherDetails_ReadByRevisionDateUserWithDeleteHistory.sql b/src/Sql/dbo/Stored Procedures/CipherDetails_ReadByRevisionDateUserWithDeleteHistory.sql deleted file mode 100644 index 724cdeb4a1..0000000000 --- a/src/Sql/dbo/Stored Procedures/CipherDetails_ReadByRevisionDateUserWithDeleteHistory.sql +++ /dev/null @@ -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 \ No newline at end of file diff --git a/src/Sql/dbo/Stored Procedures/History_ReadById.sql b/src/Sql/dbo/Stored Procedures/History_ReadById.sql deleted file mode 100644 index 900c3e1083..0000000000 --- a/src/Sql/dbo/Stored Procedures/History_ReadById.sql +++ /dev/null @@ -1,13 +0,0 @@ -CREATE PROCEDURE [dbo].[History_ReadById] - @Id BIGINT -AS -BEGIN - SET NOCOUNT ON - - SELECT - * - FROM - [dbo].[HistoryView] - WHERE - [Id] = @Id -END \ No newline at end of file diff --git a/src/Sql/dbo/Tables/Cipher.sql b/src/Sql/dbo/Tables/Cipher.sql index f29e03999f..20fc97596b 100644 --- a/src/Sql/dbo/Tables/Cipher.sql +++ b/src/Sql/dbo/Tables/Cipher.sql @@ -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 diff --git a/src/Sql/dbo/Tables/History.sql b/src/Sql/dbo/Tables/History.sql deleted file mode 100644 index ec68d90ca0..0000000000 --- a/src/Sql/dbo/Tables/History.sql +++ /dev/null @@ -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) -); - diff --git a/src/Sql/dbo/Views/HistoryView.sql b/src/Sql/dbo/Views/HistoryView.sql deleted file mode 100644 index 0fc043c0b1..0000000000 --- a/src/Sql/dbo/Views/HistoryView.sql +++ /dev/null @@ -1,6 +0,0 @@ -CREATE VIEW [dbo].[HistoryView] -AS -SELECT - * -FROM - [dbo].[History] \ No newline at end of file