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
from .isOwner import IsOwner # noqa: F401
from .noDelete import NoDelete # noqa: F401
from .isStaffOrReadOnly import IsStaffOrReadOnly # noqa: F401
from .readOnly import ReadOnly # noqa: F401
from .isDriOrReadOnly import IsDriOrReadOnly # noqa: F401
from .default_viewset_permissions import DEFAULT_VIEWSET_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
return False
import yaml
from os.path import join, realpath, dirname
from backend.permissions import IsOwner, IsStaffOrReadOnly, IsDriOrReadOnly
from backend.permissions import IsOwner, IsStaffOrReadOnly, IsDriOrReadOnly, ReadOnly
from rest_framework.permissions import IsAdminUser
from backend.permissions import DEFAULT_VIEWSET_PERMISSIONS
from general.api import get_api_config
def get_viewset_permissions(viewset):
current_dir = dirname(realpath(__file__))
api_file_loc = join(current_dir, '../../general/api/api_config.yml')
with open(api_file_loc, "r") as file:
api_config = yaml.load(
api_config = get_api_config()
for obj in api_config:
if obj['viewset'] == viewset:
custom_permission = obj["viewset_permission"]
if custom_permission == "IsOwner":
permission = (IsOwner,)
......@@ -22,11 +17,14 @@ def get_viewset_permissions(viewset):
permission = (IsDriOrReadOnly,)
elif custom_permission == "IsStaff":
permission = (IsAdminUser,)
elif custom_permission == 'default':
permission = tuple()
raise Exception(
"Permission not supported ! Dev what did you do ?")
if obj["read_only"]:
permission += (ReadOnly,)
except KeyError:
raise Exception("Viewset not found in API configuraiton, cannot process !")
......@@ -13,7 +13,8 @@ def get_api_config():
"requires_testing": False,
"moderation_level": 2,
"versionned": False,
"read_only": False
"read_only": False,
"viewset_permission": 'default'
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