Question about Setting/Unsetting flags #21
-
I'm trying to detect whether there has been a change to my roles permissions by comparing the old permission value with the new one. But it seems that beyond some threshold when I set a permission via Recording.2024-07-10.140316.mp4Notice as I click the check boxes the permissions UniqueId string changes up top from it original value of "YwAA" and the "Confirm Changes" button enables and disables indicating a change in the permission has been detected or there has been no change. This is working as expected. But when I check "CanPlaceHolder9" and uncheck it, it doesn't seem to unset that flag. Maybe I am just doing it improperly. I have attached a reproducible example you can check out. The relevant files are Permission.cs, ApplicationRoleDtoExtensions.cs, PermissionMappingGrid.razor.cs, PermissionMappingGrid.razor. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Hi @GregFaaborg, private Task SetRolesAsync()
{
List<ApplicationRoleDto> roles = [];
var basePermission = (~Permission.All).ToUniqueId(); // this must the base-permission which has the max length
for (var i = 0; i < 5; i++)
{
roles.Add(new ApplicationRoleDto()
{
ApplicationRoleId = i,
Name = $"Role{i}",
Description = $"Descr{i}",
Permission = basePermission
});
}
_roles = roles;
return Task.CompletedTask;
} here you can see the difference Console.WriteLine(Permission.None.ToBinaryString()); // 0
Console.WriteLine((~Permission.All).ToBinaryString()); // 000000000000000000000 alternatively you can use this as None: public static readonly Flag<Permission> None = ~All; |
Beta Was this translation helpful? Give feedback.
Hi @GregFaaborg,
The issue lies with your base permission. Currently, you're using
Permission.None
, but you should use~Permission.All
to ensure the bit length covers all possible features. If you modify the method accordingly, it should resolve the problem.