Commit 91acde6b authored by Mickaël Desfrênes's avatar Mickaël Desfrênes
Browse files

Add env var JAMA_URL_BASE_PATH

JAMA_URL_BASE_PATH will be prepended to all URLs.
parent d6fdab4b
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -16,7 +16,7 @@ import os
DEFAULT_AUTO_FIELD = "django.db.models.AutoField"
# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent

JAMA_URL_BASE_PATH = os.getenv("JAMA_URL_BASE_PATH") or ""
PARTIAL_UPLOADS_DIR = os.getenv("JAMA_PARTIAL_UPLOADS_DIR") or "{}/{}".format(
    BASE_DIR, "partial_uploads"
)
+13 −11
Original line number Diff line number Diff line
@@ -15,19 +15,21 @@ Including another URLconf
"""
from django.contrib import admin
from django.urls import path, include

from mediatheque import settings
from . import views


urlpatterns = [
    path("", views.homepage),
    path("signin/", views.signin),
    path("signout/", views.signout),
    path("sso/", views.sso),
    path("ui/", views.ui),
    path("resources/", include("resources.urls")),
    path("rpc/", include("rpc.urls")),
    path("admin/", admin.site.urls),
    path("accounts/", include("django.contrib.auth.urls")),
    path("oai/", include("oai.urls")),
    path(settings.JAMA_URL_BASE_PATH + "", views.homepage),
    path(settings.JAMA_URL_BASE_PATH + "signin/", views.signin),
    path(settings.JAMA_URL_BASE_PATH + "signout/", views.signout),
    path(settings.JAMA_URL_BASE_PATH + "sso/", views.sso),
    path(settings.JAMA_URL_BASE_PATH + "ui/", views.ui),
    path(settings.JAMA_URL_BASE_PATH + "resources/", include("resources.urls")),
    path(settings.JAMA_URL_BASE_PATH + "rpc/", include("rpc.urls")),
    path(settings.JAMA_URL_BASE_PATH + "admin/", admin.site.urls),
    path(
        settings.JAMA_URL_BASE_PATH + "accounts/", include("django.contrib.auth.urls")
    ),
    path(settings.JAMA_URL_BASE_PATH + "oai/", include("oai.urls")),
]
+12 −9
Original line number Diff line number Diff line
@@ -2,37 +2,40 @@ from django.http import HttpResponse, HttpRequest, HttpResponseRedirect
from django.shortcuts import render
from django.contrib.auth.models import User
from django.contrib.auth import login, logout
from mediatheque import settings

BASE_PATH = "/" + settings.JAMA_URL_BASE_PATH


def ui(request: HttpRequest) -> HttpResponse:
    if request.user.is_authenticated:
        return render(request, "ui.html")
        return render(request, "ui.html", {"BASE_PATH": BASE_PATH})
    else:
        return HttpResponseRedirect("/signin/")
        return HttpResponseRedirect(BASE_PATH + "signin/")


def homepage(request: HttpRequest) -> HttpResponse:
    return render(request, "homepage.html")
    return render(request, "homepage.html", {"BASE_PATH": BASE_PATH})


def signin(request: HttpRequest) -> HttpResponse:
    return render(request, "signin.html")
    return render(request, "signin.html", {"BASE_PATH": BASE_PATH})


def signout(request: HttpRequest) -> HttpResponse:
    logout(request)
    return HttpResponseRedirect("/")
    return HttpResponseRedirect(BASE_PATH)


def sso(request: HttpRequest) -> HttpResponse:
    if request.user.is_authenticated:
        return HttpResponseRedirect("/ui/")
        return HttpResponseRedirect(BASE_PATH + "ui/")
    eppn = request.META.get("HTTP_EPPN", None)
    if not eppn:
        return render(request, "sso_fail.html")
        return render(request, "sso_fail.html", {"BASE_PATH": BASE_PATH})
    try:
        user = User.objects.get(username=eppn.strip())
        login(request, user)
        return HttpResponseRedirect("/ui/")
        return HttpResponseRedirect(BASE_PATH + "ui/")
    except User.DoesNotExist:
        return render(request, "login_failure.html")
        return render(request, "login_failure.html", {"BASE_PATH": BASE_PATH})
+3 −3
Original line number Diff line number Diff line
@@ -10,16 +10,16 @@
        Jama est développé par le <a href="https://www.certic.unicaen.fr/">CERTIC</a>.
    </p>
    <p>
        Une <a href="/rpc/">API</a> <a href="https://www.jsonrpc.org/specification_v1">JSON-RPC 1.0</a> est disponible
        Une <a href="{{ BASE_PATH }}rpc/">API</a> <a href="https://www.jsonrpc.org/specification_v1">JSON-RPC 1.0</a> est disponible
        ainsi qu'une interface graphique sous forme de
        <a href="https://git.unicaen.fr/chauveau/vue-jama">composant Vue</a>.
    </p>
    <ul>
        <li>
            <a href="/rpc/">RPC documentation</a>
            <a href="{{ BASE_PATH }}rpc/">RPC documentation</a>
        </li>
        <li>
            <a href="/ui/">Web UI</a>
            <a href="{{ BASE_PATH }}ui/">Web UI</a>
        </li>
    </ul>
{% endblock %}
 No newline at end of file
+1 −1
Original line number Diff line number Diff line
@@ -4,5 +4,5 @@
{% endblock %}
{% block content %}
    <h1>Jama Login Failure</h1>
    <p>You don't have access to this application. You can go back to the <a href="/">homepage</a>.</p>
    <p>You don't have access to this application. You can go back to the <a href="{{ BASE_PATH }}/">homepage</a>.</p>
{% endblock %}
 No newline at end of file
Loading