mirror of
https://github.com/bitwarden/server
synced 2025-12-26 21:23:39 +00:00
Group access & sproc/model refactoring.
This commit is contained in:
@@ -68,11 +68,15 @@ namespace Bit.Core.Repositories.SqlServer
|
||||
using(var connection = new SqlConnection(ConnectionString))
|
||||
{
|
||||
var results = await connection.QueryAsync<Collection>(
|
||||
$"[{Schema}].[{Table}_ReadByUserId]",
|
||||
$"[{Schema}].[Collection_ReadByUserId]",
|
||||
new { UserId = userId },
|
||||
commandType: CommandType.StoredProcedure);
|
||||
|
||||
return results.ToList();
|
||||
// Return distinct Id results.
|
||||
return results
|
||||
.GroupBy(c => c.Id)
|
||||
.Select(c => c.First())
|
||||
.ToList();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -33,19 +33,6 @@ namespace Bit.Core.Repositories.SqlServer
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<ICollection<CollectionUserCollectionDetails>> GetManyDetailsByUserIdAsync(Guid userId)
|
||||
{
|
||||
using(var connection = new SqlConnection(ConnectionString))
|
||||
{
|
||||
var results = await connection.QueryAsync<CollectionUserCollectionDetails>(
|
||||
$"[{Schema}].[CollectionUserCollectionDetails_ReadByUserId]",
|
||||
new { UserId = userId },
|
||||
commandType: CommandType.StoredProcedure);
|
||||
|
||||
return results.ToList();
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<ICollection<CollectionUserUserDetails>> GetManyDetailsByCollectionIdAsync(Guid organizationId,
|
||||
Guid collectionId)
|
||||
{
|
||||
@@ -56,7 +43,11 @@ namespace Bit.Core.Repositories.SqlServer
|
||||
new { OrganizationId = organizationId, CollectionId = collectionId },
|
||||
commandType: CommandType.StoredProcedure);
|
||||
|
||||
return results.ToList();
|
||||
// Return distinct Id results. If at least one of the grouped results is not ReadOnly, that we return it.
|
||||
return results
|
||||
.GroupBy(c => c.Id)
|
||||
.Select(g => g.OrderBy(og => og.ReadOnly).First())
|
||||
.ToList();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -114,19 +114,18 @@ namespace Bit.Core.Repositories.SqlServer
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<Tuple<OrganizationUserUserDetails, ICollection<CollectionUserCollectionDetails>>>
|
||||
GetDetailsByIdAsync(Guid id)
|
||||
public async Task<Tuple<OrganizationUser, ICollection<SelectionReadOnly>>> GetByIdWithCollectionsAsync(Guid id)
|
||||
{
|
||||
using(var connection = new SqlConnection(ConnectionString))
|
||||
{
|
||||
var results = await connection.QueryMultipleAsync(
|
||||
"[dbo].[OrganizationUserUserDetails_ReadById]",
|
||||
"[dbo].[OrganizationUser_ReadWithCollectionsById]",
|
||||
new { Id = id },
|
||||
commandType: CommandType.StoredProcedure);
|
||||
|
||||
var user = (await results.ReadAsync<OrganizationUserUserDetails>()).SingleOrDefault();
|
||||
var collections = (await results.ReadAsync<CollectionUserCollectionDetails>()).ToList();
|
||||
return new Tuple<OrganizationUserUserDetails, ICollection<CollectionUserCollectionDetails>>(user, collections);
|
||||
var user = (await results.ReadAsync<OrganizationUser>()).SingleOrDefault();
|
||||
var collections = (await results.ReadAsync<SelectionReadOnly>()).ToList();
|
||||
return new Tuple<OrganizationUser, ICollection<SelectionReadOnly>>(user, collections);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user