diff --git a/app/controllers/volunteers_controller.rb b/app/controllers/volunteers_controller.rb
index e8e26ce5a0..05db3abc2b 100644
--- a/app/controllers/volunteers_controller.rb
+++ b/app/controllers/volunteers_controller.rb
@@ -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"
+ end
+ end
+
def reminder
authorize @volunteer
with_cc = params[:with_cc].present?
@@ -134,4 +144,22 @@ def update_volunteer_params
.new(params)
.without_active
end
+
+ def volunteers_phone_number
+ authorize @volunteer
+ @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}
+ twilio_res = twilio.send_sms(req_params)
+
+ # Error handling for spec test purposes
+ 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
diff --git a/app/policies/volunteer_policy.rb b/app/policies/volunteer_policy.rb
index 1ca5971784..712d40bcea 100644
--- a/app/policies/volunteer_policy.rb
+++ b/app/policies/volunteer_policy.rb
@@ -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
diff --git a/app/views/volunteers/_manage_active.html.erb b/app/views/volunteers/_manage_active.html.erb
index acc000d601..f8388a8d61 100644
--- a/app/views/volunteers/_manage_active.html.erb
+++ b/app/views/volunteers/_manage_active.html.erb
@@ -1,6 +1,6 @@
<% if user.active? %>
- Volunteer is Active
+ Volunteer is Active
<% if policy(user).deactivate? %>
<%= link_to "Deactivate volunteer",
deactivate_volunteer_path(user),
@@ -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? %>
+ <%= link_to "Send Reactivation Alert (SMS)",
+ send_reactivation_alert_volunteer_path(user),
+ class: "btn btn-outline-danger" %>
+ <% end %>
diff --git a/config/routes.rb b/config/routes.rb
index 23e5248596..75983388aa 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -49,6 +49,7 @@
patch :deactivate
patch :activate
patch :resend_invitation
+ post :send_reactivation_alert
patch :change_to_supervisor
end
end
@@ -107,6 +108,7 @@
patch :activate
patch :deactivate
get :resend_invitation
+ get :send_reactivation_alert
patch :reminder
get :impersonate
end
diff --git a/spec/requests/volunteers_spec.rb b/spec/requests/volunteers_spec.rb
index a8ca19417b..43b9d2a01b 100644
--- a/spec/requests/volunteers_spec.rb
+++ b/spec/requests/volunteers_spec.rb
@@ -1,4 +1,5 @@
require "rails_helper"
+require "support/webmock_helper"
RSpec.describe "/volunteers", type: :request do
let(:organization) { create(:casa_org) }
@@ -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) }
diff --git a/spec/support/webmock_helper.rb b/spec/support/webmock_helper.rb
index cbf27457b8..6ee8ec80fa 100644
--- a/spec/support/webmock_helper.rb
+++ b/spec/support/webmock_helper.rb
@@ -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