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:
@@ -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".
|
||||
|
||||
Reference in New Issue
Block a user