Skip to content

Feature/1887 Volunteer receives SMS notification when their account is reactivated by admin#3641

Merged
compwron merged 19 commits intorubyforgood:mainfrom
rubyforpeace:feature/1887
Jun 15, 2022
Merged

Feature/1887 Volunteer receives SMS notification when their account is reactivated by admin#3641
compwron merged 19 commits intorubyforgood:mainfrom
rubyforpeace:feature/1887

Conversation

@7riumph
Copy link
Copy Markdown
Collaborator

@7riumph 7riumph commented Jun 13, 2022

What github issue is this PR for, if any?

Resolves #1887

What changed, and why?

Admins can send SMS messages to inform volunteers that their account was reactivated.

  • Added send_reactivation_alert button and path's action method endpoint
  • Configured HTTP get and post methods in routes.rb
  • Granted admins send_reactivation_alert to volunteer privileges in policies/volunteer_policy.rb
  • Invoked Twilio API through new send_sms_to(phone_number, body) method in volunteers controller

How will this affect user permissions?

  • Volunteer and Supervisor permissions: n/a
  • Admin permissions: Can now send account reactivation alerts to volunteers

How is this tested? (please write tests!) 💖💪

Created a test to confirm send_reactivation_alert_volunteer_path redirects correctly. And added a stub_request to confirm the corresponding SMS is generated on said redirect

Screenshots please :)

send-reactivation-alert.mov

@github-actions github-actions Bot added erb ruby Pull requests that update Ruby code labels Jun 13, 2022
Copy link
Copy Markdown
Collaborator

@compwron compwron left a comment

Choose a reason for hiding this comment

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

Please add a test :)

@7riumph 7riumph added the codethechange for codethechange developers label Jun 14, 2022
@7riumph 7riumph self-assigned this Jun 15, 2022
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

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


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

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
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

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?

Comment thread config/routes.rb
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...

@compwron compwron marked this pull request as ready for review June 15, 2022 01:38
@compwron compwron merged commit 34d4a2c into rubyforgood:main Jun 15, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

codethechange for codethechange developers erb ruby Pull requests that update Ruby code Tests! 🎉💖👏

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Volunteer receives SMS notification when their account is reactivated by admin

2 participants