Skip to content

Commit ed76c14

Browse files
authored
Open Locations in Maps and new API Routes
2 parents 3e0639e + a16df16 commit ed76c14

File tree

31 files changed

+105
-222
lines changed

31 files changed

+105
-222
lines changed
Lines changed: 13 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,6 @@
1-
class AppVersionMiddleware:
2-
def __init__(self, get_response):
3-
self.get_response = get_response
4-
5-
def __call__(self, request):
6-
# Process request (if needed)
7-
response = self.get_response(request)
8-
9-
# Add custom header to response
10-
# Replace with your app version
11-
response['X-AdventureLog-Version'] = '1.0.0'
12-
13-
return response
14-
15-
# make a middlewra that prints all of the request cookies
16-
class PrintCookiesMiddleware:
17-
def __init__(self, get_response):
18-
self.get_response = get_response
19-
20-
def __call__(self, request):
21-
print(request.COOKIES)
22-
response = self.get_response(request)
23-
return response
24-
25-
# middlewares.py
26-
1+
from django.conf import settings
2+
from django.utils.deprecation import MiddlewareMixin
273
import os
28-
from django.http import HttpRequest
294

305
class OverrideHostMiddleware:
316
def __init__(self, get_response):
@@ -44,3 +19,14 @@ def __call__(self, request):
4419

4520
response = self.get_response(request)
4621
return response
22+
23+
class XSessionTokenMiddleware(MiddlewareMixin):
24+
def process_request(self, request):
25+
session_token = request.headers.get('X-Session-Token')
26+
if session_token:
27+
request.COOKIES[settings.SESSION_COOKIE_NAME] = session_token
28+
29+
class DisableCSRFForSessionTokenMiddleware(MiddlewareMixin):
30+
def process_request(self, request):
31+
if 'X-Session-Token' in request.headers:
32+
setattr(request, '_dont_enforce_csrf_checks', True)

backend/server/adventures/views/adventure_view.py

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -133,35 +133,6 @@ def all(self, request):
133133
serializer = self.get_serializer(queryset, many=True)
134134
return Response(serializer.data)
135135

136-
@action(detail=False, methods=['get'])
137-
def search(self, request):
138-
query = request.query_params.get('query', '')
139-
property = request.query_params.get('property', 'all')
140-
141-
if len(query) < 2:
142-
return Response({"error": "Query must be at least 2 characters long"}, status=400)
143-
144-
valid_properties = ['name', 'location', 'description', 'activity_types']
145-
if property not in valid_properties:
146-
property = 'all'
147-
148-
filters = {
149-
'name': Q(name__icontains=query),
150-
'location': Q(location__icontains=query),
151-
'description': Q(description__icontains=query),
152-
'activity_types': Q(activity_types__icontains=query),
153-
'all': Q(name__icontains=query) | Q(description__icontains=query) |
154-
Q(location__icontains=query) | Q(activity_types__icontains=query)
155-
}
156-
157-
queryset = Adventure.objects.filter(
158-
filters[property] & (Q(user_id=request.user.id) | Q(is_public=True))
159-
)
160-
161-
queryset = self.apply_sorting(queryset)
162-
serializer = self.get_serializer(queryset, many=True)
163-
return Response(serializer.data)
164-
165136
def update(self, request, *args, **kwargs):
166137
instance = self.get_object()
167138
serializer = self.get_serializer(instance, data=request.data, partial=True)

backend/server/adventures/views/stats_view.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,13 @@ class StatsViewSet(viewsets.ViewSet):
1414
"""
1515
A simple ViewSet for listing the stats of a user.
1616
"""
17-
@action(detail=False, methods=['get'], url_path='counts/(?P<username>[^/]+)')
17+
@action(detail=False, methods=['get'], url_path='counts/(?P<username>[\w.@+-]+)')
1818
def counts(self, request, username):
1919
if request.user.username == username:
2020
user = get_object_or_404(User, username=username)
2121
else:
2222
user = get_object_or_404(User, username=username, public_profile=True)
23-
serializer = PublicUserSerializer(user)
23+
# serializer = PublicUserSerializer(user)
2424

2525
# remove the email address from the response
2626
user.email = None

backend/server/main/settings.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@
6969

