Files
mayan-edms/mayan/apps/rest_api/apps.py
Roberto Rosario 61ebda6e63 REST API app updates
- Add back support for API views but using the
api_urlpatterns list. Needed for the current user
API until a dynamic route router is implemented that
can allow a viewset action to specify its entire URL.

- Make sure the user is authenticated before
trying to the user permissions.

- Improve how external_object_list options are read from
the class.

- None authenticated users will get a blank queryset if the
view doesn't require a permission.

Signed-off-by: Roberto Rosario <Roberto.Rosario@mayan-edms.com>
2019-02-07 20:13:35 -04:00

58 lines
1.7 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:
app_api_router_entries = import_string(
dotted_path='{}.urls.api_router_entries'.format(app.name)
)
except ImportError:
pass
else:
for entry in app_api_router_entries:
router.register(**entry)
try:
app_api_urlpatterns = import_string(
dotted_path='{}.urls.api_urlpatterns'.format(app.name)
)
except ImportError:
pass
else:
urlpatterns.extend(app_api_urlpatterns)
urlpatterns.extend(router.urls)