mirror of
https://github.com/bitwarden/server.git
synced 2025-07-19 00:21:35 -05:00
apis for managing collection users
This commit is contained in:
@ -1,34 +0,0 @@
|
||||
using System;
|
||||
using Bit.Core.Models.Data;
|
||||
using Bit.Core.Enums;
|
||||
|
||||
namespace Bit.Core.Models.Api
|
||||
{
|
||||
public class CollectionUserResponseModel : ResponseModel
|
||||
{
|
||||
public CollectionUserResponseModel(CollectionUserDetails collectionUser)
|
||||
: base("collectionUser")
|
||||
{
|
||||
if(collectionUser == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(collectionUser));
|
||||
}
|
||||
|
||||
OrganizationUserId = collectionUser.OrganizationUserId.ToString();
|
||||
AccessAll = collectionUser.AccessAll;
|
||||
Name = collectionUser.Name;
|
||||
Email = collectionUser.Email;
|
||||
Type = collectionUser.Type;
|
||||
Status = collectionUser.Status;
|
||||
ReadOnly = collectionUser.ReadOnly;
|
||||
}
|
||||
|
||||
public string OrganizationUserId { get; set; }
|
||||
public bool AccessAll { get; set; }
|
||||
public string Name { get; set; }
|
||||
public string Email { get; set; }
|
||||
public OrganizationUserType Type { get; set; }
|
||||
public OrganizationUserStatusType Status { get; set; }
|
||||
public bool ReadOnly { get; set; }
|
||||
}
|
||||
}
|
@ -3,9 +3,10 @@ using Bit.Core.Models.Data;
|
||||
|
||||
namespace Bit.Core.Models.Api
|
||||
{
|
||||
public class SelectionReadOnlyResponseModel
|
||||
public class SelectionReadOnlyResponseModel : ResponseModel
|
||||
{
|
||||
public SelectionReadOnlyResponseModel(SelectionReadOnly selection)
|
||||
: base("selection")
|
||||
{
|
||||
if(selection == null)
|
||||
{
|
||||
|
@ -1,15 +0,0 @@
|
||||
using System;
|
||||
|
||||
namespace Bit.Core.Models.Data
|
||||
{
|
||||
public class CollectionUserDetails
|
||||
{
|
||||
public Guid OrganizationUserId { get; set; }
|
||||
public bool AccessAll { get; set; }
|
||||
public string Name { get; set; }
|
||||
public string Email { get; set; }
|
||||
public Enums.OrganizationUserStatusType Status { get; set; }
|
||||
public Enums.OrganizationUserType Type { get; set; }
|
||||
public bool ReadOnly { get; set; }
|
||||
}
|
||||
}
|
@ -14,10 +14,10 @@ namespace Bit.Core.Repositories
|
||||
Task<ICollection<Collection>> GetManyByOrganizationIdAsync(Guid organizationId);
|
||||
Task<CollectionDetails> GetByIdAsync(Guid id, Guid userId);
|
||||
Task<ICollection<CollectionDetails>> GetManyByUserIdAsync(Guid userId);
|
||||
Task<ICollection<CollectionUserDetails>> GetManyUserDetailsByIdAsync(Guid organizationId, Guid collectionId);
|
||||
Task CreateAsync(Collection obj, IEnumerable<SelectionReadOnly> groups);
|
||||
Task ReplaceAsync(Collection obj, IEnumerable<SelectionReadOnly> groups);
|
||||
Task DeleteUserAsync(Guid collectionId, Guid organizationUserId);
|
||||
Task UpdateUsersAsync(Guid id, IEnumerable<SelectionReadOnly> users);
|
||||
Task<ICollection<SelectionReadOnly>> GetManyUsersByIdAsync(Guid id);
|
||||
}
|
||||
}
|
||||
|
@ -111,24 +111,6 @@ namespace Bit.Core.Repositories.SqlServer
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<ICollection<CollectionUserDetails>> GetManyUserDetailsByIdAsync(Guid organizationId,
|
||||
Guid collectionId)
|
||||
{
|
||||
using(var connection = new SqlConnection(ConnectionString))
|
||||
{
|
||||
var results = await connection.QueryAsync<CollectionUserDetails>(
|
||||
$"[{Schema}].[CollectionUserDetails_ReadByCollectionId]",
|
||||
new { OrganizationId = organizationId, CollectionId = collectionId },
|
||||
commandType: CommandType.StoredProcedure);
|
||||
|
||||
// Return distinct Id results. If at least one of the grouped results is not ReadOnly, that we return it.
|
||||
return results
|
||||
.GroupBy(c => c.OrganizationUserId)
|
||||
.Select(g => g.OrderBy(og => og.ReadOnly).First())
|
||||
.ToList();
|
||||
}
|
||||
}
|
||||
|
||||
public async Task CreateAsync(Collection obj, IEnumerable<SelectionReadOnly> groups)
|
||||
{
|
||||
obj.SetNewId();
|
||||
@ -185,12 +167,25 @@ namespace Bit.Core.Repositories.SqlServer
|
||||
using(var connection = new SqlConnection(ConnectionString))
|
||||
{
|
||||
var results = await connection.ExecuteAsync(
|
||||
$"[{Schema}].[Collection_UpdateUsers]",
|
||||
$"[{Schema}].[CollectionUser_UpdateUsers]",
|
||||
new { Id = id, Users = users.ToArrayTVP() },
|
||||
commandType: CommandType.StoredProcedure);
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<ICollection<SelectionReadOnly>> GetManyUsersByIdAsync(Guid id)
|
||||
{
|
||||
using(var connection = new SqlConnection(ConnectionString))
|
||||
{
|
||||
var results = await connection.QueryAsync<SelectionReadOnly>(
|
||||
$"[{Schema}].[CollectionUser_ReadByCollectionId]",
|
||||
new { CollectionId = id },
|
||||
commandType: CommandType.StoredProcedure);
|
||||
|
||||
return results.ToList();
|
||||
}
|
||||
}
|
||||
|
||||
public class CollectionWithGroups : Collection
|
||||
{
|
||||
public DataTable Groups { get; set; }
|
||||
|
Reference in New Issue
Block a user