1
0
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:
Kyle Spearrin 2019-03-12 11:35:03 -04:00
parent b6f54324a5
commit 3187afdb0b
2 changed files with 49 additions and 0 deletions

View File

@ -1,4 +1,5 @@
using System; using System;
using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Net; using System.Net;
using System.Threading.Tasks; using System.Threading.Tasks;
@ -52,6 +53,28 @@ namespace Bit.Api.Public.Controllers
return new JsonResult(response); 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> /// <summary>
/// List all groups. /// List all groups.
/// </summary> /// </summary>

View File

@ -1,4 +1,5 @@
using System; using System;
using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Net; using System.Net;
using System.Threading.Tasks; using System.Threading.Tasks;
@ -16,17 +17,20 @@ namespace Bit.Api.Public.Controllers
public class MembersController : Controller public class MembersController : Controller
{ {
private readonly IOrganizationUserRepository _organizationUserRepository; private readonly IOrganizationUserRepository _organizationUserRepository;
private readonly IGroupRepository _groupRepository;
private readonly IOrganizationService _organizationService; private readonly IOrganizationService _organizationService;
private readonly IUserService _userService; private readonly IUserService _userService;
private readonly CurrentContext _currentContext; private readonly CurrentContext _currentContext;
public MembersController( public MembersController(
IOrganizationUserRepository organizationUserRepository, IOrganizationUserRepository organizationUserRepository,
IGroupRepository groupRepository,
IOrganizationService organizationService, IOrganizationService organizationService,
IUserService userService, IUserService userService,
CurrentContext currentContext) CurrentContext currentContext)
{ {
_organizationUserRepository = organizationUserRepository; _organizationUserRepository = organizationUserRepository;
_groupRepository = groupRepository;
_organizationService = organizationService; _organizationService = organizationService;
_userService = userService; _userService = userService;
_currentContext = currentContext; _currentContext = currentContext;
@ -56,6 +60,28 @@ namespace Bit.Api.Public.Controllers
return new JsonResult(response); 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> /// <summary>
/// List all members. /// List all members.
/// </summary> /// </summary>