Skip to content

Commit

Permalink
fix: improve redirect to login logic for anonymous users accessing po…
Browse files Browse the repository at this point in the history
…rtal urls
  • Loading branch information
adrianmcphee committed Nov 17, 2024
1 parent da8dcab commit ce3579e
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion apps/portal/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,18 @@

class PortalBaseView(LoginRequiredMixin, TemplateView):
"""Base view for portal pages."""
login_url = 'sign_in'
def get_login_url(self):
return reverse('security:sign_in')

portal_service = PortalService()
role_service = RoleService()

def get_current_organisation(self, request):
"""Get the current organisation from session or default to first available."""
# Add safety check for anonymous users
if not request.user.is_authenticated:
return None

current_org_id = request.session.get('current_organisation_id')
person = request.user.person

Expand All @@ -79,6 +85,10 @@ def get_current_organisation(self, request):

def dispatch(self, request, *args, **kwargs):
"""Common permission checking and org context setting."""
# Add safety check for anonymous users
if not request.user.is_authenticated:
return redirect(self.get_login_url())

try:
# Set current_organisation as an instance variable
self.current_organisation = self.get_current_organisation(request)
Expand Down

0 comments on commit ce3579e

Please sign in to comment.