from rest_framework import views
from rest_framework.routers import DefaultRouter
from rest_framework.permissions import IsAdminUser
from rest_framework.response import Response
from rest_framework.reverse import reverse
from rest_framework.urlpatterns import format_suffix_patterns


class SecuredDefaultRouter(DefaultRouter):
    """
    Extend the `DefaultRouter` so that the API root view
    is only visible for the admin users
    """

    def get_api_root_view(self):
        """
        Return a view to use as the API root.
        """
        api_root_dict = {}
        list_name = self.routes[0].name
        for prefix, viewset, basename in self.registry:
            api_root_dict[prefix] = list_name.format(basename=basename)

        class APIRoot(views.APIView):
            _ignore_model_permissions = True

            # only accept admin users
            permission_classes = (IsAdminUser,)

            def get(self, request, format=None):
                ret = {}
                for key, url_name in api_root_dict.items():
                    ret[key] = reverse(url_name, request=request, format=format)
                return Response(ret)

        return APIRoot.as_view()

826a0b36b408e499ef850e9eccd117f696037f10
<mask token>


class SecuredDefaultRouter(DefaultRouter):
    <mask token>
    <mask token>

<mask token>


class SecuredDefaultRouter(DefaultRouter):
    <mask token>

    def get_api_root_view(self):
        """
        Return a view to use as the API root.
        """
        api_root_dict = {}
        list_name = self.routes[0].name
        for prefix, viewset, basename in self.registry:
            api_root_dict[prefix] = list_name.format(basename=basename)


        class APIRoot(views.APIView):
            _ignore_model_permissions = True
            permission_classes = IsAdminUser,

            def get(self, request, format=None):
                ret = {}
                for key, url_name in api_root_dict.items():
                    ret[key] = reverse(url_name, request=request, format=format
                        )
                return Response(ret)
        return APIRoot.as_view()

<mask token>


class SecuredDefaultRouter(DefaultRouter):
    """
    Extend the `DefaultRouter` so that the API root view
    is only visible for the admin users
    """

    def get_api_root_view(self):
        """
        Return a view to use as the API root.
        """
        api_root_dict = {}
        list_name = self.routes[0].name
        for prefix, viewset, basename in self.registry:
            api_root_dict[prefix] = list_name.format(basename=basename)


        class APIRoot(views.APIView):
            _ignore_model_permissions = True
            permission_classes = IsAdminUser,

            def get(self, request, format=None):
                ret = {}
                for key, url_name in api_root_dict.items():
                    ret[key] = reverse(url_name, request=request, format=format
                        )
                return Response(ret)
        return APIRoot.as_view()

from rest_framework import views
from rest_framework.routers import DefaultRouter
from rest_framework.permissions import IsAdminUser
from rest_framework.response import Response
from rest_framework.reverse import reverse
from rest_framework.urlpatterns import format_suffix_patterns


class SecuredDefaultRouter(DefaultRouter):
    """
    Extend the `DefaultRouter` so that the API root view
    is only visible for the admin users
    """

    def get_api_root_view(self):
        """
        Return a view to use as the API root.
        """
        api_root_dict = {}
        list_name = self.routes[0].name
        for prefix, viewset, basename in self.registry:
            api_root_dict[prefix] = list_name.format(basename=basename)


        class APIRoot(views.APIView):
            _ignore_model_permissions = True
            permission_classes = IsAdminUser,

            def get(self, request, format=None):
                ret = {}
                for key, url_name in api_root_dict.items():
                    ret[key] = reverse(url_name, request=request, format=format
                        )
                return Response(ret)
        return APIRoot.as_view()

from rest_framework import views
from rest_framework.routers import DefaultRouter
from rest_framework.permissions import IsAdminUser
from rest_framework.response import Response
from rest_framework.reverse import reverse
from rest_framework.urlpatterns import format_suffix_patterns


class SecuredDefaultRouter(DefaultRouter):
    """
    Extend the `DefaultRouter` so that the API root view
    is only visible for the admin users
    """

    def get_api_root_view(self):
        """
        Return a view to use as the API root.
        """
        api_root_dict = {}
        list_name = self.routes[0].name
        for prefix, viewset, basename in self.registry:
            api_root_dict[prefix] = list_name.format(basename=basename)

        class APIRoot(views.APIView):
            _ignore_model_permissions = True

            # only accept admin users
            permission_classes = (IsAdminUser,)

            def get(self, request, format=None):
                ret = {}
                for key, url_name in api_root_dict.items():
                    ret[key] = reverse(url_name, request=request, format=format)
                return Response(ret)

        return APIRoot.as_view()
