Skip to content

Commit

Permalink
Granular notify changes, improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
afleishaker committed Jan 14, 2021
1 parent b657619 commit bc8e593
Show file tree
Hide file tree
Showing 9 changed files with 74 additions and 55 deletions.
2 changes: 1 addition & 1 deletion app/controllers/events_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,6 @@ def set_event

# Only allow a list of trusted parameters through.
def event_params
params.require(:event).permit(:title, :description, :startDate, :startTime, :endDate, :endTime, :location, :eventType, :published, :users, :use_email, :use_call, :use_text, :use_app)
params.require(:event).permit(:title, :description, :startDate, :startTime, :endDate, :endTime, :location, :eventType, :published, :notify, :users, :use_email, :use_call, :use_text, :use_app)
end
end
101 changes: 53 additions & 48 deletions app/helpers/events_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def get_event_html_body(event, attending_count, is_on_show)
else
if is_on_show
event.users.each do |user|
users_html += "<p class='card-text pt-2'><strong>#{get_full_name(user)}</strong></p>" + get_user_html_body(user, EventStatus.find_by(user_id: user.id, event_id: event.id))
users_html += "<p class='card-text pt-2'><strong>#{get_full_name(user)}</strong></p>" + get_user_html_body(user, EventStatus.find_by(user_id: user.id, event_id: event.id))
end
end
attendance_display_html = "#{attending_count} #{I18n.t("global.attending").downcase}"
Expand All @@ -67,17 +67,17 @@ def get_event_html_body(event, attending_count, is_on_show)
end

"#{!event.description.blank? ?
"<p class='card-text'><strong>#{I18n.t("events.description")}:</strong> #{with_urls(event.description)}</p>" :
""}
"<p class='card-text'><strong>#{I18n.t("events.description")}:</strong> #{with_urls(event.description)}</p>" :
""}
#{!get_when_text(event).blank? ?
"<p class='card-text'><strong>#{I18n.t("events.when")}:</strong> #{with_urls(get_when_text(event))}</p>" :
""}
"<p class='card-text'><strong>#{I18n.t("events.when")}:</strong> #{with_urls(get_when_text(event))}</p>" :
""}
#{!event.location.blank? ?
"<p class='card-text'><strong>#{I18n.t("events.where")}:</strong> #{with_urls(event.location)}</p>" :
""}
"<p class='card-text'><strong>#{I18n.t("events.where")}:</strong> #{with_urls(event.location)}</p>" :
""}
#{attendance_display_html}
#{users_html}"
.html_safe
.html_safe
end

def get_event_html_buttons(event, is_on_show)
Expand All @@ -90,8 +90,8 @@ def get_event_html_buttons(event, is_on_show)
<div class='btn-group btn-group-md' role='group'>"
if moderator_signed_in?(current_user)
button_html += "#{link_to I18n.t("global.delete"), event, class: "btn btn-danger", method: :delete, data: { confirm: I18n.t("global.are_you_sure") }}
#{link_to I18n.t("global.edit"), edit_event_path(event), class: "btn btn-secondary"}
#{tertiary_button}
#{link_to I18n.t("global.edit"), edit_event_path(event), class: "btn btn-secondary"}
#{tertiary_button}
</div>
</div>"
else
Expand Down Expand Up @@ -141,10 +141,10 @@ def get_attending_counts(event)
event.users.each do |user|
status = EventStatus.find_by(user_id: user.id, event_id: event.id)
if !status.blank? && status.attending?
attending_count += 1
attending_count += 1
end
end
attending_count
attending_count
end

##
Expand Down Expand Up @@ -188,16 +188,18 @@ def get_event_text_params(event, uses_email)
# event - an event
# status - a status
def set_new_state_after_notify(was_successful, event, status)
if was_successful
if event.event?
status.not_responded!
unless status.attending?
if was_successful
if event.event?
status.not_responded!
else
status.delivered!
end
else
status.delivered!
status.not_delivered!
end
else
status.not_delivered!
status.save
end
status.save
end

