-
Notifications
You must be signed in to change notification settings - Fork 517
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
AO3-6609 Allow users to resend invitations (#4648)
* Check for invitations in invite request status. * AO3-6609 Fill spec requirements * AO3-6609 Hound * AO3-6609 Houndilocks * AO3-6609 Reviewdog * Feedback * AO3-6609 Houndini * Apply suggestions Co-authored-by: Brian Austin <[email protected]> * Fix spec Co-authored-by: Brian Austin <[email protected]> * AO3-6609 Feedback * AO3-6609 Oops --------- Co-authored-by: tickinginstant <[email protected]> Co-authored-by: Brian Austin <[email protected]>
- Loading branch information
1 parent
9121fb4
commit 6c30419
Showing
15 changed files
with
211 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<!--Descriptive page name, messages and instructions--> | ||
<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(".info.#{status}", | ||
sent_at: l(invitation.sent_at.to_date), | ||
resent_at: invitation.resent_at ? l(invitation.resent_at.to_date) : nil) %> | ||
<% 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, | ||
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(){ | ||
$j('#invite-heading').replaceWith(function () { | ||
return "<h3>" + $j(this).html() + "</h3>"; | ||
}); | ||
}) | ||
</script> | ||
<% end %> | ||
<!--/content--> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<p class="notice"> | ||
<%= t(".email_not_found") %> | ||
</p> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,11 @@ | ||
<%= render "invite_request", invite_request: @invite_request %> | ||
<% if @invite_request %> | ||
<%= render "invite_request", invite_request: @invite_request %> | ||
<% elsif @invitation %> | ||
<%= render "invitation", invitation: @invitation %> | ||
<% else %> | ||
<%= render "no_invitation" %> | ||
<% end %> | ||
|
||
<p> | ||
<%= ts("To check on the status of your invitation, go to the %{status_page} and enter your email in the space provided!", status_page: link_to("Invitation Request Status page", status_invite_requests_path)).html_safe %> | ||
<%= t(".instructions_html", status_link: link_to("Invitation Request Status page", status_invite_requests_path)) %> | ||
</p> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
<% if @invite_request %> | ||
$j("#invite-status").html("<%= escape_javascript(render "invite_requests/invite_request", invite_request: @invite_request) %>"); | ||
<% elsif @invitation %> | ||
$j("#invite-status").html("<%= escape_javascript(render "invitation", invitation: @invitation) %>"); | ||
<% else %> | ||
$j("#invite-status").html("<p>Sorry, we can't find the email address you entered. If you had used it to join our invitation queue, it's possible that your invitation may have already been emailed to you; please check your spam folder, as your spam filters may have placed it there.</p>"); | ||
$j("#invite-status").html("<%= escape_javascript(render "no_invitation") %>"); | ||
<% end %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -81,6 +81,7 @@ | |
collection do | ||
get :manage | ||
get :status | ||
post :resend | ||
end | ||
end | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -57,7 +57,7 @@ Feature: Invite queue management | |
# check your place in the queue - invalid address | ||
When I check how long "[email protected]" will have to wait in the invite request queue | ||
Then I should see "Invitation Request Status" | ||
And I should see "If you can't find it, your invitation may have already been emailed to that address; please check your email spam folder as your spam filters may have placed it there." | ||
And I should see "Sorry, we can't find the email address you entered." | ||
And I should not see "You are currently number" | ||
|
||
# check your place in the queue - correct address | ||
|
@@ -98,7 +98,7 @@ Feature: Invite queue management | |
Then 1 email should be delivered to test@archiveofourown.org | ||
When I check how long "[email protected]" will have to wait in the invite request queue | ||
Then I should see "Invitation Request Status" | ||
And I should see "If you can't find it, your invitation may have already been emailed to that address;" | ||
And I should see "If you can't find it, please check your email spam folder as your spam filters may have placed it there." | ||
|
||
# invite can be used | ||
When I am logged in as an admin | ||
|
@@ -155,3 +155,29 @@ Feature: Invite queue management | |
And I fill in "invite_request_email" with "[email protected]" | ||
And I press "Add me to the list" | ||
Then I should see "Email is already being used by an account holder." | ||
|
||
Scenario: Users can resend their invitation after enough time has passed | ||
Given account creation is enabled | ||
And the invitation queue is enabled | ||
And account creation requires an invitation | ||
And the invite_from_queue_at is yesterday | ||
And an invitation request for "[email protected]" | ||
When the scheduled check_invite_queue job is run | ||
Then 1 email should be delivered to invitee@example.org | ||
|
||
When I check how long "[email protected]" will have to wait in the invite request queue | ||
Then I should see "Invitation Request Status" | ||
And I should see "If you can't find it, please check your email spam folder as your spam filters may have placed it there." | ||
And I should not see "Because your invitation was sent more than 24 hours ago, you can have your invitation resent." | ||
And I should not see a "Resend Invitation" button | ||
|
||
When all emails have been delivered | ||
And it is currently 25 hours from now | ||
And I check how long "[email protected]" will have to wait in the invite request queue | ||
Then I should see "Invitation Request Status" | ||
And I should see "If you can't find it, please check your email spam folder as your spam filters may have placed it there." | ||
And I should see "Because your invitation was sent more than 24 hours ago, you can have your invitation resent." | ||
And I should see a "Resend Invitation" button | ||
|
||
When I press "Resend Invitation" | ||
Then 1 email should be delivered to invitee@example.org |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,21 +17,14 @@ | |
|
||
describe "GET #show" do | ||
context "when given invalid emails" do | ||
it "redirects to index with error" do | ||
message = "You can search for the email address you signed up with below. If you can't find it, your invitation may have already been emailed to that address; please check your email spam folder as your spam filters may have placed it there." | ||
get :show, params: { id: 0 } | ||
it_redirects_to_with_error(status_invite_requests_path, message) | ||
expect(assigns(:invite_request)).to be_nil | ||
get :show, params: { id: 0, email: "[email protected]" } | ||
it_redirects_to_with_error(status_invite_requests_path, message) | ||
it "renders" do | ||
get :show, params: { email: "[email protected]" } | ||
expect(response).to render_template("show") | ||
expect(assigns(:invite_request)).to be_nil | ||
end | ||
|
||
it "renders for an ajax call" do | ||
get :show, params: { id: 0 }, xhr: true | ||
expect(response).to render_template("show") | ||
expect(assigns(:invite_request)).to be_nil | ||
get :show, params: { id: 0, email: "[email protected]" }, xhr: true | ||
get :show, params: { email: "[email protected]" }, xhr: true | ||
expect(response).to render_template("show") | ||
expect(assigns(:invite_request)).to be_nil | ||
end | ||
|
@@ -41,19 +34,51 @@ | |
let(:invite_request) { create(:invite_request) } | ||
|
||
it "renders" do | ||
get :show, params: { id: 0, email: invite_request.email } | ||
get :show, params: { email: invite_request.email } | ||
expect(response).to render_template("show") | ||
expect(assigns(:invite_request)).to eq(invite_request) | ||
end | ||
|
||
it "renders for an ajax call" do | ||
get :show, params: { id: 0, email: invite_request.email }, xhr: true | ||
get :show, params: { email: invite_request.email }, xhr: true | ||
expect(response).to render_template("show") | ||
expect(assigns(:invite_request)).to eq(invite_request) | ||
end | ||
end | ||
end | ||
|
||
describe "POST #resend" do | ||
context "when the email doesn't match any invitations" do | ||
it "redirects with an error" do | ||
post :resend, params: { email: "[email protected]" } | ||
it_redirects_to_with_error(status_invite_requests_path, | ||
"Could not find an invitation associated with that email.") | ||
end | ||
end | ||
|
||
context "when the invitation is too recent" do | ||
let(:invitation) { create(:invitation) } | ||
|
||
it "redirects with an error" do | ||
post :resend, params: { email: invitation.invitee_email } | ||
it_redirects_to_with_error(status_invite_requests_path, | ||
"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 a success message" do | ||
travel_to((1 + ArchiveConfig.HOURS_BEFORE_RESEND_INVITATION).hours.from_now) | ||
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 | ||
it "redirects to index with error given invalid emails" do | ||
post :create, params: { invite_request: { email: "wat" } } | ||
|