get_api_config.py 887 Bytes
Newer Older
1 2
import yaml
from os.path import join, realpath, dirname
3
from backend.permissions.obj_moderation_permission import OBJ_MODERATION_PERMISSIONS
4 5 6 7 8 9 10 11 12 13 14


def get_api_config():
    current_dir = dirname(realpath(__file__))
    with open(join(current_dir, 'api_config.yml'), 'r') as f:
        api_config = yaml.load(f)

    # clean api_config (add default arguments)
    DEFAULT_SETTINGS = {
        "ignore_in_admin": False,
        "requires_testing": False,
Florent Chehab's avatar
Florent Chehab committed
15 16
        "moderation_level": 2,
        "versionned": False,
17 18
        "read_only": False,
        "viewset_permission": 'default'
19 20 21
    }

    for obj in api_config:
22 23 24
        tmp = 'enforce_moderation_user_level'
        if tmp in obj.keys():
            obj[tmp] = OBJ_MODERATION_PERMISSIONS[obj[tmp]]
25 26 27 28 29
        for key in DEFAULT_SETTINGS:
            if key not in obj:
                obj[key] = DEFAULT_SETTINGS[key]

    return api_config