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
Next Next commit
Add 'date of birth' to Users model
  • Loading branch information
davidgumberg committed Nov 4, 2023
commit 715e687d9965a8781b260e2ccd83478cc61f842e
2 changes: 1 addition & 1 deletion app/controllers/casa_admins_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ def set_admin
end

def update_casa_admin_params
CasaAdminParameters.new(params).with_only(:email, :display_name, :phone_number, :monthly_learning_hours_report)
CasaAdminParameters.new(params).with_only(:email, :display_name, :phone_number, :date_of_birth, :monthly_learning_hours_report)
davidgumberg marked this conversation as resolved.
Show resolved Hide resolved
end

def learning_hours_checked?
Expand Down
4 changes: 2 additions & 2 deletions app/controllers/users_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,9 @@ def update_user_email

def user_params
if !current_user.casa_admin?
params.require(:user).permit(:display_name, :phone_number, :receive_sms_notifications, :receive_email_notifications, sms_notification_event_ids: [], address_attributes: [:id, :content])
params.require(:user).permit(:display_name, :phone_number, :date_of_birth, :receive_sms_notifications, :receive_email_notifications, sms_notification_event_ids: [], address_attributes: [:id, :content])
else
params.require(:user).permit(:email, :display_name, :phone_number, :receive_sms_notifications, :receive_email_notifications, sms_notification_event_ids: [], address_attributes: [:id, :content])
params.require(:user).permit(:email, :display_name, :phone_number, :date_of_birth, :receive_sms_notifications, :receive_email_notifications, sms_notification_event_ids: [], address_attributes: [:id, :content])
end
end

Expand Down
1 change: 1 addition & 0 deletions app/models/casa_admin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ def change_to_supervisor!
# confirmed_at :datetime
# current_sign_in_at :datetime
# current_sign_in_ip :string
# date_of_birth :datetime
# display_name :string default(""), not null
# email :string default(""), not null
# encrypted_password :string default(""), not null
Expand Down
1 change: 1 addition & 0 deletions app/models/supervisor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ def recently_unassigned_volunteers
# confirmed_at :datetime
# current_sign_in_at :datetime
# current_sign_in_ip :string
# date_of_birth :datetime
# display_name :string default(""), not null
# email :string default(""), not null
# encrypted_password :string default(""), not null
Expand Down
1 change: 1 addition & 0 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ def normalize_phone_number
# confirmed_at :datetime
# current_sign_in_at :datetime
# current_sign_in_ip :string
# date_of_birth :datetime
# display_name :string default(""), not null
# email :string default(""), not null
# encrypted_password :string default(""), not null
Expand Down
1 change: 1 addition & 0 deletions app/models/volunteer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ def cases_where_contact_made_in_days(num_days = CONTACT_MADE_IN_DAYS_NUM)
# confirmed_at :datetime
# current_sign_in_at :datetime
# current_sign_in_ip :string
# date_of_birth :datetime
# display_name :string default(""), not null
# email :string default(""), not null
# encrypted_password :string default(""), not null
Expand Down
7 changes: 7 additions & 0 deletions app/validators/user_validator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ def validate(record)
validate_presence(:display_name, record)
at_least_one_communication_preference_selected(record)
valid_phone_number_if_receive_sms_notifications(record)
valid_date_of_birth(record.date_of_birth, record)
end

private
Expand Down Expand Up @@ -36,4 +37,10 @@ def valid_phone_number_if_receive_sms_notifications(record)
record.errors.add(:base, " Must add a valid phone number to receive SMS notifications.")
end
end

def valid_date_of_birth(date_of_birth, record)
return unless date_of_birth.present?

record.errors.add(:base, " Date of birth must be in the past.") unless date_of_birth.past?
end
end
1 change: 1 addition & 0 deletions app/values/user_parameters.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ def initialize(params, key = :user)
:casa_org_id,
:display_name,
:phone_number,
:date_of_birth,
:password,
:active,
:receive_reimbursement_email,
Expand Down
12 changes: 12 additions & 0 deletions app/views/shared/_edit_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,18 @@
<% end %>
</div>

<div class="input-style-1">
<%= f.label :date_of_birth, "Date of birth" %>
<% if policy(resource).update_user_setting? %>
<%= f.text_field :date_of_birth,
value: resource.date_of_birth&.strftime("%Y/%m/%d"),
data: {provide: "datepicker", date_format: "yyyy/mm/dd"},
class: "form-control label-font-weight" %>
<% else %>
<input type="text" placeholder="<%= resource.date_of_birth&.strftime("%Y/%m/%d") %>" autocomplete="off" readonly>
<% end %>
</div>

<div class="form-check checkbox-style mb-20">
<%= f.check_box :receive_reimbursement_email, class: "form-check-input" %>
<%= f.label :receive_reimbursement_email, "Email Reimbursement Requests", class: "form-check-label" %>
Expand Down
8 changes: 8 additions & 0 deletions app/views/users/edit.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,14 @@
<%= form.text_field :phone_number, class: "form-control" %>
</div>

<div class="input-style-1">
<%= form.label :date_of_birth, "Date of birth" %>
<%= form.text_field :date_of_birth,
value: @user.date_of_birth&.strftime("%Y/%m/%d"),
davidgumberg marked this conversation as resolved.
Show resolved Hide resolved
data: {provide: "datepicker", date_format: "yyyy/mm/dd"},
class: "form-control label-font-weight" %>
</div>

<% if current_user.address %>
<% address = current_user.address %>
<% else %>
Expand Down
8 changes: 8 additions & 0 deletions app/views/volunteers/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,14 @@
<%= form.telephone_field :phone_number, placeholder: "Phone Number", class: "form-control" %>
</div>

<div class="input-style-1">
<%= form.label :date_of_birth, "Date of birth" %>
<%= form.text_field :date_of_birth,
value: @volunteer.date_of_birth&.strftime("%Y/%m/%d"),
davidgumberg marked this conversation as resolved.
Show resolved Hide resolved
data: {provide: "datepicker", date_format: "yyyy/mm/dd"},
davidgumberg marked this conversation as resolved.
Show resolved Hide resolved
class: "form-control label-font-weight" %>
</div>

<div class="actions">
<%= button_tag(
type: "submit",
Expand Down
5 changes: 5 additions & 0 deletions db/migrate/20231102181027_add_birthdays_to_users.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddBirthdaysToUsers < ActiveRecord::Migration[7.0]
def change
add_column :users, :date_of_birth, :datetime
end
end
3 changes: 2 additions & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema[7.0].define(version: 2023_09_03_182657) do
ActiveRecord::Schema[7.0].define(version: 2023_11_02_181027) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"

Expand Down Expand Up @@ -599,6 +599,7 @@
t.boolean "receive_reimbursement_email", default: false
t.string "token"
t.boolean "monthly_learning_hours_report", default: false, null: false
t.datetime "date_of_birth"
t.index ["casa_org_id"], name: "index_users_on_casa_org_id"
t.index ["confirmation_token"], name: "index_users_on_confirmation_token", unique: true
t.index ["email"], name: "index_users_on_email", unique: true
Expand Down