Commit 92f591e0 authored by Florent Chehab's avatar Florent Chehab
Browse files

Fixed oneToOne fields on taggedItems => ForeignKey

Cleared migrations
added LIST_SHOULD_BE_DETAIL in MyModelViewSet
cleaned get_viewset_permissions
parent a49d5f70
Pipeline #27137 passed with stages
in 2 minutes and 38 seconds
...@@ -2,6 +2,7 @@ from .noDeleteIfNotStaff import NoDeleteIfNotStaff # noqa: F401 ...@@ -2,6 +2,7 @@ from .noDeleteIfNotStaff import NoDeleteIfNotStaff # noqa: F401
from .isOwner import IsOwner # noqa: F401 from .isOwner import IsOwner # noqa: F401
from .noDelete import NoDelete # noqa: F401 from .noDelete import NoDelete # noqa: F401
from .isStaffOrReadOnly import IsStaffOrReadOnly # noqa: F401 from .isStaffOrReadOnly import IsStaffOrReadOnly # noqa: F401
from .readOnly import ReadOnly # noqa: F401
from .isDriOrReadOnly import IsDriOrReadOnly # noqa: F401 from .isDriOrReadOnly import IsDriOrReadOnly # noqa: F401
from .default_viewset_permissions import DEFAULT_VIEWSET_PERMISSIONS # noqa: F401 from .default_viewset_permissions import DEFAULT_VIEWSET_PERMISSIONS # noqa: F401
from .obj_moderation_permission import OBJ_MODERATION_PERMISSIONS # noqa: F401 from .obj_moderation_permission import OBJ_MODERATION_PERMISSIONS # noqa: F401
......
from rest_framework import permissions
class ReadOnly(permissions.BasePermission):
def has_permission(self, request, view):
if request.method in permissions.SAFE_METHODS:
return True
else:
return False
import yaml from backend.permissions import IsOwner, IsStaffOrReadOnly, IsDriOrReadOnly, ReadOnly
from os.path import join, realpath, dirname
from backend.permissions import IsOwner, IsStaffOrReadOnly, IsDriOrReadOnly
from rest_framework.permissions import IsAdminUser from rest_framework.permissions import IsAdminUser
from backend.permissions import DEFAULT_VIEWSET_PERMISSIONS from backend.permissions import DEFAULT_VIEWSET_PERMISSIONS
from general.api import get_api_config
def get_viewset_permissions(viewset): def get_viewset_permissions(viewset):
current_dir = dirname(realpath(__file__)) api_config = get_api_config()
api_file_loc = join(current_dir, '../../general/api/api_config.yml') for obj in api_config:
with open(api_file_loc, "r") as file: if obj['viewset'] == viewset:
api_config = yaml.load(file.read()) custom_permission = obj["viewset_permission"]
for obj in api_config: if custom_permission == "IsOwner":
if obj['viewset'] == viewset: permission = (IsOwner,)
try: elif custom_permission == "IsStaffOrReadOnly":
custom_permission = obj["viewset_permission"] permission = (IsStaffOrReadOnly,)
if custom_permission == "IsOwner": elif custom_permission == "IsDriOrReadOnly":
permission = (IsOwner,) permission = (IsDriOrReadOnly,)
elif custom_permission == "IsStaffOrReadOnly": elif custom_permission == "IsStaff":
permission = (IsStaffOrReadOnly,) permission = (IsAdminUser,)
elif custom_permission == "IsDriOrReadOnly": elif custom_permission == 'default':
permission = (IsDriOrReadOnly,) permission = tuple()
elif custom_permission == "IsStaff": else:
permission = (IsAdminUser,) raise Exception(
else: "Permission not supported ! Dev what did you do ?")
raise Exception(
"Permission not supported ! Dev what did you do ?") if obj["read_only"]:
return DEFAULT_VIEWSET_PERMISSIONS + permission permission += (ReadOnly,)
except KeyError: return DEFAULT_VIEWSET_PERMISSIONS + permission
return DEFAULT_VIEWSET_PERMISSIONS
raise Exception("Viewset not found in API configuraiton, cannot process !") raise Exception("Viewset not found in API configuraiton, cannot process !")
...@@ -13,7 +13,8 @@ def get_api_config(): ...@@ -13,7 +13,8 @@ def get_api_config():
"requires_testing": False, "requires_testing": False,
"moderation_level": 2, "moderation_level": 2,
"versionned": False, "versionned": False,
"read_only": False "read_only": False,
"viewset_permission": 'default'
} }
for obj in api_config: for obj in api_config:
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment