@@ -26,7 +26,7 @@ class ApplicationController < ActionController::Base # rubocop:todo Metrics/Clas
2626 rescue_from Pundit ::NotAuthorizedError , with : :user_not_authorized
2727 rescue_from StandardError , with : :handle_error
2828
29- helper_method :default_url_options , :valid_platform_invitation_token_present?
29+ helper_method :current_invitation , : default_url_options, :valid_platform_invitation_token_present?
3030
3131 def self . default_url_options
3232 super . merge ( locale : I18n . locale )
@@ -72,29 +72,33 @@ def set_platform_invitation # rubocop:todo Metrics/CyclomaticComplexity, Metrics
7272 return
7373 end
7474
75- if params [ :invitation_code ] . present?
76- # On first visit with the invitation code, update the session with the token and a new expiry.
77- token = params [ :invitation_code ]
78- session [ :platform_invitation_token ] = token
79- session [ :platform_invitation_expires_at ] ||= Time . current + platform_invitation_expiry_time
80- else
81- # If no params, simply use the token stored in the session.
82- token = session [ :platform_invitation_token ]
83- end
75+ token = if params [ :invitation_code ] . present?
76+ # On first visit with the invitation code, update the session with the token and a new expiry.
77+ session [ :platform_invitation_token ] = params [ :invitation_code ]
78+ else
79+ # If no params, simply use the token stored in the session.
80+ session [ :platform_invitation_token ]
81+ end
8482
8583 return unless token . present?
8684
8785 @platform_invitation = ::BetterTogether ::PlatformInvitation . pending . find_by ( token : token )
8886
89- return if @platform_invitation
90-
91- session . delete ( :platform_invitation_token )
92- session . delete ( :platform_invitation_expires_at )
87+ if @platform_invitation
88+ session [ :platform_invitation_expires_at ] ||= Time . current + @platform_invitation . session_duration_mins . minutes
89+ else
90+ session . delete ( :platform_invitation_token )
91+ session . delete ( :platform_invitation_expires_at )
92+ end
9393 end
9494 # rubocop:enable Metrics/AbcSize
9595 # rubocop:enable Metrics/MethodLength
9696 # rubocop:enable Metrics/PerceivedComplexity
9797
98+ def current_invitation
99+ @platform_invitation
100+ end
101+
98102 def check_platform_privacy
99103 return if helpers . host_platform . privacy_public?
100104 return if current_user
0 commit comments