Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add notifications for volunteer birthdays (#5316) #5328

Merged
merged 9 commits into from
Nov 8, 2023

Conversation

davidgumberg
Copy link
Contributor

@davidgumberg davidgumberg commented Nov 3, 2023

Resolves #5316

This PR adds notifications for volunteer birthdays.

  • Adds an optional 'date_of_birth' parameter to the Users model, which is a prerequisite for being able to notify supervisors of upcoming volunteer birthdays.

  • Adds a birthday_next_month scope to Volunteer, volunteer birthday notification, and rake task for creating the notifications.

Permissions

Volunteers can edit their own DOB, and supervisors and admins from the same org as a volunteer are able to edit the volunteer's DOB.

Tests

I've added tests for the views, and permissions, and a validation rule for the DOB's (they must be in the past.) and for the notification message, and notification rake task.

Volunteer birthday notification

Supervisor editing a volunteer from the shared form

User editing their own profile with datepicker

Date of birth validation message

Copy link
Contributor

@mattzollinhofer mattzollinhofer left a comment

Choose a reason for hiding this comment

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

This is a completely drive by review from a new guy to the area. Please take it or leave it completely. Just wanted to provide a few thoughts. Generally looks good!

app/models/learning_hour.rb Show resolved Hide resolved
app/validators/user_validator.rb Outdated Show resolved Hide resolved
@schoork
Copy link
Collaborator

schoork commented Nov 4, 2023

@davidgumberg What's the reasoning behind splitting this into 2 prs?

@davidgumberg
Copy link
Contributor Author

@davidgumberg What's the reasoning behind splitting this into 2 prs?

More than the size of the changes, I just wanted to make sure that adding a date of birth column to the Users table was desired, but since it's only use case is the birthday notification I think I'll make it one PR so they can be looked at together.

@davidgumberg davidgumberg changed the title Add date of birth to Users model; #5316 1/2 Add notifications for volunteer birthdays (#5316) Nov 5, 2023
@davidgumberg davidgumberg force-pushed the volunteerbirthdays branch 3 times, most recently from a97c1e9 to 6ae6e08 Compare November 5, 2023 07:19
app/models/volunteer.rb Outdated Show resolved Hide resolved
@@ -57,6 +63,10 @@ class Volunteer < User
.order(:display_name)
}

scope :birthday_next_month, -> {
where("EXTRACT(month from date_of_birth) = ?", DateTime.now.next_month.month)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Instead of raw SQL, use Rails helpers here

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I tried, but could not come up with a way to do this without using EXTRACT

Copy link
Collaborator

Choose a reason for hiding this comment

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

Try this

where(date_of_birth: Date.today.beginning_of_month.next_month..Date.today.end_of_month.next_month)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The problem is that this range will only include date_of_birth's that fall on the next month of this year.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Good point. Yeah, the only solution I saw started to feel over-engineered. There's no user input in this, so that makes me more comfortable. Keep as is.

app/notifications/volunteer_birthday_notification.rb Outdated Show resolved Hide resolved
app/views/notifications/index.html.erb Outdated Show resolved Hide resolved
app/views/users/edit.html.erb Outdated Show resolved Hide resolved
app/views/volunteers/_form.html.erb Show resolved Hide resolved
app/views/volunteers/_form.html.erb Show resolved Hide resolved
config/initializers/date_formats.rb Outdated Show resolved Hide resolved
@schoork
Copy link
Collaborator

schoork commented Nov 5, 2023

Absolutely love all the tests @davidgumberg!

@davidgumberg davidgumberg force-pushed the volunteerbirthdays branch 3 times, most recently from 694653b to f763e01 Compare November 8, 2023 04:54
@davidgumberg
Copy link
Contributor Author

@schoork Thanks for the review, I've implemented the suggestions you made (minus using rails helpers for birthday_next_month, which I could not figure out a way to do) and I've also added tests for the two new scopes in the volunteer model.

@@ -44,4 +44,16 @@ def formatted_reset_password_sent_at
def formatted_invitation_sent_at
formatted_timestamp(:invitation_sent_at)
end

def formatted_birthday
return "" unless object.date_of_birth.respond_to?(:strftime)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Love the NoMethodError guards.

Copy link
Collaborator

@schoork schoork left a comment

Choose a reason for hiding this comment

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

Really awesome work @davidgumberg! Love all the tests. Had never heard of the travel_to DATE. That's pretty nifty!

@schoork schoork merged commit e96ff2a into rubyforgood:main Nov 8, 2023
12 checks passed
@davidgumberg
Copy link
Contributor Author

Really awesome work @davidgumberg! Love all the tests. Had never heard of the travel_to DATE. That's pretty nifty!

Thanks for the review and feedback!

I got the idea for travel_to from spec/lib/tasks/emancipation_checklist_reminder_spec.rb

@bcastillo32
Copy link
Collaborator

@davidgumberg Thanks for the work here. I want to share this update with the casa stakeholders. They will love it. how many days out does the birthday need to be to receive a notification?

@davidgumberg
Copy link
Contributor Author

davidgumberg commented Dec 5, 2023

@davidgumberg Thanks for the work here. I want to share this update with the casa stakeholders. They will love it. how many days out does the birthday need to be to receive a notification?

Thanks @bcastillo32.

Actually, there is a heroku task that will need to be added to run once a month by whoever administers the CASA application, and it will notify volunteers in the same cadence as the youth volunteer reminders, on the 15th (or whichever day of the month the administrator sets the task to run) of each month, users will receive a notification about all volunteer birthdays that are coming in the next month. Please let me know if that behavior is aligned with what the stakeholders requested, and if not, I can write another PR to update the changes to better reflect their request.

@davidgumberg davidgumberg deleted the volunteerbirthdays branch December 5, 2023 17:45
@bcastillo32
Copy link
Collaborator

@davidgumberg Thanks for the work here. I want to share this update with the casa stakeholders. They will love it. how many days out does the birthday need to be to receive a notification?

Thanks @bcastillo32.

Actually, there is a heroku task that will need to be added to run once a month by whoever administers the CASA application, and it will notify volunteers in the same cadence as the youth volunteer reminders, on the 15th (or whichever day of the month the administrator sets the task to run) of each month, users will receive a notification about all volunteer birthdays that are coming in the next month. Please let me know if that behavior is aligned with what the stakeholders requested, and if not, I can write another PR to update the changes to better reflect their request.

thanks @davidgumberg ! I will reach out to the CASA team to confirm if the proposed schedule suits their requirements. I plan to inform them of the suggested cadence, and if they have any objections and want to propose a different one, we can consider it. Thank you once again for your valuable input!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
erb ruby Pull requests that update Ruby code Tests! 🎉💖👏
Projects
None yet
Development

Successfully merging this pull request may close these issues.

alerts supervisors to upcoming volunteer birthdays
5 participants