Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions app/controllers/volunteers_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,16 @@ def resend_invitation
end
end

def send_reactivation_alert
authorize @volunteer
if @volunteer.save
send_sms_to(volunteers_phone_number, "Hello #{@volunteer.display_name}, \n \n Your CASA/Prince George’s County volunteer console account has been reactivated. You can login using the credentials you were already using. \n \n If you have any questions, please contact your most recent Case Supervisor for assistance. \n \n CASA/Prince George’s County")
redirect_to edit_volunteer_path(@volunteer), notice: "Volunteer reactivation alert sent"
else
redirect_to edit_volunteer_path(@volunteer), alert: "Volunteer reactivation alert failed"
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe add the failure notes from volunteer.errors.full_messages ?

end
end

def reminder
authorize @volunteer
with_cc = params[:with_cc].present?
Expand Down Expand Up @@ -134,4 +144,22 @@ def update_volunteer_params
.new(params)
.without_active
end

def volunteers_phone_number
authorize @volunteer
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you don't need to authorize twice

@volunteers_phone_number = @volunteer.phone_number
end

def send_sms_to(phone_number, body)
twilio = TwilioService.new(current_user.casa_org.twilio_api_key_sid, current_user.casa_org.twilio_api_key_secret, current_user.casa_org.twilio_account_sid)
req_params = {From: current_user.casa_org.twilio_phone_number, Body: body, To: phone_number}
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lowercase is more normal than uppercase From

twilio_res = twilio.send_sms(req_params)

# Error handling for spec test purposes
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might be better to just leave twilio.send_sms(req_params) as the last line in the method so it is returned by default, and then assert on twilio_res.error_code directly in spec

if twilio_res.error_code.nil?
"SMS has been sent to Volunteer!"
else
"SMS was not sent to Volunteer due to an error."
end
end
end
1 change: 1 addition & 0 deletions app/policies/volunteer_policy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,6 @@ def stop_impersonating?
alias_method :activate?, :admin_or_supervisor_same_org?
alias_method :deactivate?, :admin_or_supervisor_same_org?
alias_method :resend_invitation?, :admin_or_supervisor_same_org?
alias_method :send_reactivation_alert?, :admin_or_supervisor_same_org?
alias_method :reminder?, :admin_or_supervisor_same_org?
end
9 changes: 7 additions & 2 deletions app/views/volunteers/_manage_active.html.erb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<div class="field form-group">
<% if user.active? %>
Volunteer is <span class="badge badge-success text-uppercase display-1">Active</span>
Volunteer is <span class="badge badge-success text-uppercase display-1">Active</span><br>
<% if policy(user).deactivate? %>
<%= link_to "Deactivate volunteer",
deactivate_volunteer_path(user),
Expand All @@ -22,8 +22,13 @@
<% if (current_user.supervisor? ||
current_user.casa_admin?) &&
user.invitation_accepted_at.nil? %>
<%= link_to "Resend Invitation",
<%= link_to "Resend Invitation (Email)",
resend_invitation_volunteer_path(user),
class: "btn btn-outline-danger" %>
<% end %>
<% if current_user.casa_admin? %>
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

linter might be sad here?

<%= link_to "Send Reactivation Alert (SMS)",
send_reactivation_alert_volunteer_path(user),
class: "btn btn-outline-danger" %>
<% end %>
</div>
2 changes: 2 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
patch :deactivate
patch :activate
patch :resend_invitation
post :send_reactivation_alert
patch :change_to_supervisor
end
end
Expand Down Expand Up @@ -107,6 +108,7 @@
patch :activate
patch :deactivate
get :resend_invitation
get :send_reactivation_alert
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is there a get here? Seems odd...

patch :reminder
get :impersonate
end
Expand Down
21 changes: 21 additions & 0 deletions spec/requests/volunteers_spec.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
require "rails_helper"
require "support/webmock_helper"

RSpec.describe "/volunteers", type: :request do
let(:organization) { create(:casa_org) }
Expand Down Expand Up @@ -274,6 +275,26 @@
end
end

describe "POST /send_reactivation_alert" do
before do
sign_in admin

stubbed_requests
WebMock.disable_net_connect!
@acc_sid = "fake_twilio_sid"
@api_key = "fake_twilio_api_key"
@api_secret = "fake_twilio_api_secret"
@short_url = ShortUrlService.new
@twilio = TwilioService.new(@api_key, @api_secret, @acc_sid)
end

it "sends an reactivation SMS" do
get send_reactivation_alert_volunteer_path(volunteer)
expect(response).to redirect_to(edit_volunteer_path(volunteer))
expect(response.status).to match 302
end
end

describe "GET /impersonate" do
let!(:other_volunteer) { create(:volunteer, casa_org: organization) }
let!(:supervisor) { create(:supervisor, casa_org: organization) }
Expand Down
13 changes: 13 additions & 0 deletions spec/support/webmock_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,17 @@ def stubbed_requests
}
)
.to_return(body: "{\"error_code\":null, \"status\":\"sent\", \"body\":\"If you have made contact with them in the past 60 days, remember to log it: https://42ni.short.gy/jzTwdF\"}")
stub_request(:post, "https://api.twilio.com/2010-04-01/Accounts//Messages.json")
.with(
body: {"Body" => /volunteer\sconsole\saccount\shas\sbeen\sreactivated/, "From" => nil, "To" => ""},
headers: {
"Accept" => "application/json",
"Accept-Charset" => "utf-8",
"Accept-Encoding" => "gzip;q=1.0,deflate;q=0.6,identity;q=0.3",
"Authorization" => "Basic Og==",
"Content-Type" => "application/x-www-form-urlencoded",
"User-Agent" => "twilio-ruby/5.67.2 (linux x86_64) Ruby/3.1.0"
}
)
.to_return(status: 200, body: "", headers: {})
end