-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
398 changed files
with
18,706 additions
and
8,109 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,49 @@ | ||
import enum | ||
import functools | ||
|
||
__all__ = ["RoleType"] | ||
|
||
|
||
@functools.total_ordering | ||
class RoleType(enum.Enum): | ||
""" | ||
Role type privilege | ||
Usage: | ||
>>> from antarest.core.roles import RoleType | ||
>>> RoleType.ADMIN == RoleType.ADMIN | ||
True | ||
>>> RoleType.ADMIN == RoleType.WRITER | ||
False | ||
>>> RoleType.ADMIN > RoleType.WRITER | ||
True | ||
>>> RoleType.ADMIN >= RoleType.WRITER | ||
True | ||
>>> # noinspection PyTypeChecker | ||
>>> RoleType.RUNNER > 10 | ||
True | ||
>>> # noinspection PyTypeChecker | ||
>>> RoleType.READER > "foo" | ||
Traceback (most recent call last): | ||
... | ||
TypeError: '>' not supported between instances of 'RoleType' and 'str' | ||
""" | ||
|
||
ADMIN = 40 | ||
WRITER = 30 | ||
RUNNER = 20 | ||
READER = 10 | ||
|
||
def is_higher_or_equals(self, other: "RoleType") -> bool: | ||
return int(self.value) >= int(other.value) | ||
def __ge__(self, other: object) -> bool: | ||
""" | ||
Returns `True` if the current role has same or greater privilege than other role. | ||
""" | ||
|
||
if isinstance(other, RoleType): | ||
return self.value >= other.value | ||
elif isinstance(other, int): | ||
return self.value >= other | ||
else: | ||
return NotImplemented |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.