__get_user_level.py 530 Bytes
Newer Older
1
from .__is_member import is_member
2
from base_app.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
    """
    if user.is_staff:
        return OBJ_MODERATION_PERMISSIONS["staff"]
12
    elif is_member("DRI", user):
Florent Chehab's avatar
Florent Chehab committed
13
        return OBJ_MODERATION_PERMISSIONS["DRI"]
14
    elif is_member("Moderators", user):
Florent Chehab's avatar
Florent Chehab committed
15
16
17
        return OBJ_MODERATION_PERMISSIONS["moderator"]
    else:
        return OBJ_MODERATION_PERMISSIONS["authenticated_user"]