7070
MIDDLEWARE = (
7171
'whitenoise.middleware.WhiteNoiseMiddleware',
72+
'adventures.middleware.XSessionTokenMiddleware',
73+
'adventures.middleware.DisableCSRFForSessionTokenMiddleware',
7274
'corsheaders.middleware.CorsMiddleware',
7375
'django.contrib.sessions.middleware.SessionMiddleware',
7476
'django.middleware.common.CommonMiddleware',
@@ -133,6 +135,8 @@
133135

134136
SESSION_COOKIE_SAMESITE = 'Lax'
135137

138+
SESSION_COOKIE_NAME = 'sessionid'
139+
136140
SESSION_COOKIE_SECURE = FRONTEND_URL.startswith('https')
137141

138142
hostname = urlparse(FRONTEND_URL).hostname

backend/server/main/urls.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
urlpatterns = [
1616
path('api/', include('adventures.urls')),
1717
path('api/', include('worldtravel.urls')),
18-
path("_allauth/", include("allauth.headless.urls")),
18+
path("auth/", include("allauth.headless.urls")),
1919

2020
# Serve protected media files
2121
re_path(r'^media/(?P<path>.*)$', serve_protected_media, name='serve-protected-media'),

backend/server/users/tests.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ class UserAPITestCase(APITestCase):
88

99
def setUp(self):
1010
# Signup a new user
11-
response = self.client.post('/_allauth/browser/v1/auth/signup', {
11+
response = self.client.post('/auth/browser/v1/auth/signup', {
1212
'username': 'testuser',
1313
'email': 'testuser@example.com',
1414
'password': 'testpassword',
@@ -63,7 +63,7 @@ def test_002_user_update(self):
6363

6464
def test_003_user_add_email(self):
6565
# Update user email
66-
response = self.client.post('/_allauth/browser/v1/account/email', {
66+
response = self.client.post('/auth/browser/v1/account/email', {
6767
'email': 'testuser2@example.com',
6868
}, format='json')
6969
self.assertEqual(response.status_code, 200)

frontend/src/lib/components/LocationDropdown.svelte

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,9 @@
4949
reverseGeocode();
5050
}
5151
52-
if (!item.name) {
53-
item.name = markers[0].name;
54-
}
52+
// if (!item.name) {
53+
// item.name = markers[0].name;
54+
// }
5555
}
5656
5757
$: if (triggerMarkVisted && willBeMarkedVisited) {
@@ -193,7 +193,7 @@
193193
) {
194194
old_display_name = reverseGeocodePlace.display_name;
195195
item.location = reverseGeocodePlace.display_name;
196-
if (reverseGeocodePlace.location_name) {
196+
if (reverseGeocodePlace.location_name && !item.name) {
197197
item.name = reverseGeocodePlace.location_name;
198198
}
199199
}
@@ -270,6 +270,8 @@
270270
activity_type: place.type
271271
}
272272
];
273+
274+
item.name = place.name;
273275
}}
274276
>
275277
{place.display_name}

frontend/src/lib/components/TOTPModal.svelte

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
}
3838
3939
async function fetchSetupInfo() {
40-
const res = await fetch('/_allauth/browser/v1/account/authenticators/totp', {
40+
const res = await fetch('/auth/browser/v1/account/authenticators/totp', {
4141
method: 'GET'
4242
});
4343
const data = await res.json();
@@ -53,7 +53,7 @@
5353
}
5454
5555
async function sendTotp() {
56-
const res = await fetch('/_allauth/browser/v1/account/authenticators/totp', {
56+
const res = await fetch('/auth/browser/v1/account/authenticators/totp', {
5757
method: 'POST',
5858
headers: {
5959
'Content-Type': 'application/json'
@@ -78,7 +78,7 @@
7878
7979
async function getRecoveryCodes() {
8080
console.log('getting recovery codes');
81-
const res = await fetch('/_allauth/browser/v1/account/authenticators/recovery-codes', {
81+
const res = await fetch('/auth/browser/v1/account/authenticators/recovery-codes', {
8282
method: 'GET'
8383
});
8484
if (res.ok) {

frontend/src/locales/de.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,8 @@
246246
"lodging_information": "Unterkunftsinformationen",
247247
"price": "Preis",
248248
"reservation_number": "Reservierungsnummer",
249-
"welcome_map_info": "Öffentliche Abenteuer auf diesem Server"
249+
"welcome_map_info": "Öffentliche Abenteuer auf diesem Server",
250+
"open_in_maps": "In Karten geöffnet"
250251
},
251252
"home": {
252253
"desc_1": "Entdecken, planen und erkunden Sie mit Leichtigkeit",

frontend/src/locales/en.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@
113113
"copy_link": "Copy Link",
114114
"image": "Image",
115115
"upload_image": "Upload Image",
116+
"open_in_maps": "Open in Maps",
116117
"url": "URL",
117118
"fetch_image": "Fetch Image",
118119
"wikipedia": "Wikipedia",

0 commit comments

Comments
 (0)