2022-01-15 00:23:50 +00:00
|
|
|
from enum import Enum
|
|
|
|
|
2022-03-23 02:50:12 +00:00
|
|
|
|
2022-01-15 00:23:50 +00:00
|
|
|
class PermissionHelper:
|
|
|
|
@staticmethod
|
2022-04-14 02:10:25 +00:00
|
|
|
def both_have_perm(
|
|
|
|
permission_mask_a: str, permission_mask_b: str, permission_tested: Enum
|
|
|
|
):
|
2022-04-11 05:23:55 +00:00
|
|
|
return PermissionHelper.combine_perm_bool(
|
2022-04-14 02:10:25 +00:00
|
|
|
permission_mask_a[permission_tested.value],
|
|
|
|
permission_mask_b[permission_tested.value],
|
2022-03-23 02:50:12 +00:00
|
|
|
)
|
2022-01-15 00:23:50 +00:00
|
|
|
|
|
|
|
@staticmethod
|
2022-04-14 02:10:25 +00:00
|
|
|
def combine_perm(permission_mask_a: str, permission_mask_b: str) -> str:
|
|
|
|
return "1" if (permission_mask_a == "1" and permission_mask_b == "1") else "0"
|
2022-01-15 00:23:50 +00:00
|
|
|
|
|
|
|
@staticmethod
|
2022-04-14 02:10:25 +00:00
|
|
|
def combine_perm_bool(permission_mask_a: str, permission_mask_b: str) -> bool:
|
|
|
|
return permission_mask_a == "1" and permission_mask_b == "1"
|
2022-01-15 00:23:50 +00:00
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def combine_masks(permission_mask_a: str, permission_mask_b: str) -> str:
|
|
|
|
both_masks = zip(list(permission_mask_a), list(permission_mask_b))
|
2022-03-23 02:50:12 +00:00
|
|
|
return "".join(
|
2022-04-11 05:23:55 +00:00
|
|
|
map(lambda x: PermissionHelper.combine_perm(x[0], x[1]), both_masks)
|
2022-03-23 02:50:12 +00:00
|
|
|
)
|