diff --git a/app/controllers/invite_requests_controller.rb b/app/controllers/invite_requests_controller.rb index 95c981dbdd8..58efe1e623c 100644 --- a/app/controllers/invite_requests_controller.rb +++ b/app/controllers/invite_requests_controller.rb @@ -26,13 +26,18 @@ def resend @invitation = Invitation.unredeemed.from_queue.find_by(invitee_email: params[:email]) if @invitation.nil? - flash[:error] = ts("Could not find an invitation associated with that email.") - elsif @invitation.can_resend? - @invitation.send_and_set_date(resend: true) - flash[:notice] = ts("Invitation resent to %{email}.", email: @invitation.invitee_email) + flash[:error] = t("invite_requests.resend.not_found") + elsif !@invitation.can_resend? + flash[:error] = t("invite_requests.resend.not_yet", + count: ArchiveConfig.HOURS_BEFORE_RESEND_INVITATION) else - flash[:error] = ts("You cannot resend an invitation that was sent in the last %{count} hours.", - count: ArchiveConfig.HOURS_BEFORE_RESEND_INVITATION) + @invitation.send_and_set_date(resend: true) + + if @invitation.errors.any? + flash[:error] = @invitation.errors.full_messages.first + else + flash[:notice] = t("invite_requests.resend.success", email: @invitation.invitee_email) + end end redirect_to status_invite_requests_path diff --git a/app/models/invitation.rb b/app/models/invitation.rb index 393186a75a3..7e6801e9066 100644 --- a/app/models/invitation.rb +++ b/app/models/invitation.rb @@ -58,22 +58,20 @@ def mark_as_redeemed(user=nil) def send_and_set_date(resend: false) return if invitee_email.blank? - begin - if self.external_author - archivist = self.external_author.external_creatorships.collect(&:archivist).collect(&:login).uniq.join(", ") - # send invite synchronously for now -- this should now work delayed but just to be safe - UserMailer.invitation_to_claim(self.id, archivist).deliver_now - else - # send invitations actively sent by a user synchronously to avoid delays - UserMailer.invitation(self.id).deliver_now - end - - date_column = resend ? :resent_at : :sent_at - # Skip callbacks within after_save by using update_column to avoid a callback loop - self.update_column(date_column, Time.current) - rescue StandardError => e - errors.add(:base, "Notification email could not be sent: #{e.message}") + if self.external_author + archivist = self.external_author.external_creatorships.collect(&:archivist).collect(&:login).uniq.join(", ") + # send invite synchronously for now -- this should now work delayed but just to be safe + UserMailer.invitation_to_claim(self.id, archivist).deliver_now + else + # send invitations actively sent by a user synchronously to avoid delays + UserMailer.invitation(self.id).deliver_now end + + date_column = resend ? :resent_at : :sent_at + # Skip callbacks within after_save by using update_column to avoid a callback loop + self.update_column(date_column, Time.current) + rescue StandardError => e + errors.add(:base, :notification_could_not_be_sent, error: e.message) end def can_resend? diff --git a/app/views/invitations/_invitation.html.erb b/app/views/invitations/_invitation.html.erb index ae915164f10..24fdc3b778b 100644 --- a/app/views/invitations/_invitation.html.erb +++ b/app/views/invitations/_invitation.html.erb @@ -24,7 +24,7 @@