35 lines
673 B
Python
35 lines
673 B
Python
from __future__ import annotations
|
|
|
|
from enum import Enum, auto
|
|
|
|
from .db import User
|
|
|
|
|
|
class Permission(Enum):
|
|
tag = auto()
|
|
untag = auto()
|
|
edit = auto()
|
|
delete = auto()
|
|
|
|
def __repr__(self) -> str:
|
|
return self.name
|
|
|
|
@classmethod
|
|
def _(
|
|
cls,
|
|
actor: User | None,
|
|
target: User,
|
|
) -> set[Permission]:
|
|
result = set()
|
|
|
|
if actor is None:
|
|
return result
|
|
|
|
if isinstance(target, User):
|
|
if actor.is_admin():
|
|
if target != actor:
|
|
result |= set([cls.tag, cls.untag, cls.delete])
|
|
|
|
result.add(cls.edit)
|
|
|
|
return result
|