Skip to content

Commit

Permalink
Update base path using force_script_name (#199)
Browse files Browse the repository at this point in the history
* update base_path using force_script_name

* fix black style, using url template
  • Loading branch information
odkhang authored Sep 17, 2024
1 parent a581363 commit 61c207a
Show file tree
Hide file tree
Showing 13 changed files with 42 additions and 39 deletions.
1 change: 1 addition & 0 deletions src/pretalx/common/context_processors.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ def system_information(request):

context["warning_update_available"] = False
context["warning_update_check_active"] = False
context["base_path"] = settings.BASE_PATH
if (
not request.user.is_anonymous
and request.user.is_administrator
Expand Down
8 changes: 5 additions & 3 deletions src/pretalx/common/middleware/domains.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,10 @@ def process_request(self, request):
request.port = int(port) if port else None
request.uses_custom_domain = False

resolved = resolve(request.path)
if resolved.url_name in ANY_DOMAIN_ALLOWED or request.path.startswith("/api/"):
resolved = resolve(request.path_info)
if resolved.url_name in ANY_DOMAIN_ALLOWED or request.path_info.startswith(
"/api/"
):
return None
event_slug = resolved.kwargs.get("event")
if event_slug:
Expand All @@ -76,7 +78,7 @@ def process_request(self, request):
if settings.DEBUG or domain in LOCAL_HOST_NAMES:
return None

if request.path.startswith("/orga"): # pragma: no cover
if request.path_info.startswith("/orga"): # pragma: no cover
if default_port not in (80, 443):
default_domain = f"{default_domain}:{default_port}"
return redirect(urljoin(default_domain, request.get_full_path()))
Expand Down
11 changes: 7 additions & 4 deletions src/pretalx/event/models/event.py
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,8 @@ class Event(PretalxModel):
objects = models.Manager()

class urls(EventUrls):
base = "/{self.slug}/"
base_path = settings.BASE_PATH
base = "{base_path}/{self.slug}/"
login = "{base}login/"
logout = "{base}logout"
auth = "{base}auth/"
Expand Down Expand Up @@ -349,8 +350,9 @@ class urls(EventUrls):
schedule_widget_script = "{base}widgets/schedule.js"

class orga_urls(EventUrls):
create = "/orga/event/new"
base = "/orga/event/{self.slug}/"
base_path = settings.BASE_PATH
create = "{base_path}/orga/event/new"
base = "{base_path}/orga/event/{self.slug}/"
login = "{base}login/"
live = "{base}live"
delete = "{base}delete"
Expand Down Expand Up @@ -402,7 +404,8 @@ class orga_urls(EventUrls):
new_information = "{base}info/new"

class api_urls(EventUrls):
base = "/api/events/{self.slug}/"
base_path = settings.BASE_PATH
base = "{base_path}/api/events/{self.slug}/"
submissions = "{base}submissions/"
talks = "{base}talks/"
schedules = "{base}schedules/"
Expand Down
4 changes: 3 additions & 1 deletion src/pretalx/event/models/organiser.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import json
import string

from django.conf import settings
from django.core.validators import RegexValidator
from django.db import models, transaction
from django.utils.crypto import get_random_string
Expand Down Expand Up @@ -48,7 +49,8 @@ def __str__(self) -> str:
return str(self.name)

class orga_urls(EventUrls):
base = "/orga/organiser/{self.slug}/"
base_path = settings.BASE_PATH
base = "{base_path}/orga/organiser/{self.slug}/"
delete = "{base}delete"
teams = "{base}teams/"
new_team = "{teams}new"
Expand Down
1 change: 1 addition & 0 deletions src/pretalx/orga/context_processors.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ def orga_events(request):
# rather than using the settings object directly in the template
site_config = dict(settings.CONFIG.items("site"))
context["site_config"] = site_config
context["base_path"] = settings.BASE_PATH

if not request.path.startswith("/orga/"):
return {}
Expand Down
18 changes: 3 additions & 15 deletions src/pretalx/orga/templates/orga/admin.html
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@ <h1>{% translate "Administrator information" %}</h1>

<p>
{% translate "Your pretalx version is:" %} <strong>{{ pretalx_version|copyable }}</strong>.
{% blocktranslate trimmed with url="/orga/admin/update/" %}
You can check for updates <a href="{{ url }}">here</a>.
{% url 'orga:admin.update' as update_url %}
{% blocktranslate trimmed %}
You can check for updates <a href="{{ update_url }}">here</a>.
{% endblocktranslate %}
</p>

Expand Down Expand Up @@ -97,17 +98,4 @@ <h3 class="mt-4">Celery</h3>
</ul>
{% endif %}

<h2 class="mt-4">{% translate "Links" %}</h2>
<ul>
<li><a target="_blank" rel="noopener" href="https://pretalx.com">{% translate "pretalx website" %}</a></li>
<li><a target="_blank" rel="noopener" href="https://docs.pretalx.org">{% translate "pretalx documentation" %}</a>
<ul>
<li><a target="_blank" rel="noopener" href="https://docs.pretalx.org/en/latest/administrator/configure.html">{% translate "Configuration reference" %}</a></li>
<li><a target="_blank" rel="noopener" href="https://docs.pretalx.org/en/latest/administrator/installation.html">{% translate "Installation guide" %}</a></li>
<li><a target="_blank" rel="noopener" href="https://docs.pretalx.org/en/latest/administrator/maintenance.html">{% translate "Upgrade/maintenance guide" %}</a></li>
</ul>
</li>
<li><a target="_blank" rel="noopener" href="https://docs.pretalx.org/en/latest/changelog.html">{% translate "Release notes" %}</a></li>
<li><a target="_blank" rel="noopener" href="https://pretalx.com/p/news">{% translate "pretalx blog (release announcements, features)" %}</a></li>
</ul>
{% endblock %}
8 changes: 4 additions & 4 deletions src/pretalx/orga/templates/orga/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
</a>
</li>
</ul>
<a class="navbar-brand d-none d-md-block" href="/orga/">
<a class="navbar-brand d-none d-md-block" href='{% url "orga:base" %}'>
<img loading="lazy" src="{% static "common/img/icons/icon.svg" %}" alt="{% translate "The {{ site_config.name }} logo" %}"> {{ site_config.name }}
</a>
<div class="navbar-collapse" id="navbartoggle">
Expand Down Expand Up @@ -392,20 +392,20 @@
{% endif %}
{% else %} {# if request.event #}
{% if request.orga_events|length > 1 %}
<a class="nav-link {% if request.path == "/orga/event/" %} active{% endif %}" href="/orga/">
<a class='nav-link {% if request.path == "/orga/event/" %} active{% endif %}' href='{% url "orga:base" %}'>
<i class="fa fa-calendar-o"></i>
<span>{% translate "Events" %}</span>
</a>
{% endif %}
{% has_perm 'orga.view_organisers' request.user request as can_see_organisers %}
{% if can_see_organisers %}
<a class="nav-link {% if "/orga/organiser/" in request.path %} active{% endif %}" href="/orga/organiser/">
<a class='nav-link {% if "/orga/organiser/" in request.path %} active{% endif %}' href='{% url "orga:organiser.list" %}'>
<i class="fa fa-users"></i>
<span>{% translate "Organisers" %}</span>
</a>
{% endif %}
{% if request.user.is_administrator %}
<a class="nav-link {% if "/orga/admin/" in request.path %} active{% endif %}" href="/orga/admin/">
<a class='nav-link {% if "/orga/admin/" in request.path %} active{% endif %}' href='{% url "orga:admin.dashboard" %}'>
<i class="fa fa-users"></i>
<span>{% translate "Admin information" %}</span>
</a>
Expand Down
2 changes: 1 addition & 1 deletion src/pretalx/orga/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
path("logout/", auth.logout_view, name="logout"),
path("reset/", auth.ResetView.as_view(), name="auth.reset"),
path("reset/<token>", auth.RecoverView.as_view(), name="auth.recover"),
path("", RedirectView.as_view(url="event", permanent=False)),
path("", RedirectView.as_view(url="event", permanent=False), name="base"),
path("admin/", admin.AdminDashboard.as_view(), name="admin.dashboard"),
path("admin/update/", admin.UpdateCheckView.as_view(), name="admin.update"),
path("me", event.UserSettings.as_view(), name="user.view"),
Expand Down
1 change: 1 addition & 0 deletions src/pretalx/orga/views/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
site_name = dict(settings.CONFIG.items("site")).get("name")
context["site_name"] = site_name
context["base_path"] = settings.BASE_PATH
return context

@context
Expand Down
6 changes: 3 additions & 3 deletions src/pretalx/orga/views/event.py
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,7 @@ def password_reset_link(self):
def post(self, *args, **kwargs):
if not self.request.user.is_anonymous:
self.accept_invite(self.request.user)
return redirect("/orga/event/")
return redirect(settings.BASE_PATH + "/orga/event/")
return super().post(*args, **kwargs)

def form_valid(self, form):
Expand All @@ -496,7 +496,7 @@ def form_valid(self, form):

self.accept_invite(user)
login(self.request, user, backend="django.contrib.auth.backends.ModelBackend")
return redirect("/orga/event/")
return redirect(settings.BASE_PATH + "/orga/event/")

@transaction.atomic()
def accept_invite(self, user):
Expand Down Expand Up @@ -735,7 +735,7 @@ def action_back_url(self):

def post(self, request, *args, **kwargs):
self.get_object().shred(person=self.request.user)
return redirect("/orga/")
return redirect(settings.BASE_PATH + "/orga/")


@method_decorator(csp_update(SCRIPT_SRC="'self' 'unsafe-eval'"), name="dispatch")
Expand Down
4 changes: 3 additions & 1 deletion src/pretalx/orga/views/organiser.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import logging

from allauth.socialaccount.models import SocialApp
from django.conf import settings
from django.contrib import messages
from django.http import HttpResponseRedirect
from django.shortcuts import get_object_or_404, redirect
Expand Down Expand Up @@ -359,4 +360,5 @@ def action_back_url(self):
def post(self, *args, **kwargs):
organiser = self.get_object()
organiser.shred()
return HttpResponseRedirect("/orga/")
base_path = settings.BASE_PATH
return HttpResponseRedirect(base_path + "/orga/")
4 changes: 3 additions & 1 deletion src/pretalx/orga/views/typeahead.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import json
from contextlib import suppress

from django.conf import settings
from django.db.models import Exists, OuterRef, Q
from django.http import JsonResponse
from django.utils.translation import ngettext_lazy as _n
Expand All @@ -12,10 +13,11 @@


def serialize_user(user):
base_path = settings.BASE_PATH
return {
"type": "user",
"name": str(user),
"url": "/orga/me",
"url": base_path + "/orga/me",
}


Expand Down
13 changes: 7 additions & 6 deletions src/pretalx/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,10 +125,11 @@
ALLOWED_HOSTS = [
"*"
] # We have our own security middleware to allow for custom event URLs

ROOT_URLCONF = "pretalx.urls"
STATIC_URL = config.get("site", "static")
MEDIA_URL = config.get("site", "media")
BASE_PATH = config.get("site", "base_path", fallback="")
FORCE_SCRIPT_NAME = BASE_PATH
STATIC_URL = config.get("site", "static", fallback=BASE_PATH + "/static/")
MEDIA_URL = config.get("site", "media", fallback=BASE_PATH + "/media/")
FILE_UPLOAD_DIRECTORY_PERMISSIONS = 0o755
FILE_UPLOAD_DEFAULT_LIMIT = 10 * 1024 * 1024
IMAGE_DEFAULT_MAX_WIDTH = 1920
Expand Down Expand Up @@ -493,7 +494,7 @@ def merge_csp(*options, config=None):

## AUTHENTICATION SETTINGS
AUTH_USER_MODEL = "person.User"
LOGIN_URL = "/orga/login"
LOGIN_URL = BASE_PATH + "/orga/login"
AUTHENTICATION_BACKENDS = (
"rules.permissions.ObjectPermissionBackend",
"django.contrib.auth.backends.ModelBackend",
Expand Down Expand Up @@ -688,7 +689,7 @@ def merge_csp(*options, config=None):
# Below is configuration for SSO using eventyay-ticket

EVENTYAY_TICKET_BASE_PATH = config.get(
"urls", "eventyay-ticket", fallback="https://tickets-dev.eventyay.com"
"urls", "eventyay-ticket", fallback="https://app-test.eventyay.com/tickets"
)

SITE_ID = 1
Expand All @@ -697,7 +698,7 @@ def merge_csp(*options, config=None):
# will take name from eventyay-ticket as username
ACCOUNT_USER_MODEL_USERNAME_FIELD = "name"
# redirect to home page after login with eventyay-ticket
LOGIN_REDIRECT_URL = "/"
LOGIN_REDIRECT_URL = BASE_PATH
# custom form for signup and adapter
SOCIALACCOUNT_FORMS = {"signup": "pretalx.sso_provider.forms.CustomSignUpForm"}
SOCIALACCOUNT_ADAPTER = "pretalx.sso_provider.views.CustomSocialAccountAdapter"
Expand Down

0 comments on commit 61c207a

Please sign in to comment.