mirror of
https://github.com/bitwarden/server.git
synced 2025-07-12 05:13:58 -05:00
group user assignment apis
This commit is contained in:
@ -43,6 +43,12 @@ namespace Bit.Core.Models.Api
|
||||
}
|
||||
}
|
||||
|
||||
public class OrganizationUserUpdateGroupsRequestModel
|
||||
{
|
||||
[Required]
|
||||
public IEnumerable<string> GroupIds { get; set; }
|
||||
}
|
||||
|
||||
public class OrganizationUserCollectionRequestModel
|
||||
{
|
||||
[Required]
|
||||
|
34
src/Core/Models/Api/Response/GroupUserResponseModel.cs
Normal file
34
src/Core/Models/Api/Response/GroupUserResponseModel.cs
Normal file
@ -0,0 +1,34 @@
|
||||
using System;
|
||||
using Bit.Core.Models.Data;
|
||||
using Bit.Core.Enums;
|
||||
|
||||
namespace Bit.Core.Models.Api
|
||||
{
|
||||
public class GroupUserResponseModel : ResponseModel
|
||||
{
|
||||
public GroupUserResponseModel(GroupUserUserDetails groupUser)
|
||||
: base("groupUser")
|
||||
{
|
||||
if(groupUser == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(groupUser));
|
||||
}
|
||||
|
||||
OrganizationUserId = groupUser.OrganizationUserId.ToString();
|
||||
GroupId = groupUser.GroupId.ToString();
|
||||
AccessAll = groupUser.AccessAll;
|
||||
Name = groupUser.Name;
|
||||
Email = groupUser.Email;
|
||||
Type = groupUser.Type;
|
||||
Status = groupUser.Status;
|
||||
}
|
||||
|
||||
public string OrganizationUserId { get; set; }
|
||||
public string GroupId { 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; }
|
||||
}
|
||||
}
|
16
src/Core/Models/Data/GroupUserUserDetails.cs
Normal file
16
src/Core/Models/Data/GroupUserUserDetails.cs
Normal file
@ -0,0 +1,16 @@
|
||||
using System;
|
||||
|
||||
namespace Bit.Core.Models.Data
|
||||
{
|
||||
public class GroupUserUserDetails
|
||||
{
|
||||
public Guid OrganizationUserId { get; set; }
|
||||
public Guid OrganizationId { get; set; }
|
||||
public Guid GroupId { 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; }
|
||||
}
|
||||
}
|
@ -2,6 +2,7 @@
|
||||
using Bit.Core.Models.Table;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using Bit.Core.Models.Data;
|
||||
|
||||
namespace Bit.Core.Repositories
|
||||
{
|
||||
@ -9,6 +10,8 @@ namespace Bit.Core.Repositories
|
||||
{
|
||||
Task<Tuple<Group, ICollection<Guid>>> GetByIdWithCollectionsAsync(Guid id);
|
||||
Task<ICollection<Group>> GetManyByOrganizationIdAsync(Guid organizationId);
|
||||
Task<ICollection<GroupUserUserDetails>> GetManyUserDetailsByIdAsync(Guid id);
|
||||
Task<ICollection<Guid>> GetManyIdsByUserIdAsync(Guid organizationUserId);
|
||||
Task CreateAsync(Group obj, IEnumerable<Guid> collectionIds);
|
||||
Task ReplaceAsync(Group obj, IEnumerable<Guid> collectionIds);
|
||||
}
|
||||
|
@ -20,5 +20,6 @@ namespace Bit.Core.Repositories
|
||||
Task<ICollection<OrganizationUserUserDetails>> GetManyDetailsByOrganizationAsync(Guid organizationId);
|
||||
Task<ICollection<OrganizationUserOrganizationDetails>> GetManyDetailsByUserAsync(Guid userId,
|
||||
OrganizationUserStatusType? status = null);
|
||||
Task UpdateGroupsAsync(Guid orgUserId, IEnumerable<Guid> groupIds);
|
||||
}
|
||||
}
|
||||
|
@ -8,6 +8,7 @@ using System.Data.SqlClient;
|
||||
using System.Linq;
|
||||
using Newtonsoft.Json;
|
||||
using Bit.Core.Utilities;
|
||||
using Bit.Core.Models.Data;
|
||||
|
||||
namespace Bit.Core.Repositories.SqlServer
|
||||
{
|
||||
@ -50,6 +51,32 @@ namespace Bit.Core.Repositories.SqlServer
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<ICollection<GroupUserUserDetails>> GetManyUserDetailsByIdAsync(Guid id)
|
||||
{
|
||||
using(var connection = new SqlConnection(ConnectionString))
|
||||
{
|
||||
var results = await connection.QueryAsync<GroupUserUserDetails>(
|
||||
$"[{Schema}].[GroupUserUserDetails_ReadByGroupId]",
|
||||
new { GroupId = id },
|
||||
commandType: CommandType.StoredProcedure);
|
||||
|
||||
return results.ToList();
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<ICollection<Guid>> GetManyIdsByUserIdAsync(Guid organizationUserId)
|
||||
{
|
||||
using(var connection = new SqlConnection(ConnectionString))
|
||||
{
|
||||
var results = await connection.QueryAsync<Guid>(
|
||||
$"[{Schema}].[GroupUser_ReadGroupIdsByOrganizationUserId]",
|
||||
new { OrganizationUserId = organizationUserId },
|
||||
commandType: CommandType.StoredProcedure);
|
||||
|
||||
return results.ToList();
|
||||
}
|
||||
}
|
||||
|
||||
public async Task CreateAsync(Group obj, IEnumerable<Guid> collectionIds)
|
||||
{
|
||||
obj.SetNewId();
|
||||
|
@ -8,6 +8,7 @@ using System.Linq;
|
||||
using Bit.Core.Models.Data;
|
||||
using System.Collections.Generic;
|
||||
using Bit.Core.Enums;
|
||||
using Bit.Core.Utilities;
|
||||
|
||||
namespace Bit.Core.Repositories.SqlServer
|
||||
{
|
||||
@ -155,5 +156,16 @@ namespace Bit.Core.Repositories.SqlServer
|
||||
return results.ToList();
|
||||
}
|
||||
}
|
||||
|
||||
public async Task UpdateGroupsAsync(Guid orgUserId, IEnumerable<Guid> groupIds)
|
||||
{
|
||||
using(var connection = new SqlConnection(ConnectionString))
|
||||
{
|
||||
var results = await connection.ExecuteAsync(
|
||||
"[dbo].[GroupUser_UpdateGroups]",
|
||||
new { OrganizationUserId = orgUserId, GroupIds = groupIds.ToGuidIdArrayTVP() },
|
||||
commandType: CommandType.StoredProcedure);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user