##
Expand Down Expand Up @@ -227,15 +229,17 @@ def handle_send_publish_event_notification(event, user, status, contact)
end
# Otherwise, they aren't new, don't update their state, send as updated event
else
if contact == "email"
UserMailer.event_update_email(user, event).deliver rescue user
else
if contact == "text"
prompt = (event.event? ? t('texts.updated_prompt', id: event.id, yes: t('texts.text_yes'), no: t('texts.text_no')) : "")
TwilioHandler.new.send_text(user, t('texts.updated_event', params: get_event_text_params(event, false), type: event.eventType.capitalize, prompt: prompt))
if event.notify?
if contact == "email"
UserMailer.event_update_email(user, event).deliver rescue user
else
prompt = (event.event? ? t('texts.updated_prompt', id: event.id.to_s.chars.join(' '), yes: " #{t('texts.call_yes')} #{t('texts.pound')}", no: " #{t('texts.call_no')} #{t('texts.pound')}") : "")
TwilioHandler.new.send_call(user, t('texts.updated_event', params: get_event_text_params(event, false), type: event.eventType.capitalize, prompt: prompt))
if contact == "text"
prompt = (event.event? ? t('texts.updated_prompt', id: event.id, yes: t('texts.text_yes'), no: t('texts.text_no')) : "")
TwilioHandler.new.send_text(user, t('texts.updated_event', params: get_event_text_params(event, false), type: event.eventType.capitalize, prompt: prompt))
else
prompt = (event.event? ? t('texts.updated_prompt', id: event.id.to_s.chars.join(' '), yes: " #{t('texts.call_yes')} #{t('texts.pound')}", no: " #{t('texts.call_no')} #{t('texts.pound')}") : "")
TwilioHandler.new.send_call(user, t('texts.updated_event', params: get_event_text_params(event, false), type: event.eventType.capitalize, prompt: prompt))
end
end
end
end
Expand All @@ -248,36 +252,37 @@ def handle_send_publish_event_notification(event, user, status, contact)
# user - a user
# status - a status
def send_publish_event_notification(event, user, status)
if !user.confirmed? && !user.confirmed_text? && !user.confirmed_call?
success = true
if user.use_email? && user.confirmed? && event.use_email?
success = handle_send_publish_event_notification(event, user, status, "email")
end
if user.use_text? && user.confirmed_text? && event.use_text?
success = handle_send_publish_event_notification(event, user, status, "text")
end
if user.use_call? && user.confirmed_call? && event.use_call?
success = handle_send_publish_event_notification(event, user, status, "call")
end
unless success
status.not_delivered!
else
success = true
if user.use_email? && user.confirmed? && event.use_email?
success = handle_send_publish_event_notification(event, user, status, "email")
end
if user.use_text? && user.confirmed_text? && event.use_text?
success = handle_send_publish_event_notification(event, user, status, "text")
end
if user.use_call? && user.confirmed_call? && event.use_call?
success = handle_send_publish_event_notification(event, user, status, "call")
end
set_new_state_after_notify(success, event, status)
end
set_new_state_after_notify(success, event, status)
end

##
# Sends notification of a deleted event to a given user
# event - an event
# user - a user
def send_delete_event_notification(event, user)
if user.use_email? && user.confirmed? && event.use_email?
UserMailer.event_delete_email(user, event).deliver rescue user
end
if user.use_text? && user.confirmed_text? && event.use_text?
success, error = TwilioHandler.new.send_text(user, t('texts.deleted_event', params: get_event_text_params(event, false), type: event.eventType.capitalize))
end
if user.use_call? && user.confirmed_call? && event.use_call?
success, error = TwilioHandler.new.send_call(user, t('texts.deleted_event', params: get_event_text_params(event, false), type: event.eventType.capitalize))
if event.notify?
if user.use_email? && user.confirmed? && event.use_email?
UserMailer.event_delete_email(user, event).deliver rescue user
end
if user.use_text? && user.confirmed_text? && event.use_text?
success, error = TwilioHandler.new.send_text(user, t('texts.deleted_event', params: get_event_text_params(event, false), type: event.eventType.capitalize))
end
if user.use_call? && user.confirmed_call? && event.use_call?
success, error = TwilioHandler.new.send_call(user, t('texts.deleted_event', params: get_event_text_params(event, false), type: event.eventType.capitalize))
end
end
end

Expand Down
6 changes: 6 additions & 0 deletions app/views/events/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,12 @@
<% end %>
</div>

<div class="col-12">
<%= f.form_group do %>
<%= f.check_box :notify, custom: :switch, control_class: "text-secondary", label: I18n.t("events.notify_changes") %>
<% end %>
</div>

