Skip to content

Commit

Permalink
feat(account invitation): some changes
Browse files Browse the repository at this point in the history
  • Loading branch information
andreybakanovsky committed Aug 25, 2023
1 parent 2889cbc commit 6c0e14a
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 11 deletions.
11 changes: 4 additions & 7 deletions app/controllers/accept_account_invitations_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,20 @@

class AcceptAccountInvitationsController < ApplicationController
def show
return if user_signed_in? && the_invitation
return if user_signed_in?

session[:token] = ps[:token]
redirect_to new_user_session_url(email: the_invitation.email)
session[:after_sign_in_url] = request.fullpath
redirect_to new_user_session_url(email: AccountInvitation.find_by!(token: ps.fetch(:token)).email)
end

def update
received_invitation.update!(accepted_at: Time.current)
redirect_to account_path(received_invitation.account_id)
end

private

helper_method memoize def received_invitation
AccountInvitation.unaccepted.for(current_user).find_by!(token: ps.fetch(:token))
end

memoize def the_invitation
AccountInvitation.find_by!(token: ps.fetch(:token))
end
end
6 changes: 3 additions & 3 deletions app/controllers/users/sessions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ def new
end
end

protected
private

def after_sign_in_path_for(_resource)
if (token = session.delete(:token)).present?
return accept_account_invitation_path(token: token)
if (after_sign_in_url = session.delete(:after_sign_in_url)).present?
return after_sign_in_url
end

super
Expand Down
3 changes: 2 additions & 1 deletion spec/controllers/accept_account_invitations_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
subject
expect(AccountInvitation.find(account_invitation.id).accepted_at).not_to be_nil
end
it { is_expected.to have_http_status(204) }
it { is_expected.to have_http_status(302) }
it { is_expected.to redirect_to(account_path(account_invitation.account_id)) }
end
end

0 comments on commit 6c0e14a

Please sign in to comment.