Skip to content

Commit

Permalink
Feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
weeklies committed Oct 30, 2023
1 parent 878e62b commit ec32496
Show file tree
Hide file tree
Showing 8 changed files with 53 additions and 27 deletions.
17 changes: 11 additions & 6 deletions app/controllers/invite_requests_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
28 changes: 13 additions & 15 deletions app/models/invitation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand Down
2 changes: 1 addition & 1 deletion app/views/invitations/_invitation.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
<dd><%= invitation.created_at %></dd>
<dt>Sent at</dt>
<dd><%= invitation.sent_at %></dd>
<dt>Resent at</dt>
<dt>Last resent at</dt>
<dd><%= invitation.resent_at %></dd>
<dt>Redeemed at</dt>
<dd><%= invitation.redeemed_at %></dd>
Expand Down
3 changes: 2 additions & 1 deletion app/views/invite_requests/_invitation.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,14 @@
i18n-tasks-use t("invite_requests.invitation.after_cooldown_period.resent")-%>
<%= t(".after_cooldown_period.#{status}",
count: ArchiveConfig.HOURS_BEFORE_RESEND_INVITATION,
support_link: link_to(t(".contact_support"), new_feedback_report_path)) %>
contact_support_link: link_to(t(".contact_support"), new_feedback_report_path)) %>
<%= button_to t(".resend_button"), resend_invite_requests_path(email: invitation.invitee_email) %>
<% else %>
<%= t(".before_cooldown_period", count: ArchiveConfig.HOURS_BEFORE_RESEND_INVITATION) %>
<% end %>
</p>

<%# Correct heading size for JavaScript display %>
<%= content_for :footer_js do %>
<script>
$j(document).ready(function(){
Expand Down
5 changes: 5 additions & 0 deletions config/locales/controllers/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,11 @@ en:
error: Sorry, that comment could not be unhidden.
permission_denied: Sorry, you don't have permission to unhide that comment.
success: Comment successfully unhidden!
invite_requests:
resend:
not_found: Could not find an invitation associated with that email.
not_yet: You cannot resend an invitation that was sent in the last %{count} hours.
success: Invitation resent to %{email}.
kudos:
create:
success: Thank you for leaving kudos!
Expand Down
5 changes: 5 additions & 0 deletions config/locales/models/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,11 @@ en:
attributes:
user_defined_tags_count:
at_most: must not add up to more than %{count}. You have entered %{value} of these tags, so you must remove %{diff} of them.
invitation:
attributes:
base:
format: "%{message}"
notification_could_not_be_sent: 'Notification email could not be sent: %{error}'
kudo:
attributes:
commentable:
Expand Down
8 changes: 4 additions & 4 deletions config/locales/views/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -489,11 +489,11 @@ en:
one: Because your invitation was sent more than an hour ago, you can have your invitation resent.
other: Because your invitation was sent more than %{count} hours ago, you can have your invitation resent.
resent:
one: Because your invitation was resent more than an hour ago, you can have your invitation resent again, or you may want to %{support_link}.
other: Because your invitation was resent more than %{count} hours ago, you can have your invitation resent again, or you may want to %{support_link}.
one: Because your invitation was resent more than an hour ago, you can have your invitation resent again, or you may want to %{contact_support_link}.
other: Because your invitation was resent more than %{count} hours ago, you can have your invitation resent again, or you may want to %{contact_support_link}.
before_cooldown_period:
one: if it has been more than an hour since you should have received your invitation, but you have not received it after checking your spam folder, you can visit this page to resend the invitation.
other: if it has been more than %{count} hours since you should have received your invitation, but you have not received it after checking your spam folder, you can visit this page to resend the invitation.
one: If it has been more than an hour since you should have received your invitation, but you have not received it after checking your spam folder, you can visit this page to resend the invitation.
other: If it has been more than %{count} hours since you should have received your invitation, but you have not received it after checking your spam folder, you can visit this page to resend the invitation.
contact_support: contact Support
info:
not_resent: Your invitation was emailed to this address on %{sent_at}. If you can't find it, please check your email spam folder as your spam filters may have placed it there.
Expand Down
12 changes: 12 additions & 0 deletions spec/controllers/invite_requests_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,18 @@
"You cannot resend an invitation that was sent in the last 24 hours.")
end
end

context "when the email and time are valid" do
let!(:invitation) { create(:invitation) }

it "redirects with an error" do
travel_to (1 + ArchiveConfig.HOURS_BEFORE_RESEND_INVITATION).hours.since
post :resend, params: { email: invitation.invitee_email }

it_redirects_to_with_notice(status_invite_requests_path,
"Invitation resent to #{invitation.invitee_email}.")
end
end
end

describe "POST #create" do
Expand Down

0 comments on commit ec32496

Please sign in to comment.