add rule permission reflected operation support (#872)

Feature: 添加 Rule, Permission 反向位运算支持
This commit is contained in:
Ju4tCode
2022-03-17 21:11:37 +08:00
committed by GitHub
parent 06f8dde33c
commit 02de6fd266
5 changed files with 196 additions and 2 deletions

View File

@ -85,7 +85,7 @@ class Permission:
)
return any(results)
def __and__(self, other) -> NoReturn:
def __and__(self, other: object) -> NoReturn:
raise RuntimeError("And operation between Permissions is not allowed.")
def __or__(
@ -98,6 +98,16 @@ class Permission:
else:
return Permission(*self.checkers, other)
def __ror__(
self, other: Optional[Union["Permission", T_PermissionChecker]]
) -> "Permission":
if other is None:
return self
elif isinstance(other, Permission):
return Permission(*other.checkers, *self.checkers)
else:
return Permission(other, *self.checkers)
class User:
"""检查当前事件是否属于指定会话