# Path: core/exceptions.py
# class InvalidRequest(APIException):
#     status_code = status.HTTP_400_BAD_REQUEST
#     default_detail = "Votre requête n'est pas valide"
#     default_code = 'invalid_request'
# 
# Path: core/helpers.py
# def filter_dict_keys(obj: dict, whitelist: Sequence) -> dict:
#     """
#     Filter dictionnary keys from a whitelist
# 
#     Args:
#         obj: the dictionnary to filter
#         whitelist: the whitelist of keys to keep
# 
#     Returns:
#         dict: the filtered dictionnary
#     """
#     return { k: v for k, v in obj.items() if k in whitelist }


from typing import List
from collections import OrderedDict
from django.utils.module_loading import import_string
from rest_framework.exceptions import PermissionDenied
from rest_framework.relations import ManyRelatedField
from rest_framework import serializers
from .exceptions import InvalidRequest
from .helpers import filter_dict_keys

        return list(field_names)

    def check_manager_rights_on_fields(self, fields: OrderedDict) -> None:
        """
        Check that fields comply with manager permissions
        """
        is_manager = getattr(self.context.get("request"), "is_manager", None)
        manager_fields = set(getattr(self.Meta, "manager_fields", []))

        for key in fields:
            if key in manager_fields and not is_manager:
                raise PermissionDenied(f"Cannot use '{key}' field")

    def get_fields(self) -> OrderedDict:
        """
        Override of rest_framework.serializers.ModelSerializer.get_fields
        Change normal related field for included ones if specified in include tree
        Returns a dictionary of {field_name: field_instance}.
        """
        fields = super().get_fields()
        include_tree = self._context.get('include_tree')
        if not include_tree:
            self.check_manager_rights_on_fields(fields)
            return fields

        # Update all included fields with included serializers
        for key, sub_tree in include_tree.items():
            if key not in fields:
                msg = f"Key '{key}' is not a declared field of {type(self).__name__}"

# Path: core/exceptions.py
# class InvalidRequest(APIException):
#     status_code = status.HTTP_400_BAD_REQUEST
#     default_detail = "Votre requête n'est pas valide"
#     default_code = 'invalid_request'
# 
# Path: core/helpers.py
# def filter_dict_keys(obj: dict, whitelist: Sequence) -> dict:
#     """
#     Filter dictionnary keys from a whitelist
# 
#     Args:
#         obj: the dictionnary to filter
#         whitelist: the whitelist of keys to keep
# 
#     Returns:
#         dict: the filtered dictionnary
#     """
#     return { k: v for k, v in obj.items() if k in whitelist }


# Path: core/serializers.py
from typing import List
from collections import OrderedDict
from django.utils.module_loading import import_string
from rest_framework.exceptions import PermissionDenied
from rest_framework.relations import ManyRelatedField
from rest_framework import serializers
from .exceptions import InvalidRequest
from .helpers import filter_dict_keys


        return list(field_names)

    def check_manager_rights_on_fields(self, fields: OrderedDict) -> None:
        """
        Check that fields comply with manager permissions
        """
        is_manager = getattr(self.context.get("request"), "is_manager", None)
        manager_fields = set(getattr(self.Meta, "manager_fields", []))

        for key in fields:
            if key in manager_fields and not is_manager:
                raise PermissionDenied(f"Cannot use '{key}' field")

    def get_fields(self) -> OrderedDict:
        """
        Override of rest_framework.serializers.ModelSerializer.get_fields
        Change normal related field for included ones if specified in include tree
        Returns a dictionary of {field_name: field_instance}.
        """
        fields = super().get_fields()
        include_tree = self._context.get('include_tree')
        if not include_tree:
            self.check_manager_rights_on_fields(fields)
            return fields

        # Update all included fields with included serializers
        for key, sub_tree in include_tree.items():
            if key not in fields:
                msg = f"Key '{key}' is not a declared field of {type(self).__name__}"

                raise InvalidRequest(msg, code="invalid_field")