mirror of
https://github.com/bitwarden/server.git
synced 2025-05-23 04:21:05 -05:00
get group member ids and member group ids apis
This commit is contained in:
parent
b6f54324a5
commit
3187afdb0b
@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Threading.Tasks;
|
||||
@ -52,6 +53,28 @@ namespace Bit.Api.Public.Controllers
|
||||
return new JsonResult(response);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Retrieve a groups's member ids
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Retrieves the unique identifiers for all members that are associated with this group. You need only
|
||||
/// supply the unique group identifier that was returned upon group creation.
|
||||
/// </remarks>
|
||||
/// <param name="id">The identifier of the group to be retrieved.</param>
|
||||
[HttpGet("{id}/member-ids")]
|
||||
[ProducesResponseType(typeof(HashSet<Guid>), (int)HttpStatusCode.OK)]
|
||||
[ProducesResponseType((int)HttpStatusCode.NotFound)]
|
||||
public async Task<IActionResult> GetMemberIds(Guid id)
|
||||
{
|
||||
var group = await _groupRepository.GetByIdAsync(id);
|
||||
if(group == null || group.OrganizationId != _currentContext.OrganizationId)
|
||||
{
|
||||
return new NotFoundResult();
|
||||
}
|
||||
var orgUserIds = await _groupRepository.GetManyUserIdsByIdAsync(id);
|
||||
return new JsonResult(orgUserIds);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// List all groups.
|
||||
/// </summary>
|
||||
|
@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Threading.Tasks;
|
||||
@ -16,17 +17,20 @@ namespace Bit.Api.Public.Controllers
|
||||
public class MembersController : Controller
|
||||
{
|
||||
private readonly IOrganizationUserRepository _organizationUserRepository;
|
||||
private readonly IGroupRepository _groupRepository;
|
||||
private readonly IOrganizationService _organizationService;
|
||||
private readonly IUserService _userService;
|
||||
private readonly CurrentContext _currentContext;
|
||||
|
||||
public MembersController(
|
||||
IOrganizationUserRepository organizationUserRepository,
|
||||
IGroupRepository groupRepository,
|
||||
IOrganizationService organizationService,
|
||||
IUserService userService,
|
||||
CurrentContext currentContext)
|
||||
{
|
||||
_organizationUserRepository = organizationUserRepository;
|
||||
_groupRepository = groupRepository;
|
||||
_organizationService = organizationService;
|
||||
_userService = userService;
|
||||
_currentContext = currentContext;
|
||||
@ -56,6 +60,28 @@ namespace Bit.Api.Public.Controllers
|
||||
return new JsonResult(response);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Retrieve a member's group ids
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Retrieves the unique identifiers for all groups that are associated with this member. You need only
|
||||
/// supply the unique member identifier that was returned upon member creation.
|
||||
/// </remarks>
|
||||
/// <param name="id">The identifier of the member to be retrieved.</param>
|
||||
[HttpGet("{id}/group-ids")]
|
||||
[ProducesResponseType(typeof(HashSet<Guid>), (int)HttpStatusCode.OK)]
|
||||
[ProducesResponseType((int)HttpStatusCode.NotFound)]
|
||||
public async Task<IActionResult> GetGroupIds(Guid id)
|
||||
{
|
||||
var orgUser = await _organizationUserRepository.GetByIdAsync(id);
|
||||
if(orgUser == null || orgUser.OrganizationId != _currentContext.OrganizationId)
|
||||
{
|
||||
return new NotFoundResult();
|
||||
}
|
||||
var groupIds = await _groupRepository.GetManyIdsByUserIdAsync(id);
|
||||
return new JsonResult(groupIds);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// List all members.
|
||||
/// </summary>
|
||||
|
Loading…
x
Reference in New Issue
Block a user