Files
mealie/mealie/routes/_base/checks.py
Hayden 7866f0f46e Feature/improve localization (#1147)
* use locale to set language header

* rewrite i18n provider and drop dependency

* rename file

* rename CrudMixin to HttpRepo

* refactor: code-cleanup

* add crowdin source

* remove unused translations

* grab translations from dev branch

* add translation support for foods, units, and labels

* remove rich import
2022-04-10 14:07:35 -08:00

37 lines
1016 B
Python

from fastapi import HTTPException, status
from mealie.schema.user.user import PrivateUser
class OperationChecks:
"""
OperationChecks class is a mixin class that can be used on routers to provide common permission
checks and raise the appropriate http error as necessary
"""
user: PrivateUser
ForbiddenException = HTTPException(status.HTTP_403_FORBIDDEN)
UnauthorizedException = HTTPException(status.HTTP_401_UNAUTHORIZED)
def __init__(self, user: PrivateUser) -> None:
self.user = user
# =========================================
# User Permission Checks
def can_manage(self) -> bool:
if not self.user.can_manage:
raise self.ForbiddenException
return True
def can_invite(self) -> bool:
if not self.user.can_invite:
raise self.ForbiddenException
return True
def can_organize(self) -> bool:
if not self.user.can_organize:
raise self.ForbiddenException
return True