mirror of
https://github.com/bitwarden/server.git
synced 2025-05-28 23:04:50 -05:00
Allow MP policy check when registering via SSO (#1779)
* add endpoint to policies for invited users * convert serialization to use built in dotnet tool
This commit is contained in:
parent
f51bdfe2e3
commit
8cbf1906ae
@ -106,6 +106,32 @@ namespace Bit.Api.Controllers
|
|||||||
return new ListResponseModel<PolicyResponseModel>(responses);
|
return new ListResponseModel<PolicyResponseModel>(responses);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[AllowAnonymous]
|
||||||
|
[HttpGet("invited-user")]
|
||||||
|
public async Task<ListResponseModel<PolicyResponseModel>> GetByInvitedUser(string orgId, [FromQuery] string userId)
|
||||||
|
{
|
||||||
|
var user = await _userService.GetUserByIdAsync(new Guid(userId));
|
||||||
|
if (user == null)
|
||||||
|
{
|
||||||
|
throw new UnauthorizedAccessException();
|
||||||
|
}
|
||||||
|
var orgIdGuid = new Guid(orgId);
|
||||||
|
var orgUsersByUserId = await _organizationUserRepository.GetManyByUserAsync(user.Id);
|
||||||
|
var orgUser = orgUsersByUserId.SingleOrDefault(u => u.OrganizationId == orgIdGuid);
|
||||||
|
if (orgUser == null)
|
||||||
|
{
|
||||||
|
throw new NotFoundException();
|
||||||
|
}
|
||||||
|
if (orgUser.Status != OrganizationUserStatusType.Invited)
|
||||||
|
{
|
||||||
|
throw new UnauthorizedAccessException();
|
||||||
|
}
|
||||||
|
|
||||||
|
var policies = await _policyRepository.GetManyByOrganizationIdAsync(orgIdGuid);
|
||||||
|
var responses = policies.Where(p => p.Enabled).Select(p => new PolicyResponseModel(p));
|
||||||
|
return new ListResponseModel<PolicyResponseModel>(responses);
|
||||||
|
}
|
||||||
|
|
||||||
[HttpPut("{type}")]
|
[HttpPut("{type}")]
|
||||||
public async Task<PolicyResponseModel> Put(string orgId, int type, [FromBody] PolicyRequestModel model)
|
public async Task<PolicyResponseModel> Put(string orgId, int type, [FromBody] PolicyRequestModel model)
|
||||||
{
|
{
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.ComponentModel.DataAnnotations;
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
using System.Text.Json;
|
||||||
using Bit.Core.Enums;
|
using Bit.Core.Enums;
|
||||||
using Bit.Core.Models.Table;
|
using Bit.Core.Models.Table;
|
||||||
using Newtonsoft.Json;
|
|
||||||
|
|
||||||
namespace Bit.Api.Models.Request
|
namespace Bit.Api.Models.Request
|
||||||
{
|
{
|
||||||
@ -27,7 +27,7 @@ namespace Bit.Api.Models.Request
|
|||||||
public Policy ToPolicy(Policy existingPolicy)
|
public Policy ToPolicy(Policy existingPolicy)
|
||||||
{
|
{
|
||||||
existingPolicy.Enabled = Enabled.GetValueOrDefault();
|
existingPolicy.Enabled = Enabled.GetValueOrDefault();
|
||||||
existingPolicy.Data = Data != null ? JsonConvert.SerializeObject(Data) : null;
|
existingPolicy.Data = Data != null ? JsonSerializer.Serialize(Data) : null;
|
||||||
return existingPolicy;
|
return existingPolicy;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user