1
0
mirror of https://github.com/bitwarden/server.git synced 2025-04-05 05:00:19 -05:00

Fix logic and apply to controller

This commit is contained in:
Thomas Rittson 2025-03-26 15:14:58 +10:00
parent 3d564e7658
commit 74f45a18ae
No known key found for this signature in database
GPG Key ID: CDDDA03861C35E27
3 changed files with 17 additions and 13 deletions

View File

@ -35,6 +35,7 @@ namespace Bit.Api.AdminConsole.Controllers;
[Route("organizations/{orgId}/users")] [Route("organizations/{orgId}/users")]
[Authorize("Application")] [Authorize("Application")]
[Authorize<MemberOrProviderRequirement>]
public class OrganizationUsersController : Controller public class OrganizationUsersController : Controller
{ {
private readonly IOrganizationRepository _organizationRepository; private readonly IOrganizationRepository _organizationRepository;
@ -137,7 +138,7 @@ public class OrganizationUsersController : Controller
return response; return response;
} }
[Authorize<OrganizationMemberRequirement>] [Authorize<MemberOrProviderRequirement>]
[HttpGet("mini-details")] [HttpGet("mini-details")]
public async Task<ListResponseModel<OrganizationUserUserMiniDetailsResponseModel>> GetMiniDetails(Guid orgId) public async Task<ListResponseModel<OrganizationUserUserMiniDetailsResponseModel>> GetMiniDetails(Guid orgId)
{ {

View File

@ -0,0 +1,15 @@
#nullable enable
using Bit.Core.AdminConsole.OrganizationFeatures.Shared.Authorization;
using Bit.Core.Context;
namespace Bit.Core.AdminConsole.OrganizationFeatures;
/// <summary>
/// Requires that the user is a member of the organization or a provider for the organization.
/// </summary>
public class MemberOrProviderRequirement : IOrganizationRequirement
{
public async Task<bool> AuthorizeAsync(Guid organizationId, CurrentContextOrganization? organizationClaims, ICurrentContext currentContext)
=> organizationClaims is not null || await currentContext.ProviderUserForOrgAsync(organizationId);
}

View File

@ -1,12 +0,0 @@
#nullable enable
using Bit.Core.AdminConsole.OrganizationFeatures.Shared.Authorization;
using Bit.Core.Context;
namespace Bit.Core.AdminConsole.OrganizationFeatures;
public class OrganizationMemberRequirement : IOrganizationRequirement
{
public Task<bool> AuthorizeAsync(Guid organizationId, CurrentContextOrganization? organizationClaims, ICurrentContext currentContext)
=> Task.FromResult(organizationClaims is not null);
}