✨(backend) add public endpoint /api/v1.0/config/
Add public endpoint /api/v1.0/config/ to share some public configuration values.
This commit is contained in:
@@ -13,6 +13,7 @@ and this project adheres to
|
|||||||
|
|
||||||
- 🌐(frontend) Add German translation #255
|
- 🌐(frontend) Add German translation #255
|
||||||
- ✨(frontend) Add a broadcast store #387
|
- ✨(frontend) Add a broadcast store #387
|
||||||
|
- ✨(backend) config endpoint #425
|
||||||
|
|
||||||
|
|
||||||
## Changed
|
## Changed
|
||||||
|
|||||||
@@ -26,11 +26,13 @@ from rest_framework import (
|
|||||||
mixins,
|
mixins,
|
||||||
pagination,
|
pagination,
|
||||||
status,
|
status,
|
||||||
|
views,
|
||||||
viewsets,
|
viewsets,
|
||||||
)
|
)
|
||||||
from rest_framework import (
|
from rest_framework import (
|
||||||
response as drf_response,
|
response as drf_response,
|
||||||
)
|
)
|
||||||
|
from rest_framework.permissions import AllowAny
|
||||||
|
|
||||||
from core import enums, models
|
from core import enums, models
|
||||||
from core.services.ai_services import AIService
|
from core.services.ai_services import AIService
|
||||||
@@ -886,3 +888,27 @@ class InvitationViewset(
|
|||||||
invitation.document.email_invitation(
|
invitation.document.email_invitation(
|
||||||
language, invitation.email, invitation.role, self.request.user
|
language, invitation.email, invitation.role, self.request.user
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
class ConfigView(views.APIView):
|
||||||
|
"""API ViewSet for sharing some public settings."""
|
||||||
|
|
||||||
|
permission_classes = [AllowAny]
|
||||||
|
|
||||||
|
def get(self, request):
|
||||||
|
"""
|
||||||
|
GET /api/v1.0/config/
|
||||||
|
Return a dictionary of public settings.
|
||||||
|
"""
|
||||||
|
array_settings = [
|
||||||
|
"ENVIRONMENT",
|
||||||
|
"LANGUAGES",
|
||||||
|
"LANGUAGE_CODE",
|
||||||
|
"SENTRY_DSN",
|
||||||
|
]
|
||||||
|
dict_settings = {}
|
||||||
|
for setting in array_settings:
|
||||||
|
if hasattr(settings, setting):
|
||||||
|
dict_settings[setting] = getattr(settings, setting)
|
||||||
|
|
||||||
|
return drf_response.Response(dict_settings)
|
||||||
|
|||||||
47
src/backend/core/tests/test_api_config.py
Normal file
47
src/backend/core/tests/test_api_config.py
Normal file
@@ -0,0 +1,47 @@
|
|||||||
|
"""
|
||||||
|
Test config API endpoints in the Impress core app.
|
||||||
|
"""
|
||||||
|
|
||||||
|
from django.test import override_settings
|
||||||
|
|
||||||
|
import pytest
|
||||||
|
from rest_framework.status import (
|
||||||
|
HTTP_200_OK,
|
||||||
|
)
|
||||||
|
from rest_framework.test import APIClient
|
||||||
|
|
||||||
|
from core import factories
|
||||||
|
|
||||||
|
pytestmark = pytest.mark.django_db
|
||||||
|
|
||||||
|
|
||||||
|
@override_settings(SENTRY_DSN="https://sentry.test/123")
|
||||||
|
def test_api_config_anonymous():
|
||||||
|
"""Anonymous users should be allowed to get the configuration."""
|
||||||
|
client = APIClient()
|
||||||
|
response = client.get("/api/v1.0/config/")
|
||||||
|
assert response.status_code == HTTP_200_OK
|
||||||
|
assert response.json() == {
|
||||||
|
"LANGUAGES": [["en-us", "English"], ["fr-fr", "French"], ["de-de", "German"]],
|
||||||
|
"LANGUAGE_CODE": "en-us",
|
||||||
|
"SENTRY_DSN": "https://sentry.test/123",
|
||||||
|
"ENVIRONMENT": "test",
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@override_settings(SENTRY_DSN="https://sentry.test/123")
|
||||||
|
def test_api_config_authenticated():
|
||||||
|
"""Authenticated users should be allowed to get the configuration."""
|
||||||
|
user = factories.UserFactory()
|
||||||
|
|
||||||
|
client = APIClient()
|
||||||
|
client.force_login(user)
|
||||||
|
|
||||||
|
response = client.get("/api/v1.0/config/")
|
||||||
|
assert response.status_code == HTTP_200_OK
|
||||||
|
assert response.json() == {
|
||||||
|
"LANGUAGES": [["en-us", "English"], ["fr-fr", "French"], ["de-de", "German"]],
|
||||||
|
"LANGUAGE_CODE": "en-us",
|
||||||
|
"SENTRY_DSN": "https://sentry.test/123",
|
||||||
|
"ENVIRONMENT": "test",
|
||||||
|
}
|
||||||
@@ -55,4 +55,5 @@ urlpatterns = [
|
|||||||
]
|
]
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
path(f"api/{settings.API_VERSION}/config/", viewsets.ConfigView.as_view()),
|
||||||
]
|
]
|
||||||
|
|||||||
@@ -56,7 +56,7 @@ class Base(Configuration):
|
|||||||
You may also want to override default configuration by setting the following environment
|
You may also want to override default configuration by setting the following environment
|
||||||
variables:
|
variables:
|
||||||
|
|
||||||
* DJANGO_SENTRY_DSN
|
* SENTRY_DSN
|
||||||
* DB_NAME
|
* DB_NAME
|
||||||
* DB_HOST
|
* DB_HOST
|
||||||
* DB_PASSWORD
|
* DB_PASSWORD
|
||||||
@@ -372,7 +372,7 @@ class Base(Configuration):
|
|||||||
CORS_ALLOWED_ORIGIN_REGEXES = values.ListValue([])
|
CORS_ALLOWED_ORIGIN_REGEXES = values.ListValue([])
|
||||||
|
|
||||||
# Sentry
|
# Sentry
|
||||||
SENTRY_DSN = values.Value(None, environ_name="SENTRY_DSN")
|
SENTRY_DSN = values.Value(None, environ_name="SENTRY_DSN", environ_prefix=None)
|
||||||
|
|
||||||
# Easy thumbnails
|
# Easy thumbnails
|
||||||
THUMBNAIL_EXTENSION = "webp"
|
THUMBNAIL_EXTENSION = "webp"
|
||||||
|
|||||||
Reference in New Issue
Block a user