__is_moderation_required.py 1.28 KB
Newer Older
1
from backend.utils.__get_user_level import get_user_level
2 3 4 5
from django.conf import settings
from .obj_moderation_permission import OBJ_MODERATION_PERMISSIONS


6 7 8 9 10 11 12 13 14
######################################
######################################
##
# IF YOU TOUCH THIS FILE, MODIFY IT'S
# JS EQUIVALENT (isModerationRequired)
##
######################################
######################################

15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
def is_moderation_required(model_moderation_level, obj_in_db, user, user_level=None):
    if user_level is None:
        user_level = get_user_level(user)

    if model_moderation_level == 0:
        return False
    else:
        # At this point we have to check the obj_moderation_level
        if obj_in_db is not None:
            obj_moderation_level = obj_in_db.obj_moderation_level
            if user_level < obj_moderation_level:
                return True

        if model_moderation_level == 1:
            if settings.MODERATION_ACTIVATED:
30
                return not user_level >= OBJ_MODERATION_PERMISSIONS["moderator"]
31 32 33
            else:
                return False
        elif model_moderation_level == 2:
34
            return not user_level >= OBJ_MODERATION_PERMISSIONS["moderator"]
35 36 37
        else:
            raise Exception(
                "No other moderation level should be defined...")