mirror of
https://github.com/bitwarden/server
synced 2026-01-03 17:14:00 +00:00
* [PM-13748] Remove SCIM provider type checks from group endpoints * Remove Okta provider type config from group command tests --------- Co-authored-by: bnagawiecki <107435978+bnagawiecki@users.noreply.github.com>
58 lines
1.7 KiB
C#
58 lines
1.7 KiB
C#
using Bit.Core.AdminConsole.Entities;
|
|
using Bit.Core.AdminConsole.OrganizationFeatures.Groups.Interfaces;
|
|
using Bit.Core.AdminConsole.Repositories;
|
|
using Bit.Core.Enums;
|
|
using Bit.Core.Exceptions;
|
|
using Bit.Scim.Groups.Interfaces;
|
|
using Bit.Scim.Models;
|
|
|
|
namespace Bit.Scim.Groups;
|
|
|
|
public class PutGroupCommand : IPutGroupCommand
|
|
{
|
|
private readonly IGroupRepository _groupRepository;
|
|
private readonly IUpdateGroupCommand _updateGroupCommand;
|
|
|
|
public PutGroupCommand(
|
|
IGroupRepository groupRepository,
|
|
IUpdateGroupCommand updateGroupCommand)
|
|
{
|
|
_groupRepository = groupRepository;
|
|
_updateGroupCommand = updateGroupCommand;
|
|
}
|
|
|
|
public async Task<Group> PutGroupAsync(Organization organization, Guid id, ScimGroupRequestModel model)
|
|
{
|
|
var group = await _groupRepository.GetByIdAsync(id);
|
|
if (group == null || group.OrganizationId != organization.Id)
|
|
{
|
|
throw new NotFoundException("Group not found.");
|
|
}
|
|
|
|
group.Name = model.DisplayName;
|
|
await _updateGroupCommand.UpdateGroupAsync(group, organization, EventSystemUser.SCIM);
|
|
await UpdateGroupMembersAsync(group, model);
|
|
|
|
return group;
|
|
}
|
|
|
|
private async Task UpdateGroupMembersAsync(Group group, ScimGroupRequestModel model)
|
|
{
|
|
if (model.Members == null)
|
|
{
|
|
return;
|
|
}
|
|
|
|
var memberIds = new List<Guid>();
|
|
foreach (var id in model.Members.Select(i => i.Value))
|
|
{
|
|
if (Guid.TryParse(id, out var guidId))
|
|
{
|
|
memberIds.Add(guidId);
|
|
}
|
|
}
|
|
|
|
await _groupRepository.UpdateUsersAsync(group.Id, memberIds);
|
|
}
|
|
}
|