mirror of
https://github.com/bitwarden/server.git
synced 2025-02-25 03:21:46 +01:00
return collection associations with group response
This commit is contained in:
parent
41ab456bbd
commit
df09b02ecc
@ -42,12 +42,13 @@ namespace Bit.Api.Public.Controllers
|
||||
[ProducesResponseType((int)HttpStatusCode.NotFound)]
|
||||
public async Task<IActionResult> Get(Guid id)
|
||||
{
|
||||
var group = await _groupRepository.GetByIdAsync(id);
|
||||
var groupDetails = await _groupRepository.GetByIdWithCollectionsAsync(id);
|
||||
var group = groupDetails?.Item1;
|
||||
if(group == null || group.OrganizationId != _currentContext.OrganizationId)
|
||||
{
|
||||
return new NotFoundResult();
|
||||
}
|
||||
var response = new GroupResponseModel(group);
|
||||
var response = new GroupResponseModel(group, groupDetails.Item2);
|
||||
return new JsonResult(response);
|
||||
}
|
||||
|
||||
@ -56,13 +57,15 @@ namespace Bit.Api.Public.Controllers
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Returns a list of your organization's groups.
|
||||
/// Group objects listed in this call do not include information about their associated collections.
|
||||
/// </remarks>
|
||||
[HttpGet]
|
||||
[ProducesResponseType(typeof(ListResponseModel<GroupResponseModel>), (int)HttpStatusCode.OK)]
|
||||
public async Task<IActionResult> List()
|
||||
{
|
||||
var groups = await _groupRepository.GetManyByOrganizationIdAsync(_currentContext.OrganizationId.Value);
|
||||
var groupResponses = groups.Select(g => new GroupResponseModel(g));
|
||||
// TODO: Get all CollectionGroup associations for the organization and marry them up here for the response.
|
||||
var groupResponses = groups.Select(g => new GroupResponseModel(g, null));
|
||||
var response = new ListResponseModel<GroupResponseModel>(groupResponses);
|
||||
return new JsonResult(response);
|
||||
}
|
||||
@ -82,7 +85,7 @@ namespace Bit.Api.Public.Controllers
|
||||
var group = model.ToGroup(_currentContext.OrganizationId.Value);
|
||||
var associations = model.Collections?.Select(c => c.ToSelectionReadOnly());
|
||||
await _groupService.SaveAsync(group, associations);
|
||||
var response = new GroupResponseModel(group);
|
||||
var response = new GroupResponseModel(group, associations);
|
||||
return new JsonResult(response);
|
||||
}
|
||||
|
||||
@ -109,7 +112,7 @@ namespace Bit.Api.Public.Controllers
|
||||
var updatedGroup = model.ToGroup(existingGroup);
|
||||
var associations = model.Collections?.Select(c => c.ToSelectionReadOnly());
|
||||
await _groupService.SaveAsync(updatedGroup, associations);
|
||||
var response = new GroupResponseModel(updatedGroup);
|
||||
var response = new GroupResponseModel(updatedGroup, associations);
|
||||
return new JsonResult(response);
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,21 @@
|
||||
using System;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace Bit.Core.Models.Api.Public
|
||||
{
|
||||
public abstract class BaseAssociationWithPermissionsModel
|
||||
{
|
||||
/// <summary>
|
||||
/// The associated object's unique identifier.
|
||||
/// </summary>
|
||||
/// <example>bfbc8338-e329-4dc0-b0c9-317c2ebf1a09</example>
|
||||
[Required]
|
||||
public Guid? Id { get; set; }
|
||||
/// <summary>
|
||||
/// When true, the read only permission will not allow the user or group to make changes to items.
|
||||
/// </summary>
|
||||
[Required]
|
||||
public bool? ReadOnly { get; set; }
|
||||
}
|
||||
}
|
@ -1,24 +1,9 @@
|
||||
using System;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using Newtonsoft.Json;
|
||||
using Bit.Core.Models.Data;
|
||||
using Bit.Core.Models.Data;
|
||||
|
||||
namespace Bit.Core.Models.Api.Public
|
||||
{
|
||||
public class AssociationWithPermissionsRequestModel
|
||||
public class AssociationWithPermissionsRequestModel : BaseAssociationWithPermissionsModel
|
||||
{
|
||||
/// <summary>
|
||||
/// The associated object's unique identifier.
|
||||
/// </summary>
|
||||
/// <example>bfbc8338-e329-4dc0-b0c9-317c2ebf1a09</example>
|
||||
[Required]
|
||||
public Guid? Id { get; set; }
|
||||
/// <summary>
|
||||
/// When true, the read only permission will not allow the user or group to make changes to items.
|
||||
/// </summary>
|
||||
[Required]
|
||||
public bool? ReadOnly { get; set; }
|
||||
|
||||
public SelectionReadOnly ToSelectionReadOnly()
|
||||
{
|
||||
return new SelectionReadOnly
|
||||
|
@ -0,0 +1,18 @@
|
||||
using System;
|
||||
using Bit.Core.Models.Data;
|
||||
|
||||
namespace Bit.Core.Models.Api.Public
|
||||
{
|
||||
public class AssociationWithPermissionsResponseModel : BaseAssociationWithPermissionsModel
|
||||
{
|
||||
public AssociationWithPermissionsResponseModel(SelectionReadOnly selection)
|
||||
{
|
||||
if(selection == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(selection));
|
||||
}
|
||||
Id = selection.Id;
|
||||
ReadOnly = selection.ReadOnly;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,5 +1,8 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Linq;
|
||||
using Bit.Core.Models.Data;
|
||||
using Bit.Core.Models.Table;
|
||||
|
||||
namespace Bit.Core.Models.Api.Public
|
||||
@ -9,7 +12,7 @@ namespace Bit.Core.Models.Api.Public
|
||||
/// </summary>
|
||||
public class GroupResponseModel : GroupBaseModel, IResponseModel
|
||||
{
|
||||
public GroupResponseModel(Group group)
|
||||
public GroupResponseModel(Group group, IEnumerable<SelectionReadOnly> collections)
|
||||
{
|
||||
if(group == null)
|
||||
{
|
||||
@ -20,6 +23,7 @@ namespace Bit.Core.Models.Api.Public
|
||||
Name = group.Name;
|
||||
AccessAll = group.AccessAll;
|
||||
ExternalId = group.ExternalId;
|
||||
Collections = collections?.Select(c => new AssociationWithPermissionsResponseModel(c));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -34,5 +38,9 @@ namespace Bit.Core.Models.Api.Public
|
||||
/// <example>539a36c5-e0d2-4cf9-979e-51ecf5cf6593</example>
|
||||
[Required]
|
||||
public Guid Id { get; set; }
|
||||
/// <summary>
|
||||
/// The associated collections that this group can access.
|
||||
/// </summary>
|
||||
public IEnumerable<AssociationWithPermissionsResponseModel> Collections { get; set; }
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user