-
-
Notifications
You must be signed in to change notification settings - Fork 504
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Streamline organization onboarding using a newly introduced account r…
…equest flow (#1788) * Add AccountRequest model + specs & migration * Enable creating account_requests * Redirect to confirmation page when the account_request was succesful * Add case to handle invalid token * Add AccountRequestMailer & confirmation mail * Add routing specs for AccountRequestsController * Just about ready functionally * Fix spec with the mailing * Functional! * Allow mailer jobs to be processed off the `default` queue * Update copies * Change route name * Update styling on pages * Keep track of confirmed account requests * Functional! * Flash an error message if trying to use the same account request * Add more account_request request specs * Add admin request specs * Add system spec * System test for Account Request flow * Fix rubocop complaints * Add back in fakeredis * Remove unneeded templates * Update copy * Fix broken specs * Fix broken specs * Update app/views/static/index.html.erb Co-authored-by: Aaron H <aaron@rubyforgood.org> * Update app/views/account_requests/confirmation.html.erb Co-authored-by: Aaron H <aaron@rubyforgood.org> * Update app/views/account_requests/confirmation.html.erb Co-authored-by: Aaron H <aaron@rubyforgood.org> * Update app/views/account_request_mailer/confirmation.html.erb Co-authored-by: Aaron H <aaron@rubyforgood.org> * Update spec * Update based on PR suggestion * Fix rubocop * Fix broken spec Co-authored-by: Aaron H <aaron@rubyforgood.org>
- Loading branch information
1 parent
8f1fc0a
commit 2ecdbd0
Showing
33 changed files
with
989 additions
and
12 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
class AccountRequestsController < ApplicationController | ||
skip_before_action :authorize_user | ||
skip_before_action :authenticate_user! | ||
|
||
before_action :set_account_request_from_token, only: [:received, :confirmation, :confirm] | ||
|
||
layout 'devise' | ||
|
||
def received; end | ||
|
||
def confirmation; end | ||
|
||
def confirm | ||
@account_request.update!(confirmed_at: Time.current) | ||
AccountRequestMailer.approval_request(account_request_id: @account_request.id).deliver_later | ||
end | ||
|
||
def invalid_token; end | ||
|
||
def new | ||
@account_request = AccountRequest.new | ||
end | ||
|
||
def create | ||
@account_request = AccountRequest.new(account_request_params) | ||
|
||
if @account_request.save | ||
AccountRequestMailer.confirmation(account_request_id: @account_request.id).deliver_later | ||
|
||
redirect_to received_account_requests_path(token: @account_request.identity_token), | ||
notice: 'Account request was successfully created.' | ||
else | ||
render :new | ||
end | ||
end | ||
|
||
private | ||
|
||
# Use callbacks to share common setup or constraints between actions. | ||
def set_account_request_from_token | ||
@account_request = AccountRequest.get_by_identity_token(params[:token]) | ||
|
||
# Use confirmation timestamp instead | ||
if @account_request.nil? || @account_request.confirmed? || @account_request.processed? | ||
redirect_to invalid_token_account_requests_path(token: params[:token]) | ||
return | ||
end | ||
|
||
@account_request | ||
end | ||
|
||
# Only allow a list of trusted parameters through. | ||
def account_request_params | ||
params.require(:account_request).permit(:name, :email, :organization_name, :organization_website, :request_details) | ||
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
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,19 @@ | ||
class AccountRequestMailer < ApplicationMailer | ||
def confirmation(account_request_id:) | ||
@account_request = AccountRequest.find(account_request_id) | ||
|
||
mail( | ||
to: @account_request.email, | ||
subject: '[Action Required] Diaperbase Account Request' | ||
) | ||
end | ||
|
||
def approval_request(account_request_id:) | ||
@account_request = AccountRequest.find(account_request_id) | ||
|
||
mail( | ||
to: 'info@diaper.app', | ||
subject: "[Account Request] #{@account_request.organization_name}" | ||
) | ||
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,64 @@ | ||
# == Schema Information | ||
# | ||
# Table name: account_requests | ||
# | ||
# id :bigint not null, primary key | ||
# confirmed_at :datetime | ||
# email :string not null | ||
# name :string not null | ||
# organization_name :string not null | ||
# organization_website :string | ||
# request_details :text not null | ||
# created_at :datetime not null | ||
# updated_at :datetime not null | ||
# | ||
class AccountRequest < ApplicationRecord | ||
validates :name, presence: true | ||
validates :email, presence: true, uniqueness: true | ||
validates :request_details, presence: true, length: { minimum: 50 } | ||
validates :email, format: { with: URI::MailTo::EMAIL_REGEXP } | ||
|
||
validate :email_not_already_used_by_organization | ||
validate :email_not_already_used_by_user | ||
|
||
has_one :organization, dependent: :nullify | ||
|
||
def self.get_by_identity_token(identity_token) | ||
decrypted_token = JWT.decode(identity_token, Rails.application.secrets[:secret_key_base], true, { algorithm: 'HS256' }) | ||
account_request_id = decrypted_token[0]["account_request_id"] | ||
|
||
AccountRequest.find_by(id: account_request_id) | ||
rescue StandardError | ||
# The identity_token was determined to not be valid | ||
# and returns nil to indicate no match found. | ||
nil | ||
end | ||
|
||
def identity_token | ||
raise 'must have an id' unless persisted? | ||
|
||
JWT.encode({ account_request_id: id }, Rails.application.secrets[:secret_key_base], 'HS256') | ||
end | ||
|
||
def confirmed? | ||
confirmed_at.present? | ||
end | ||
|
||
def processed? | ||
organization.present? | ||
end | ||
|
||
private | ||
|
||
def email_not_already_used_by_organization | ||
if Organization.find_by(email: email) | ||
errors.add(:email, 'already used by an existing Organization') | ||
end | ||
end | ||
|
||
def email_not_already_used_by_user | ||
if User.find_by(email: email) | ||
errors.add(:email, 'already used by an existing User') | ||
end | ||
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
27 changes: 27 additions & 0 deletions
27
app/views/account_request_mailer/approval_request.html.erb
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,27 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta content='text/html; charset=UTF-8' http-equiv='Content-Type' /> | ||
</head> | ||
<body> | ||
<h1> We've just received a confirmed account request from <%= @account_request.organization_name %> </h1> | ||
|
||
<h3> Here are their details </h3> | ||
<table> | ||
<thead> | ||
<td>Attribute Name</td> | ||
<td>Value</td> | ||
</thead> | ||
|
||
<% @account_request.attributes.each do |ar, val| %> | ||
<tr> | ||
<td><%= ar.humanize %></td> | ||
<td><%= val %></td> | ||
</tr> | ||
<% end %> | ||
</table> | ||
|
||
<br> | ||
<%= link_to 'Create This Organization', new_admin_organization_url(token: @account_request.identity_token) %> | ||
</body> | ||
</html> |
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,55 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta content='text/html; charset=UTF-8' http-equiv='Content-Type' /> | ||
</head> | ||
<body> | ||
<p>Greetings from the Diaperbase Team,</p> | ||
|
||
<h3> Click 'Confirm' when you want to continue requesting an account with us </h3> | ||
|
||
<%= link_to 'Confirm This Request', confirmation_account_requests_url(token: @account_request.identity_token) %> | ||
|
||
<p> | ||
We're delighted to hear from you and hope you're all staying well! | ||
</p> | ||
|
||
<p> | ||
First, and most importantly, DiaperBase is 100% free! We're supported by the non-profit Code for Good and Microsoft sponsors the servers! | ||
</p> | ||
|
||
<p> | ||
If you'd like to experience the app, please log in to the sandbox/demo sites and test it out. | ||
Here is the login information for the demo sites: | ||
</p> | ||
|
||
<p> | ||
<a href='https://diaperbase.org/'>DiaperBase</a> | ||
<br> | ||
<span>Username: org_admin1@example.com</span> | ||
<br> | ||
<span>Password: password</span> | ||
</p> | ||
|
||
<p> | ||
<a href='https://partnerbase.org/'>PartnerBase</a> | ||
<br> | ||
<span>Username: verified@example.com</span> | ||
<br> | ||
<span>Password: password</span> | ||
</p> | ||
|
||
<p> | ||
A couple things to know about the sandbox servers before you start using them: | ||
The development team uses the servers for testing our new features and upgrades before putting them on the live site to ensure that no bugs get pushed through to the live site, so if something looks different than the (real) diaper.app site that is probably why! Please don’t enter any sensitive information into the demo servers, several users have access to the demo servers and it will be visible to all users. | ||
</p> | ||
|
||
<p> | ||
Finally, we made a getting started video with detailed directions on setting up your diaper bank in DiaperBase, check it out | ||
<a href='https://www.youtube.com/watch?v=fwo3WKMGM_4&feature=youtu.be'>here</a>! Please let us know when you would like to begin using DiaperBase and we will set you up and send you a welcome email. | ||
</p> | ||
|
||
<p>Diaperbase Team</p> | ||
|
||
</body> | ||
</html> |
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,11 @@ | ||
<div class="card"> | ||
<div class="card-body text-center"> | ||
<div class='card-text'> | ||
<h3> Confirmed! <h3> | ||
<h4> We will be processing your request now. </h4> | ||
|
||
<p> We will send your invitation via email when we've processed your request. We will reach out to you also via email if we have any questions.</p> | ||
</div> | ||
</div> | ||
</div> | ||
|
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,9 @@ | ||
<div class="card"> | ||
<div class="card-body text-center"> | ||
<div class='card-text'> | ||
<h3> Are you ready to get started? </h3> | ||
|
||
<%= link_to "I'm ready! Let's go!", confirm_account_requests_path(token: @account_request.identity_token) %></li> | ||
</div> | ||
</div> | ||
</div> |
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,33 @@ | ||
<p id="notice"><%= notice %></p> | ||
|
||
<h1>Account Requests</h1> | ||
|
||
<table> | ||
<thead> | ||
<tr> | ||
<th>Email</th> | ||
<th>Organization name</th> | ||
<th>Organization website</th> | ||
<th>Request details</th> | ||
<th colspan="3"></th> | ||
</tr> | ||
</thead> | ||
|
||
<tbody> | ||
<% @account_requests.each do |account_request| %> | ||
<tr> | ||
<td><%= account_request.email %></td> | ||
<td><%= account_request.organization_name %></td> | ||
<td><%= account_request.organization_website %></td> | ||
<td><%= account_request.request_details %></td> | ||
<td><%= link_to 'Show', account_request %></td> | ||
<td><%= link_to 'Edit', edit_account_request_path(account_request) %></td> | ||
<td><%= link_to 'Destroy', account_request, method: :delete, data: { confirm: 'Are you sure?' } %></td> | ||
</tr> | ||
<% end %> | ||
</tbody> | ||
</table> | ||
|
||
<br> | ||
|
||
<%= link_to 'New Account Request', new_account_request_path %> |
Oops, something went wrong.