initial commit
This commit is contained in:
3
core/apps/companies/permissions/__init__.py
Normal file
3
core/apps/companies/permissions/__init__.py
Normal file
@@ -0,0 +1,3 @@
|
||||
from .accounts import * # noqa
|
||||
from .companies import * # noqa
|
||||
from .folders import * # noqa
|
||||
12
core/apps/companies/permissions/accounts.py
Normal file
12
core/apps/companies/permissions/accounts.py
Normal file
@@ -0,0 +1,12 @@
|
||||
from rest_framework import permissions
|
||||
|
||||
|
||||
class CompanyaccountPermission(permissions.BasePermission):
|
||||
|
||||
def __init__(self) -> None: ...
|
||||
|
||||
def __call__(self, *args, **kwargs):
|
||||
return self
|
||||
|
||||
def has_permission(self, request, view):
|
||||
return True
|
||||
23
core/apps/companies/permissions/companies.py
Normal file
23
core/apps/companies/permissions/companies.py
Normal file
@@ -0,0 +1,23 @@
|
||||
from rest_framework import permissions # type: ignore
|
||||
from rest_framework.views import APIView # type: ignore
|
||||
from rest_framework.request import HttpRequest # type: ignore
|
||||
|
||||
from core.apps.companies.models import (
|
||||
CompanyAccountModel,
|
||||
CompanyModel
|
||||
)
|
||||
|
||||
|
||||
class IsCompanyAccount(permissions.IsAuthenticated):
|
||||
def has_object_permission( # type: ignore
|
||||
self,
|
||||
request: HttpRequest,
|
||||
view: APIView,
|
||||
obj: CompanyModel
|
||||
) -> bool:
|
||||
if request.user.is_staff:
|
||||
return True
|
||||
|
||||
return CompanyAccountModel.objects.filter(
|
||||
company=obj, user=request.user,
|
||||
).exists()
|
||||
12
core/apps/companies/permissions/folders.py
Normal file
12
core/apps/companies/permissions/folders.py
Normal file
@@ -0,0 +1,12 @@
|
||||
from rest_framework import permissions
|
||||
|
||||
|
||||
class CompanyfolderPermission(permissions.BasePermission):
|
||||
|
||||
def __init__(self) -> None: ...
|
||||
|
||||
def __call__(self, *args, **kwargs):
|
||||
return self
|
||||
|
||||
def has_permission(self, request, view):
|
||||
return True
|
||||
Reference in New Issue
Block a user