is_moderation_required.py 1.02 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
from backend.utils import get_user_level
from django.conf import settings
from .obj_moderation_permission import OBJ_MODERATION_PERMISSIONS


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:
                return user_level < OBJ_MODERATION_PERMISSIONS["moderator"]
            else:
                return False
        elif model_moderation_level == 2:
            return not user_level < OBJ_MODERATION_PERMISSIONS["moderator"]
        else:
            raise Exception(
                "No other moderation level should be defined...")