1
0
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:
Thomas Rittson
2025-12-31 13:28:45 +10:00
parent e67727bf25
commit ae9d18ac9b
5 changed files with 62 additions and 0 deletions

View File

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

View File

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

View File

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

View File

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

View File

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