Skip to content

Commit

Permalink
AdventureLog Smart Recommendations
Browse files Browse the repository at this point in the history
  • Loading branch information
seanmorley15 authored Jan 18, 2025
2 parents fcec4a4 + 1a7643b commit 8f6e655
Show file tree
Hide file tree
Showing 57 changed files with 2,177 additions and 1,431 deletions.
26 changes: 4 additions & 22 deletions backend/server/adventures/permissions.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ class IsOwnerOrSharedWithFullAccess(permissions.BasePermission):
"""

def has_object_permission(self, request, view, obj):

# Allow GET only for a public object
if request.method in permissions.SAFE_METHODS and obj.is_public:
return True
# Check if the object has a collection
if hasattr(obj, 'collection') and obj.collection:
# Allow all actions for shared users
Expand All @@ -71,27 +75,5 @@ def has_object_permission(self, request, view, obj):
if request.method in permissions.SAFE_METHODS:
return True

# Allow all actions for the owner
return obj.user_id == request.user

class IsPublicOrOwnerOrSharedWithFullAccess(permissions.BasePermission):
"""
Custom permission to allow:
- Read-only access for public objects
- Full access for shared users
- Full access for owners
"""

def has_object_permission(self, request, view, obj):
# Allow read-only access for public objects
if obj.is_public and request.method in permissions.SAFE_METHODS:
return True

# Check if the object has a collection
if hasattr(obj, 'collection') and obj.collection:
# Allow all actions for shared users
if request.user in obj.collection.shared_with.all():
return True

# Allow all actions for the owner
return obj.user_id == request.user
3 changes: 2 additions & 1 deletion backend/server/adventures/urls.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from django.urls import include, path
from rest_framework.routers import DefaultRouter
from .views import AdventureViewSet, ChecklistViewSet, CollectionViewSet, NoteViewSet, StatsViewSet, GenerateDescription, ActivityTypesView, TransportationViewSet, AdventureImageViewSet, ReverseGeocodeViewSet, CategoryViewSet, IcsCalendarGeneratorViewSet
from adventures.views import *

router = DefaultRouter()
router.register(r'adventures', AdventureViewSet, basename='adventures')
Expand All @@ -15,6 +15,7 @@
router.register(r'reverse-geocode', ReverseGeocodeViewSet, basename='reverse-geocode')
router.register(r'categories', CategoryViewSet, basename='categories')
router.register(r'ics-calendar', IcsCalendarGeneratorViewSet, basename='ics-calendar')
router.register(r'overpass', OverpassViewSet, basename='overpass')


urlpatterns = [
Expand Down
6 changes: 6 additions & 0 deletions backend/server/adventures/utils/pagination.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from rest_framework.pagination import PageNumberPagination

class StandardResultsSetPagination(PageNumberPagination):
page_size = 25
page_size_query_param = 'page_size'
max_page_size = 1000
Loading

0 comments on commit 8f6e655

Please sign in to comment.