Multiple fixes and improvements in invitations system (#402)

This commit is contained in:
Riccardo Graziosi
2024-09-07 12:29:01 +02:00
committed by GitHub
parent d1faf059ee
commit 3c6b885391
3 changed files with 21 additions and 11 deletions

View File

@@ -47,10 +47,11 @@ class InvitationsController < ApplicationController
body = invitation_params[:body] body = invitation_params[:body]
invitation_token = SecureRandom.hex(16) invitation_token = SecureRandom.hex(16)
invitation = Invitation.new(email: to, token_digest: Digest::SHA256.hexdigest(invitation_token))
subject = "[TEST] " + subject subject = "[TEST] " + subject
body_with_link = body.gsub('%link%', get_url_for(method(:new_user_registration_url), options: { invitation_token: invitation_token, email: to })) 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 render json: {}, status: :ok
end end

View File

@@ -1 +1 @@
<%= @body %> <%= simple_format(@body) %>

View File

@@ -40,15 +40,24 @@ class OAuthSignInUserWorkflow
end end
full_name ||= I18n.t('defaults.user_full_name') full_name ||= I18n.t('defaults.user_full_name')
user = User.new( ActiveRecord::Base.transaction do
email: email, user = User.new(
full_name: full_name, email: email,
password: Devise.friendly_token, full_name: full_name,
has_set_password: false, password: Devise.friendly_token,
status: 'active' has_set_password: false,
) status: 'active'
user.skip_confirmation )
user.save 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 end
return user return user