Commit ac56d059 authored by Florent Chehab's avatar Florent Chehab
Browse files

New moderation protocols operationnal

parent 7cc17dfe
......@@ -3,7 +3,7 @@ from django.utils import timezone
from .pendingModeration import PendingModeration
from django.conf import settings
from django.contrib.contenttypes.models import ContentType
from backend.utils import is_member
from backend.utils import does_user_have_moderation_rights
from .myModel import MyModel
from .pendingModeration import PendingModerationSerializer
......@@ -50,20 +50,20 @@ class MyModelSerializer(serializers.ModelSerializer):
model = MyModel
def moderation_required(self):
if hasattr(self.Meta, 'NEVER_MODERATE') and self.Meta.NEVER_MODERATE:
return False
moderation_level = self.Meta.model.moderation_level
user = self.get_user_in_request()
request = self.context['request']
if user.is_staff:
if moderation_level == 0:
return False
if request.method in ['POST', 'PUT']: # should be always the case
return not is_member('Moderators', request.user)
return False
elif moderation_level == 1:
return not does_user_have_moderation_rights(user)
return False
elif moderation_level == 2:
return not does_user_have_moderation_rights(user)
raise Exception("No other moderation level should be defined...")
def get_user_in_request(self):
return self.context['request'].user
......@@ -34,7 +34,6 @@ class UserDataSerializer(MyModelSerializer):
class Meta:
model = UserData
fields = '__all__'
class UserDataViewSet(MyModelViewSet):
......@@ -3,3 +3,4 @@ from .file import read_file, write_file # noqa: F401
from .find_api_end_point_for_viewset import find_api_end_point_for_viewset # noqa: F401
from .get_moderation_level import get_moderation_level # noqa: F401
from .get_viewset_permissions import get_viewset_permissions # noqa: F401
from .does_user_have_moderation_rights import does_user_have_moderation_rights # noqa: F401
from .is_member import is_member
def does_user_have_moderation_rights(user):
TODO unit test
return user.is_staff or is_member('DRI', user) or is_member('Moderators', user)
Supports Markdown
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