__get_user_level.py 560 Bytes
Newer Older
1
from .__is_member import is_member
Florent Chehab's avatar
Florent Chehab committed
2
from django.contrib.auth.models import User
3
from shared import OBJ_MODERATION_PERMISSIONS
Florent Chehab's avatar
Florent Chehab committed
4 5


Florent Chehab's avatar
Florent Chehab committed
6
def get_user_level(user: User) -> int:
Florent Chehab's avatar
Florent Chehab committed
7
    """
Florent Chehab's avatar
Florent Chehab committed
8
    Returns the user level as int.
Florent Chehab's avatar
Florent Chehab committed
9 10 11 12
    TODO unit test
    """
    if user.is_staff:
        return OBJ_MODERATION_PERMISSIONS["staff"]
13
    elif is_member("DRI", user):
Florent Chehab's avatar
Florent Chehab committed
14
        return OBJ_MODERATION_PERMISSIONS["DRI"]
15
    elif is_member("Moderators", user):
Florent Chehab's avatar
Florent Chehab committed
16 17 18
        return OBJ_MODERATION_PERMISSIONS["moderator"]
    else:
        return OBJ_MODERATION_PERMISSIONS["authenticated_user"]