diff --git a/src/Api/Public/Controllers/GroupsController.cs b/src/Api/Public/Controllers/GroupsController.cs index f8717c543c..c43f345dd5 100644 --- a/src/Api/Public/Controllers/GroupsController.cs +++ b/src/Api/Public/Controllers/GroupsController.cs @@ -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); } + /// + /// Retrieve a groups's member ids + /// + /// + /// 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. + /// + /// The identifier of the group to be retrieved. + [HttpGet("{id}/member-ids")] + [ProducesResponseType(typeof(HashSet), (int)HttpStatusCode.OK)] + [ProducesResponseType((int)HttpStatusCode.NotFound)] + public async Task 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); + } + /// /// List all groups. /// diff --git a/src/Api/Public/Controllers/MembersController.cs b/src/Api/Public/Controllers/MembersController.cs index 54f71dffe3..76c078e545 100644 --- a/src/Api/Public/Controllers/MembersController.cs +++ b/src/Api/Public/Controllers/MembersController.cs @@ -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); } + /// + /// Retrieve a member's group ids + /// + /// + /// 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. + /// + /// The identifier of the member to be retrieved. + [HttpGet("{id}/group-ids")] + [ProducesResponseType(typeof(HashSet), (int)HttpStatusCode.OK)] + [ProducesResponseType((int)HttpStatusCode.NotFound)] + public async Task 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); + } + /// /// List all members. ///