Remove the APIRoot view. Remove the Endpoint class. Remove the EndpointSerializer. Move API documentation generation from the root urls module to the app's urls module. Update the app API URL generation to be based on viewsets instead of an custom api_urls list. Remove MayanObjectPermissionsFilter and replace it with MayanViewSetObjectPermissionsFilter which allows mapping a required permission to a specific viewset action. Signed-off-by: Roberto Rosario <Roberto.Rosario@mayan-edms.com>
45 lines
1.3 KiB
Python
45 lines
1.3 KiB
Python
from __future__ import unicode_literals
|
|
|
|
from django.apps import apps
|
|
from django.conf import settings
|
|
from django.utils.module_loading import import_string
|
|
from django.utils.translation import ugettext_lazy as _
|
|
|
|
from rest_framework import routers
|
|
|
|
from mayan.apps.common import MayanAppConfig, menu_tools
|
|
|
|
from .links import (
|
|
link_api, link_api_documentation, link_api_documentation_redoc
|
|
)
|
|
from .licenses import * # NOQA
|
|
|
|
|
|
class RESTAPIApp(MayanAppConfig):
|
|
app_url = 'api'
|
|
app_namespace = 'rest_api'
|
|
name = 'mayan.apps.rest_api'
|
|
verbose_name = _('REST API')
|
|
|
|
def ready(self):
|
|
super(RESTAPIApp, self).ready()
|
|
from .urls import urlpatterns
|
|
|
|
settings.STRONGHOLD_PUBLIC_URLS += (r'^/%s/.+$' % self.app_url,)
|
|
menu_tools.bind_links(
|
|
links=(
|
|
link_api, link_api_documentation, link_api_documentation_redoc
|
|
)
|
|
)
|
|
router = routers.DefaultRouter()
|
|
|
|
for app in apps.get_app_configs():
|
|
if getattr(app, 'has_rest_api', False):
|
|
try:
|
|
for entry in import_string('{}.urls.api_router_entries'.format(app.name)):
|
|
router.register(**entry)
|
|
except ImportError:
|
|
pass
|
|
|
|
urlpatterns.extend(router.urls)
|