1
0
mirror of https://github.com/bitwarden/server synced 2025-12-15 15:53:59 +00:00

[PM-23921] [BEEEP] Add IOrganizationRequirements for each permission (#6105)

* Add BasePermissionRequirement and implement it for each permission

* Add tests
This commit is contained in:
Thomas Rittson
2025-07-31 11:22:06 +10:00
committed by GitHub
parent cfcb24bbc9
commit 88dd977848
7 changed files with 206 additions and 40 deletions

View File

@@ -6,6 +6,23 @@ namespace Bit.Core.Test.AdminConsole.Helpers;
public static class PermissionsHelpers
{
/// <summary>
/// Sets the specified permission.
/// </summary>
/// <param name="permissionName">The permission name specified as a string - using `nameof` is highly recommended.</param>
/// <param name="value">The value to set the permission to.</param>
/// <returns>No value; this mutates the permissions object.</returns>
public static void SetPermission(this Permissions permissions, string permissionName, bool value)
{
var prop = typeof(Permissions).GetProperty(permissionName);
if (prop == null)
{
throw new NullReferenceException("Invalid property name.");
}
prop.SetValue(permissions, true);
}
/// <summary>
/// Return a new Permission object with inverted permissions.
/// This is useful to test negative cases, e.g. "all other permissions should fail".