mirror of
https://github.com/bitwarden/server.git
synced 2024-11-21 12:05:42 +01:00
SCIM: Associate users to group on PUT/POST (#2139)
* associate users to group on PUT/POST * fix logic
This commit is contained in:
parent
378b54524f
commit
cf16be16c6
@ -1,4 +1,5 @@
|
|||||||
using System.Text.Json;
|
using System.Text.Json;
|
||||||
|
using Bit.Core.Entities;
|
||||||
using Bit.Core.Repositories;
|
using Bit.Core.Repositories;
|
||||||
using Bit.Core.Services;
|
using Bit.Core.Services;
|
||||||
using Bit.Scim.Context;
|
using Bit.Scim.Context;
|
||||||
@ -126,6 +127,7 @@ namespace Bit.Scim.Controllers.v2
|
|||||||
|
|
||||||
var group = model.ToGroup(organizationId);
|
var group = model.ToGroup(organizationId);
|
||||||
await _groupService.SaveAsync(group, null);
|
await _groupService.SaveAsync(group, null);
|
||||||
|
await UpdateGroupMembersAsync(group, model, true);
|
||||||
var response = new ScimGroupResponseModel(group);
|
var response = new ScimGroupResponseModel(group);
|
||||||
return new CreatedResult(Url.Action(nameof(Get), new { group.OrganizationId, group.Id }), response);
|
return new CreatedResult(Url.Action(nameof(Get), new { group.OrganizationId, group.Id }), response);
|
||||||
}
|
}
|
||||||
@ -145,6 +147,7 @@ namespace Bit.Scim.Controllers.v2
|
|||||||
|
|
||||||
group.Name = model.DisplayName;
|
group.Name = model.DisplayName;
|
||||||
await _groupService.SaveAsync(group);
|
await _groupService.SaveAsync(group);
|
||||||
|
await UpdateGroupMembersAsync(group, model, false);
|
||||||
return new ObjectResult(new ScimGroupResponseModel(group));
|
return new ObjectResult(new ScimGroupResponseModel(group));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -295,5 +298,34 @@ namespace Bit.Scim.Controllers.v2
|
|||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private async Task UpdateGroupMembersAsync(Group group, ScimGroupRequestModel model, bool skipIfEmpty)
|
||||||
|
{
|
||||||
|
if (_scimContext.RequestScimProvider != Core.Enums.ScimProviderType.Okta)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!memberIds.Any() && skipIfEmpty)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
await _groupRepository.UpdateUsersAsync(group.Id, memberIds);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -19,5 +19,13 @@ namespace Bit.Scim.Models
|
|||||||
OrganizationId = organizationId
|
OrganizationId = organizationId
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<GroupMembersModel> Members { get; set; }
|
||||||
|
|
||||||
|
public class GroupMembersModel
|
||||||
|
{
|
||||||
|
public string Value { get; set; }
|
||||||
|
public string Display { get; set; }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user