Skip to content

Commit

Permalink
AO3-6609 Fill spec requirements
Browse files Browse the repository at this point in the history
  • Loading branch information
weeklies committed Oct 27, 2023
1 parent 0812a2a commit 3b51af9
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 17 deletions.
4 changes: 2 additions & 2 deletions app/controllers/invite_requests_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ def resend

if @invitation.nil?
flash[:error] = ts("Could not find an invitation associated with that email.")
elsif @invitation.sent_at < ArchiveConfig.HOURS_BEFORE_RESEND_INVITATION.hours.ago
@invitation.send_and_set_date
elsif @invitation.can_resend?
@invitation.send_and_set_date(resend: true)
flash[:notice] = ts("Invitation resent to %{email}.", email: @invitation.invitee_email)
else
flash[:error] = ts("You cannot resend an invitation that was sent in the last %{count} hours.",
Expand Down
10 changes: 8 additions & 2 deletions app/models/invitation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def mark_as_redeemed(user=nil)
save
end

def send_and_set_date
def send_and_set_date(resend: false)
return if invitee_email.blank?

begin
Expand All @@ -68,13 +68,19 @@ def send_and_set_date
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(:sent_at, Time.now)
self.update_column(date_column, Time.now)
rescue Exception => exception
errors.add(:base, "Notification email could not be sent: #{exception.message}")
end
end

def can_resend?
checked_date = self.resent_at ? self.resent_at : self.sent_at
checked_date < ArchiveConfig.HOURS_BEFORE_RESEND_INVITATION.hours.ago
end

private

def generate_token
Expand Down
2 changes: 2 additions & 0 deletions app/views/invitations/_invitation.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
<dd><%= invitation.created_at %></dd>
<dt>Sent at</dt>
<dd><%= invitation.sent_at %></dd>
<dt>Resent at</dt>
<dd><%= invitation.resent_at %></dd>
<dt>Redeemed at</dt>
<dd><%= invitation.redeemed_at %></dd>
</dl>
31 changes: 25 additions & 6 deletions app/views/invite_requests/_invitation.html.erb
Original file line number Diff line number Diff line change
@@ -1,15 +1,34 @@
<!--Descriptive page name, messages and instructions-->
<h2 class="heading">
<h2 class="heading" id="invite-heading">
<%= t(".title", email: invitation.invitee_email) %>
</h2>
<!--/descriptions-->

<!--main content-->
<% status = invitation.resent_at ? "resent" : "not_resent" %>
<p>
<%= t(".date", date: l(invitation.sent_at.to_date)) %>
<% if invitation.sent_at < ArchiveConfig.HOURS_BEFORE_RESEND_INVITATION.hours.ago %>
<%= t(".resend", count: ArchiveConfig.HOURS_BEFORE_RESEND_INVITATION) %>
<%= button_to t(".resend_button"), resend_invite_requests_path(email: invitation.invitee_email) %>
<% end %>
<%= t(".info.#{status}",
sent_at: l(invitation.sent_at.to_date),
resent_at: invitation.resent_at ? l(invitation.resent_at.to_date) : nil ) %>

Check failure on line 12 in app/views/invite_requests/_invitation.html.erb

View workflow job for this annotation

GitHub Actions / ERB Lint runner

[] reported by reviewdog 🐶 Layout/SpaceInsideParens: Space inside parentheses detected. Raw Output: app/views/invite_requests/_invitation.html.erb:12:79: Layout/SpaceInsideParens: Space inside parentheses detected.
<% if invitation.can_resend? %>
<%# i18n-tasks-use t("invite_requests.invitation.after_cooldown_period.not_resent")
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)) %>
<%= 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>

<%= content_for :footer_js do %>
<%= javascript_tag do %>

Check failure on line 26 in app/views/invite_requests/_invitation.html.erb

View workflow job for this annotation

GitHub Actions / ERB Lint runner

[] reported by reviewdog 🐶 Avoid using 'javascript_tag do' as it confuses tests that validate html, use inline <script> instead Raw Output: app/views/invite_requests/_invitation.html.erb:26:2: Avoid using 'javascript_tag do' as it confuses tests that validate html, use inline <script> instead
$j(document).ready(function(){
$j('#invite-heading').replaceWith(function () {
return "<h3>" + $j(this).html() + "</h3>";
});
})
<% end %>
<% end %>
<!--/content-->
24 changes: 17 additions & 7 deletions config/locales/views/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -483,17 +483,27 @@ en:
invitation:
email_address_label: Enter an email address
invite_requests:
invitation:
after_cooldown_period:
not_resent:
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}.
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.
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.
resent: Your invitation was emailed to this address on %{sent_at} and resent on %{resent_at}. If you can't find it, please check your email spam folder as your spam filters may have placed it there.
resend_button: Resend Invitation
title: Invitation Status for %{email}
invite_request:
date: 'At our current rate, you should receive an invitation on or around: %{date}.'
position_html: You are currently number %{position} on our waiting list!
title: Invitation Status for %{email}
invitation:
title: Invitation Status for %{email}
date: Your invitation was emailed to this address on %{date}. If you can't find it, please check your email spam folder as your spam filters may have placed it there.
resend:
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.
resend_button: Resend Invitation
kudos:
guest_header:
one: "%{count} guest has also left kudos"
Expand Down
7 changes: 7 additions & 0 deletions db/migrate/20231027172035_add_resent_at_to_invitations.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
class AddResentAtToInvitations < ActiveRecord::Migration[6.1]
uses_departure! if Rails.env.staging? || Rails.env.production?

def change
add_column :invitations, :resent_at, :datetime
end
end

0 comments on commit 3b51af9

Please sign in to comment.