1
0
mirror of https://github.com/bitwarden/server synced 2026-01-03 00:53:37 +00:00

api adjustments for manager role and collections

This commit is contained in:
Kyle Spearrin
2018-10-17 14:58:45 -04:00
parent ca175e7dd8
commit 7db36e0005
19 changed files with 426 additions and 82 deletions

View File

@@ -51,6 +51,23 @@ namespace Bit.Core.Repositories.SqlServer
}
}
public async Task<Tuple<CollectionDetails, ICollection<SelectionReadOnly>>> GetByIdWithGroupsAsync(
Guid id, Guid userId)
{
using(var connection = new SqlConnection(ConnectionString))
{
var results = await connection.QueryMultipleAsync(
$"[{Schema}].[Collection_ReadWithGroupsByIdUserId]",
new { Id = id, UserId = userId },
commandType: CommandType.StoredProcedure);
var collection = await results.ReadFirstOrDefaultAsync<CollectionDetails>();
var groups = (await results.ReadAsync<SelectionReadOnly>()).ToList();
return new Tuple<CollectionDetails, ICollection<SelectionReadOnly>>(collection, groups);
}
}
public async Task<ICollection<Collection>> GetManyByOrganizationIdAsync(Guid organizationId)
{
using(var connection = new SqlConnection(ConnectionString))
@@ -64,6 +81,19 @@ namespace Bit.Core.Repositories.SqlServer
}
}
public async Task<CollectionDetails> GetByIdAsync(Guid id, Guid userId)
{
using(var connection = new SqlConnection(ConnectionString))
{
var results = await connection.QueryAsync<CollectionDetails>(
$"[{Schema}].[Collection_ReadByIdUserId]",
new { Id = id, UserId = userId },
commandType: CommandType.StoredProcedure);
return results.FirstOrDefault();
}
}
public async Task<ICollection<CollectionDetails>> GetManyByUserIdAsync(Guid userId)
{
using(var connection = new SqlConnection(ConnectionString))
@@ -108,7 +138,7 @@ namespace Bit.Core.Repositories.SqlServer
using(var connection = new SqlConnection(ConnectionString))
{
var results = await connection.ExecuteAsync(
$"[{Schema}].[Collection_CreateWithGroups]",
$"[{Schema}].[Collection_CreateWithGroupsAndUsers]",
objWithGroups,
commandType: CommandType.StoredProcedure);
}
@@ -128,6 +158,17 @@ namespace Bit.Core.Repositories.SqlServer
}
}
public async Task CreateUserAsync(Guid collectionId, Guid organizationUserId)
{
using(var connection = new SqlConnection(ConnectionString))
{
var results = await connection.ExecuteAsync(
$"[{Schema}].[CollectionUser_Create]",
new { CollectionId = collectionId, OrganizationUserId = organizationUserId },
commandType: CommandType.StoredProcedure);
}
}
public async Task DeleteUserAsync(Guid collectionId, Guid organizationUserId)
{
using(var connection = new SqlConnection(ConnectionString))
@@ -139,6 +180,17 @@ namespace Bit.Core.Repositories.SqlServer
}
}
public async Task UpdateUsersAsync(Guid id, IEnumerable<SelectionReadOnly> users)
{
using(var connection = new SqlConnection(ConnectionString))
{
var results = await connection.ExecuteAsync(
$"[{Schema}].[Collection_UpdateUsers]",
new { Id = id, Users = users.ToArrayTVP() },
commandType: CommandType.StoredProcedure);
}
}
public class CollectionWithGroups : Collection
{
public DataTable Groups { get; set; }