Part One: Fix Users Stuck in a "Created" but "Unregistered" State (#10882)
* Alters the Invitations::Controller to work with registered users and onboarding - Adds #after_accept_path_for to Application::Controller for onboarding - Adds update! on the users registered status to the Invitations::Controller - Adds a respond_with in place of a redirt to Invitations::Controller - Adds a request spec testing invitation acceptance and registered status * specs: Cleans up invitations_spec.rb comments a little bit * fix: Adds comments back to the Invitations::Controller that previously existed prior to refactor * Adds back accidentally removed code from InvitationsController * Temporarily comments out invitations_spec with reference to issue in the code * Removes invitations_spec file in favor of spec file in another open PR
This commit is contained in:
parent
ef6c3838d4
commit
292b4143ce
2 changed files with 10 additions and 5 deletions
|
|
@ -103,6 +103,10 @@ class ApplicationController < ActionController::Base
|
|||
end
|
||||
end
|
||||
|
||||
def after_accept_path_for(_resource)
|
||||
onboarding_path
|
||||
end
|
||||
|
||||
def raise_suspended
|
||||
raise "SUSPENDED" if current_user&.banned
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,7 +1,9 @@
|
|||
class InvitationsController < Devise::InvitationsController
|
||||
# Copied from https://github.com/scambra/devise_invitable/blob/master/app/controllers/devise/invitations_controller.rb
|
||||
# And edited. This is a common devise pattern, similar to OmniauthCallbacksController.
|
||||
|
||||
# PUT /resource/invitation
|
||||
def update
|
||||
# Copied from https://github.com/scambra/devise_invitable/blob/master/app/controllers/devise/invitations_controller.rb
|
||||
# And edited. This is a common devise pattern, similar to OmniauthCallbacksController.
|
||||
raw_invitation_token = update_resource_params[:invitation_token]
|
||||
self.resource = accept_resource
|
||||
invitation_accepted = resource.errors.empty?
|
||||
|
|
@ -9,14 +11,13 @@ class InvitationsController < Devise::InvitationsController
|
|||
yield resource if block_given?
|
||||
|
||||
if invitation_accepted
|
||||
resource.registered = true
|
||||
resource.registered_at = Time.current
|
||||
resource.update!(registered_at: Time.current, registered: true)
|
||||
if resource.class.allow_insecure_sign_in_after_accept
|
||||
flash_message = resource.active_for_authentication? ? :updated : :updated_not_active
|
||||
set_flash_message :notice, flash_message if is_flashing_format?
|
||||
resource.after_database_authentication
|
||||
sign_in(resource_name, resource)
|
||||
redirect_to onboarding_path
|
||||
respond_with resource, location: after_accept_path_for(resource)
|
||||
else
|
||||
set_flash_message :notice, :updated_not_active if is_flashing_format?
|
||||
respond_with resource, location: new_session_path(resource_name)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue