From a0ac86888d06d176521641e3576d79d70dc94085 Mon Sep 17 00:00:00 2001 From: Thomas Rittson Date: Fri, 21 Mar 2025 14:02:47 +1000 Subject: [PATCH] use generics instead --- .../AdminConsole/Controllers/OrganizationUsersController.cs | 2 +- .../Shared/Authorization/OrganizationAuthorizeAttribute.cs | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/Api/AdminConsole/Controllers/OrganizationUsersController.cs b/src/Api/AdminConsole/Controllers/OrganizationUsersController.cs index d49f4386e2..788efca03b 100644 --- a/src/Api/AdminConsole/Controllers/OrganizationUsersController.cs +++ b/src/Api/AdminConsole/Controllers/OrganizationUsersController.cs @@ -146,7 +146,7 @@ public class OrganizationUsersController : Controller } [HttpGet("")] - [OrganizationAuthorize(typeof(ManageUsersRequirement))] + [OrganizationAuthorize] public async Task> Get(Guid orgId, bool includeGroups = false, bool includeCollections = false) { var organizationUsers = await _organizationUserUserDetailsQuery.GetOrganizationUserUserDetails( diff --git a/src/Core/AdminConsole/OrganizationFeatures/Shared/Authorization/OrganizationAuthorizeAttribute.cs b/src/Core/AdminConsole/OrganizationFeatures/Shared/Authorization/OrganizationAuthorizeAttribute.cs index f018313891..79bb6bbd06 100644 --- a/src/Core/AdminConsole/OrganizationFeatures/Shared/Authorization/OrganizationAuthorizeAttribute.cs +++ b/src/Core/AdminConsole/OrganizationFeatures/Shared/Authorization/OrganizationAuthorizeAttribute.cs @@ -2,12 +2,13 @@ namespace Bit.Core.AdminConsole.OrganizationFeatures.Shared.Authorization; -public class OrganizationAuthorizeAttribute(Type requirementType) +public class OrganizationAuthorizeAttribute : AuthorizeAttribute, IAuthorizationRequirementData + where T : IOrganizationRequirement, new() { public IEnumerable GetRequirements() { - var requirement = (IOrganizationRequirement)Activator.CreateInstance(requirementType)!; + var requirement = new T(); yield return requirement; } }