diff --git a/app/controllers/invitations_controller.rb b/app/controllers/invitations_controller.rb index b3be607c..8db5cfa5 100644 --- a/app/controllers/invitations_controller.rb +++ b/app/controllers/invitations_controller.rb @@ -47,10 +47,11 @@ class InvitationsController < ApplicationController body = invitation_params[:body] invitation_token = SecureRandom.hex(16) + invitation = Invitation.new(email: to, token_digest: Digest::SHA256.hexdigest(invitation_token)) subject = "[TEST] " + subject body_with_link = body.gsub('%link%', get_url_for(method(:new_user_registration_url), options: { invitation_token: invitation_token, email: to })) - InvitationMailer.invite(to: to, subject: subject, body: body_with_link).deliver_later + InvitationMailer.invite(invitation: invitation, subject: subject, body: body_with_link).deliver_now render json: {}, status: :ok end diff --git a/app/views/invitation_mailer/invite.html.erb b/app/views/invitation_mailer/invite.html.erb index 2f21cf84..75ba9df9 100644 --- a/app/views/invitation_mailer/invite.html.erb +++ b/app/views/invitation_mailer/invite.html.erb @@ -1 +1 @@ -<%= @body %> \ No newline at end of file +<%= simple_format(@body) %> \ No newline at end of file diff --git a/app/workflows/o_auth_sign_in_user_workflow.rb b/app/workflows/o_auth_sign_in_user_workflow.rb index 9e09a9de..fba537f5 100644 --- a/app/workflows/o_auth_sign_in_user_workflow.rb +++ b/app/workflows/o_auth_sign_in_user_workflow.rb @@ -40,15 +40,24 @@ class OAuthSignInUserWorkflow end full_name ||= I18n.t('defaults.user_full_name') - user = User.new( - email: email, - full_name: full_name, - password: Devise.friendly_token, - has_set_password: false, - status: 'active' - ) - user.skip_confirmation - user.save + ActiveRecord::Base.transaction do + user = User.new( + email: email, + full_name: full_name, + password: Devise.friendly_token, + has_set_password: false, + status: 'active' + ) + user.skip_confirmation + user.save + + # if there is a pending invitation for this email, mark it as accepted + invitation = Invitation.find_by(email: email) + if invitation && invitation.accepted_at.nil? + invitation.accepted_at = Time.now + invitation.save! + end + end end return user