mirror of
https://github.com/mealie-recipes/mealie.git
synced 2025-12-22 02:05:13 -05:00
* 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
37 lines
1016 B
Python
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
|