kiwi-vpn/api/kiwi_vpn_api/permission.py

36 lines
673 B
Python
Raw Normal View History

2022-03-29 20:46:40 +00:00
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