</div>
<div class='btn-group mb-1' role='group'>
<%= f.submit I18n.t("global.submit") %>
Expand Down
2 changes: 1 addition & 1 deletion config/locales/presets/devise.es.yml
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ es:
signed_up: Bienvenido. Tu cuenta fue creada.
signed_up_but_inactive: Tu cuenta ha sido creada correctamente. Sin embargo, no hemos podido iniciar la sesi贸n porque tu cuenta a煤n no est谩 activada.
signed_up_but_locked: Tu cuenta ha sido creada correctamente. Sin embargo, no hemos podido iniciar la sesi贸n porque que tu cuenta est谩 bloqueada.
signed_up_but_unconfirmed: Se ha enviado un mensaje con un enlace de confirmaci贸n a tu correo electr贸nico. Abre el enlace para activar tu cuenta.
signed_up_but_unconfirmed: Se ha enviado un mensaje con un enlace de confirmaci贸n a su m茅todo de contacto. Siga el enlace para activar su cuenta.
update_needs_confirmation: Has actualizado tu cuenta correctamente, pero es necesario confirmar tu nuevo correo electr贸nico. Por favor, comprueba tu correo y sigue el enlace de confirmaci贸n para finalizar la comprobaci贸n del nuevo correo electr贸nico.
updated: Tu cuenta se ha actualizado.
updated_but_not_signed_in: Su cuenta se ha actualizado correctamente, pero como se cambi贸 su contrase帽a, debe iniciar sesi贸n nuevamente
Expand Down
3 changes: 2 additions & 1 deletion config/locales/presets/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ en:
location: "Location"
type: "Type"
published: "Published"
notify_changes: "Notify changes"
event: "Event"
info: "Info"
message: "Message"
Expand Down Expand Up @@ -215,7 +216,7 @@ en:
sessions:
new:
login: "Login"
login_prompt: "Please login below using your username, email, or phone number."
login_prompt: "Please login below using your email."
passwords:
title: "Forgot your password?"
button: "Resend me reset password instructions"
Expand Down
3 changes: 2 additions & 1 deletion config/locales/presets/es.yml
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ es:
location: "Sitio"
type: "Tipo"
published: "Publicado"
notify_changes: "Notificar cambios"
event: "Evento"
info: "Informaci贸n"
message: "Mensaje"
Expand Down Expand Up @@ -215,7 +216,7 @@ es:
sessions:
new:
login: "Iniciar sesi贸n"
login_prompt: "Inicie sesi贸n a continuaci贸n utilizando su nombre de usuario, correo electr贸nico o n煤mero de tel茅fono."
login_prompt: "Inicie sesi贸n a continuaci贸n utilizando su correo electr贸nico."
passwords:
title: "驴Olvidaste tu contrase帽a?"
button: "Reenviarme las instrucciones para restablecer la contrase帽a"
Expand Down
5 changes: 5 additions & 0 deletions db/migrate/20210114090813_add_notify_flag.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddNotifyFlag < ActiveRecord::Migration[6.0]
def change
add_column :events, :notify, :boolean, null: false, default: false
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.define(version: 2020_07_21_054514) do
ActiveRecord::Schema.define(version: 2021_01_14_090813) do

# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
Expand Down Expand Up @@ -61,6 +61,7 @@
t.boolean "use_text", default: false
t.boolean "use_call", default: false
t.boolean "use_app", default: false
t.boolean "notify", default: false, null: false
end

create_table "group_memberships", force: :cascade do |t|
Expand Down
4 changes: 2 additions & 2 deletions org_init.rb
Original file line number Diff line number Diff line change
Expand Up @@ -557,7 +557,7 @@ def get_heroku_app_name(name)
begin
@config["config"]["app_name"] = @prompt.ask(prompt_box(name_prompt), default: name, required: true) { |q| q.validate /^[a-z0-9]+$/m, "Must be lowercase alphanumeric only" }
name = @config["config"]["app_name"]
@cmd.run("heroku #{command_case} #{name}")
@cmd.run("heroku #{command_case} #{name} #{command_case == "create" ? "--stack heroku-18" : ""}")
app_not_found = false
rescue TTY::Command::ExitError
error_box("App #{command_case} failed. Please try a different name.")
Expand All @@ -568,7 +568,7 @@ def get_heroku_app_name(name)
begin
@config["config"]["app_name"] = get_argument_value("heroku_app_name", true, nil)
name = @config["config"]["app_name"]
@cmd.run("heroku #{command_case} #{name}")
@cmd.run("heroku #{command_case} #{name} #{command_case == "create" ? "--stack heroku-18" : ""}")
rescue TTY::Command::ExitError
error_box("App #{command_case} failed.")
raise ArgumentError
Expand Down

0 comments on commit bc8e593

Please sign in to comment.