diff --git a/src/Core/Repositories/ISsoConfigRepository.cs b/src/Core/Repositories/ISsoConfigRepository.cs index 1fa54154e..7f5c9169e 100644 --- a/src/Core/Repositories/ISsoConfigRepository.cs +++ b/src/Core/Repositories/ISsoConfigRepository.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using System.Threading.Tasks; using Bit.Core.Models.Table; @@ -8,5 +9,6 @@ namespace Bit.Core.Repositories { Task GetByOrganizationIdAsync(Guid organizationId); Task GetByIdentifierAsync(string identifier); + Task> GetManyByRevisionNotBeforeDate(DateTime? notBefore); } } diff --git a/src/Core/Repositories/SqlServer/SsoConfigRepository.cs b/src/Core/Repositories/SqlServer/SsoConfigRepository.cs index 8bd2cb3c6..50084297f 100644 --- a/src/Core/Repositories/SqlServer/SsoConfigRepository.cs +++ b/src/Core/Repositories/SqlServer/SsoConfigRepository.cs @@ -5,6 +5,7 @@ using System.Data.SqlClient; using System.Data; using Dapper; using System.Linq; +using System.Collections.Generic; namespace Bit.Core.Repositories.SqlServer { @@ -43,5 +44,18 @@ namespace Bit.Core.Repositories.SqlServer return results.SingleOrDefault(); } } + + public async Task> GetManyByRevisionNotBeforeDate(DateTime? notBefore) + { + using (var connection = new SqlConnection(ConnectionString)) + { + var results = await connection.QueryAsync( + $"[{Schema}].[{Table}_ReadManyByNotBeforeRevisionDate]", + new { NotBefore = notBefore }, + commandType: CommandType.StoredProcedure); + + return results.ToList(); + } + } } } diff --git a/src/Sql/dbo/Stored Procedures/SsoConfig_ReadManyByNotBeforeRevisionDate.sql b/src/Sql/dbo/Stored Procedures/SsoConfig_ReadManyByNotBeforeRevisionDate.sql new file mode 100644 index 000000000..9e490d1fb --- /dev/null +++ b/src/Sql/dbo/Stored Procedures/SsoConfig_ReadManyByNotBeforeRevisionDate.sql @@ -0,0 +1,14 @@ +CREATE PROCEDURE [dbo].[SsoConfig_ReadManyByNotBeforeRevisionDate] + @NotBefore DATETIME2(7) +AS +BEGIN + SET NOCOUNT ON + + SELECT + * + FROM + [dbo].[SsoConfigView] + WHERE + [Enabled] = 1 + AND [RevisionDate] >= COALESCE(@NotBefore, [RevisionDate]); +END diff --git a/util/Migrator/DbScripts/2020-08-19_00_SsoConfigGetAll.sql b/util/Migrator/DbScripts/2020-08-19_00_SsoConfigGetAll.sql new file mode 100644 index 000000000..ae6c5447e --- /dev/null +++ b/util/Migrator/DbScripts/2020-08-19_00_SsoConfigGetAll.sql @@ -0,0 +1,21 @@ +IF OBJECT_ID('[dbo].[SsoConfig_ReadManyByNotBeforeRevisionDate]') IS NOT NULL +BEGIN + DROP PROCEDURE [dbo].[SsoConfig_ReadManyByNotBeforeRevisionDate] +END +GO + +CREATE PROCEDURE [dbo].[SsoConfig_ReadManyByNotBeforeRevisionDate] + @NotBefore DATETIME2(7) +AS +BEGIN + SET NOCOUNT ON + + SELECT + * + FROM + [dbo].[SsoConfigView] + WHERE + [Enabled] = 1 + AND [RevisionDate] >= COALESCE(@NotBefore, [RevisionDate]); +END +GO