File tree Expand file tree Collapse file tree 2 files changed +34
-7
lines changed
app/controllers/better_together Expand file tree Collapse file tree 2 files changed +34
-7
lines changed Original file line number Diff line number Diff line change @@ -126,6 +126,37 @@ def find_invitation_by_token
126126 )
127127 end
128128
129+ # Process event invitation tokens before inherited (ApplicationController) callbacks
130+ # so we can bypass platform privacy checks for valid event invitations and
131+ # return 404 for invalid tokens when the platform is private.
132+ # prepend_before_action :process_event_invitation_for_privacy, only: %i[show]
133+
134+ # Override privacy check to handle event-specific invitation tokens.
135+ # This keeps event lookup logic inside the events controller and avoids
136+ # embedding event knowledge in ApplicationController.
137+ def check_platform_privacy
138+ # If host platform is public or user is signed in, let ApplicationController handle it
139+ return super if helpers . host_platform . privacy_public? || current_user . present?
140+
141+ token = params [ :invitation_token ] . presence || params [ :token ] . presence
142+ if token . present? && params [ :id ] . present?
143+ invitation = ::BetterTogether ::EventInvitation . pending . not_expired . find_by ( token : token )
144+ if invitation
145+ # Valid invitation: set locale and allow access
146+ I18n . locale = invitation . locale if invitation . locale . present?
147+ session [ :locale ] = I18n . locale
148+ return true
149+ else
150+ # Invalid token for this event on a private platform: render 404
151+ render_not_found
152+ return
153+ end
154+ end
155+
156+ # Fall back to ApplicationController implementation for other cases
157+ super
158+ end
159+
129160 private
130161
131162 # rubocop:todo Metrics/MethodLength
Original file line number Diff line number Diff line change 33module BetterTogether
44 class InvitationsController < ApplicationController # rubocop:todo Style/Documentation
55 # skip_before_action :authenticate_user!
6- before_action :find_invitation_by_token
6+ prepend_before_action :find_invitation_by_token
7+ skip_before_action :check_platform_privacy , if : -> { @invitation . present? }
78
89 def show
910 @event = @invitation . invitable if @invitation . is_a? ( BetterTogether ::EventInvitation )
@@ -55,7 +56,7 @@ def decline # rubocop:todo Metrics/MethodLength
5556 private
5657
5758 def find_invitation_by_token
58- token = params [ :token ] . to_s
59+ token = params [ :invitation_token ] . presence || params [ : token] . presence
5960 @invitation = BetterTogether ::Invitation . pending . not_expired . find_by ( token : token )
6061 render_not_found unless @invitation
6162 end
@@ -81,10 +82,5 @@ def ensure_authenticated!
8182
8283 redirect_to redirect_path , notice : redirect_notice
8384 end
84-
85- def set_event_invitation_from_session
86- # This ensures @event_invitation is available in ApplicationController
87- @event_invitation = @invitation if @invitation . is_a? ( BetterTogether ::EventInvitation )
88- end
8985 end
9086end
You can’t perform that action at this time.
0 commit comments