mirror of
https://github.com/bitwarden/server
synced 2026-02-10 21:50:21 +00:00
Add read sproc for semaphores
This commit is contained in:
@@ -82,4 +82,11 @@ public interface ICollectionRepository : IRepository<Collection, Guid>
|
||||
/// <param name="defaultCollectionName">The encrypted string to use as the default collection name.</param>
|
||||
/// <returns></returns>
|
||||
Task UpsertDefaultCollectionsBulkAsync(Guid organizationId, IEnumerable<Guid> organizationUserIds, string defaultCollectionName);
|
||||
|
||||
/// <summary>
|
||||
/// Gets organization user IDs that have default collection semaphore entries for the specified organization.
|
||||
/// </summary>
|
||||
/// <param name="organizationId">The Organization ID.</param>
|
||||
/// <returns>Collection of organization user IDs that have default collection semaphores.</returns>
|
||||
Task<IEnumerable<Guid>> GetDefaultCollectionSemaphoresAsync(Guid organizationId);
|
||||
}
|
||||
|
||||
@@ -430,6 +430,19 @@ public class CollectionRepository : Repository<Collection, Guid>, ICollectionRep
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<Guid>> GetDefaultCollectionSemaphoresAsync(Guid organizationId)
|
||||
{
|
||||
using (var connection = new SqlConnection(ConnectionString))
|
||||
{
|
||||
var results = await connection.QueryAsync<Guid>(
|
||||
"[dbo].[DefaultCollectionSemaphore_ReadByOrganizationId]",
|
||||
new { OrganizationId = organizationId },
|
||||
commandType: CommandType.StoredProcedure);
|
||||
|
||||
return results.ToList();
|
||||
}
|
||||
}
|
||||
|
||||
private async Task<HashSet<Guid>> GetOrgUserIdsWithDefaultCollectionAsync(SqlConnection connection, SqlTransaction transaction, Guid organizationId)
|
||||
{
|
||||
const string sql = @"
|
||||
|
||||
@@ -839,6 +839,19 @@ public class CollectionRepository : Repository<Core.Entities.Collection, Collect
|
||||
await UpsertDefaultCollectionsAsync(organizationId, organizationUserIds, defaultCollectionName);
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<Guid>> GetDefaultCollectionSemaphoresAsync(Guid organizationId)
|
||||
{
|
||||
using var scope = ServiceScopeFactory.CreateScope();
|
||||
var dbContext = GetDatabaseContext(scope);
|
||||
|
||||
var organizationUserIds = await dbContext.DefaultCollectionSemaphores
|
||||
.Where(s => s.OrganizationId == organizationId)
|
||||
.Select(s => s.OrganizationUserId)
|
||||
.ToListAsync();
|
||||
|
||||
return organizationUserIds;
|
||||
}
|
||||
|
||||
private async Task<HashSet<Guid>> GetOrgUserIdsWithDefaultCollectionAsync(DatabaseContext dbContext, Guid organizationId)
|
||||
{
|
||||
var results = await dbContext.DefaultCollectionSemaphores
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
CREATE PROCEDURE [dbo].[DefaultCollectionSemaphore_ReadByOrganizationId]
|
||||
@OrganizationId UNIQUEIDENTIFIER
|
||||
AS
|
||||
BEGIN
|
||||
SET NOCOUNT ON
|
||||
|
||||
SELECT
|
||||
[OrganizationUserId]
|
||||
FROM
|
||||
[dbo].[DefaultCollectionSemaphore]
|
||||
WHERE
|
||||
[OrganizationId] = @OrganizationId
|
||||
END
|
||||
@@ -21,3 +21,19 @@ BEGIN
|
||||
);
|
||||
END
|
||||
GO
|
||||
|
||||
-- Create stored procedure to read semaphores by organization
|
||||
CREATE OR ALTER PROCEDURE [dbo].[DefaultCollectionSemaphore_ReadByOrganizationId]
|
||||
@OrganizationId UNIQUEIDENTIFIER
|
||||
AS
|
||||
BEGIN
|
||||
SET NOCOUNT ON
|
||||
|
||||
SELECT
|
||||
[OrganizationUserId]
|
||||
FROM
|
||||
[dbo].[DefaultCollectionSemaphore]
|
||||
WHERE
|
||||
[OrganizationId] = @OrganizationId
|
||||
END
|
||||
GO
|
||||
|
||||
Reference in New Issue
Block a user