From 7107f9a35f12838bf9d1279c4ac54c9a167d5cbd Mon Sep 17 00:00:00 2001 From: nasia Date: Wed, 2 Aug 2017 20:10:47 +0300 Subject: [PATCH] Add emails for booth's acceptance and rejection --- .haml-lint_todo.yml | 2 ++ .rubocop_todo.yml | 1 + app/controllers/admin/booths_controller.rb | 24 +++++++++++++++++-- app/controllers/admin/emails_controller.rb | 4 +++- app/mailers/mailbot.rb | 18 ++++++++++++++ app/models/email_settings.rb | 11 ++++++++- .../booths/_change_state_dropdown.html.haml | 18 ++++++++++---- app/views/admin/emails/_help.html.haml | 8 ++++++- app/views/admin/emails/index.html.haml | 22 +++++++++++++++++ ...0731161207_add_booths_to_email_settings.rb | 10 ++++++++ db/schema.rb | 6 +++++ 11 files changed, 114 insertions(+), 10 deletions(-) create mode 100644 db/migrate/20170731161207_add_booths_to_email_settings.rb diff --git a/.haml-lint_todo.yml b/.haml-lint_todo.yml index b7a18be0..4ec5de3c 100644 --- a/.haml-lint_todo.yml +++ b/.haml-lint_todo.yml @@ -303,6 +303,7 @@ linters: SpaceInsideHashAttributes: exclude: - "app/views/admin/conferences/_todo_list.html.haml" + - "app/views/admin/emails/index.html.haml" - "app/views/admin/questions/_form.html.haml" - "app/views/admin/questions/index.html.haml" - "app/views/admin/registrations/index.html.haml" @@ -403,6 +404,7 @@ linters: # Offense count: 14 ConsecutiveSilentScripts: exclude: + - "app/views/admin/booths/_change_state_dropdown.html.haml" - "app/views/admin/events/index.html.haml" - "app/views/admin/schedules/_day_tab.html.haml" - "app/views/admin/schedules/_event.html.haml" diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 487a9fdb..38bf269f 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -450,6 +450,7 @@ Style/IfUnlessModifier: - 'app/helpers/application_helper.rb' - 'app/models/commercial.rb' - 'app/models/conference.rb' + - 'app/models/email_settings.rb' - 'app/models/ticket_purchase.rb' - 'app/models/user.rb' - 'db/migrate/20151031092713_change_conference_id_to_venue_id_in_rooms.rb' diff --git a/app/controllers/admin/booths_controller.rb b/app/controllers/admin/booths_controller.rb index e5b55552..a200e42e 100644 --- a/app/controllers/admin/booths_controller.rb +++ b/app/controllers/admin/booths_controller.rb @@ -47,7 +47,18 @@ module Admin end def accept - update_state(:accept, 'Booth accepted!') + @booth.accept! + + if @booth.save + if @conference.email_settings.send_on_booths_acceptance + Mailbot.conference_booths_acceptance_mail(@booth).deliver + end + redirect_to admin_conference_booths_path(conference_id: @conference.short_title), + notice: 'Booth successfully accepted!' + else + redirect_to admin_conference_booths_path(conference_id: @conference.short_title) + flash[:error] = "Booth could not be accepted. #{@booth.errors.full_messages.to_sentence}." + end end def to_accept @@ -59,7 +70,16 @@ module Admin end def reject - update_state(:reject, 'Booth rejected') + @booth.reject! + + if @booth.save + Mailbot.conference_booths_rejection_mail(@booth).deliver + redirect_to admin_conference_booths_path(conference_id: @conference.short_title), + notice: 'Booth successfully rejected.' + else + redirect_to admin_conference_booths_path(conference_id: @conference.short_title) + flash[:error] = "Booth could not be rejected. #{@booth.errors.full_messages.to_sentence}." + end end def restart diff --git a/app/controllers/admin/emails_controller.rb b/app/controllers/admin/emails_controller.rb index adff714a..a4d6fe04 100644 --- a/app/controllers/admin/emails_controller.rb +++ b/app/controllers/admin/emails_controller.rb @@ -30,7 +30,9 @@ module Admin :send_on_conference_registration_dates_updated, :conference_registration_dates_updated_subject, :conference_registration_dates_updated_body, :send_on_venue_updated, :venue_updated_subject, :venue_updated_body, :send_on_cfp_dates_updated, :cfp_dates_updated_subject, :cfp_dates_updated_body, - :send_on_program_schedule_public, :program_schedule_public_subject, :program_schedule_public_body) + :send_on_program_schedule_public, :program_schedule_public_subject, :program_schedule_public_body, + :send_on_booths_acceptance, :booths_acceptance_subject, :booths_acceptance_body, + :send_on_booths_rejection, :booths_rejection_subject, :booths_rejection_body) end end end diff --git a/app/mailers/mailbot.rb b/app/mailers/mailbot.rb index 837e2c1e..63f95a40 100644 --- a/app/mailers/mailbot.rb +++ b/app/mailers/mailbot.rb @@ -97,6 +97,24 @@ class Mailbot < ActionMailer::Base conference.email_settings.cfp_dates_updated_body)) end + def conference_booths_acceptance_mail(booth) + conference = booth.conference + + mail(to: booth.submitter.email, + from: conference.contact.email, + subject: conference.email_settings.booths_acceptance_subject, + body: conference.email_settings.generate_booth_mail(booth, conference.email_settings.booths_acceptance_body)) + end + + def conference_booths_rejection_mail(booth) + conference = booth.conference + + mail(to: booth.submitter.email, + from: conference.contact.email, + subject: conference.email_settings.booths_rejection_subject, + body: conference.email_settings.generate_booth_mail(booth, conference.email_settings.booths_rejection_body)) + end + def event_comment_mail(comment, user) @comment = comment @event = @comment.commentable diff --git a/app/models/email_settings.rb b/app/models/email_settings.rb index 6d6c4478..6210cf9d 100644 --- a/app/models/email_settings.rb +++ b/app/models/email_settings.rb @@ -3,7 +3,7 @@ class EmailSettings < ActiveRecord::Base has_paper_trail on: [:update], ignore: [:updated_at], meta: { conference_id: :conference_id } - def get_values(conference, user, event = nil) + def get_values(conference, user, event = nil, booth = nil) h = { 'email' => user.email, 'name' => user.name, @@ -45,6 +45,10 @@ class EmailSettings < ActiveRecord::Base h['proposalslink'] = Rails.application.routes.url_helpers.conference_program_proposals_url( conference.short_title, host: (ENV['OSEM_HOSTNAME'] || 'localhost:3000')) end + + if booth + h['booth_title'] = booth.title + end h end @@ -58,6 +62,11 @@ class EmailSettings < ActiveRecord::Base parse_template(conf_update_template, values) end + def generate_booth_mail(booth, booth_template) + values = get_values(booth.conference, booth.submitter, nil, booth) + parse_template(booth_template, values) + end + private def parse_template(text, values) diff --git a/app/views/admin/booths/_change_state_dropdown.html.haml b/app/views/admin/booths/_change_state_dropdown.html.haml index c0418d67..8178a790 100644 --- a/app/views/admin/booths/_change_state_dropdown.html.haml +++ b/app/views/admin/booths/_change_state_dropdown.html.haml @@ -1,17 +1,25 @@ - if booth.transition_possible? :accept - %li= link_to 'Accept booth', + - if @conference.email_settings.send_on_booths_acceptance + - link = 'Accept with email' + - else + - link = 'Accept booth' + %li= link_to link, accept_admin_conference_booth_path(@conference.short_title, booth), - method: :patch, id: "accept_booth_#{booth.id}" + method: :patch ,id: "accept_booth_#{booth.id}" - if booth.transition_possible? :reject - %li= link_to 'Reject booth', + - if @conference.email_settings.send_on_booths_rejection + - link = 'Reject with email' + - else + - link = 'Reject' + %li= link_to link, reject_admin_conference_booth_path(@conference.short_title, booth), - method: :patch, confirm: 'Are you sure?', id: "reject_booth_#{booth.id}" + method: :patch, id: "reject_booth_#{booth.id}" - if booth.transition_possible? :to_reject %li= link_to 'To reject booth', to_reject_admin_conference_booth_path(@conference.short_title, booth), - method: :patch, confirm: 'Are you sure?', id: "to_reject_booth_#{booth.id}" + method: :patch, id: "to_reject_booth_#{booth.id}" - if booth.transition_possible? :restart %li= link_to 'Start review', diff --git a/app/views/admin/emails/_help.html.haml b/app/views/admin/emails/_help.html.haml index 535cd097..371bac7b 100644 --- a/app/views/admin/emails/_help.html.haml +++ b/app/views/admin/emails/_help.html.haml @@ -55,4 +55,10 @@ %tr %td {conference_splash_link} %td The link to conference splash page - + - if @conference.booths + %tr + %td {submitter_name} + %td Submitter's name + %tr + %td {booth_title} + %td Booth's title diff --git a/app/views/admin/emails/index.html.haml b/app/views/admin/emails/index.html.haml index 4b380b86..99d02130 100644 --- a/app/views/admin/emails/index.html.haml +++ b/app/views/admin/emails/index.html.haml @@ -14,6 +14,8 @@ %a{ 'aria-controls' => 'notifications', 'data-toggle' => 'tab', href: '#notifications', role: 'tab' } Update Notifications %li{ role: 'presentation' } %a{ 'aria-controls' => 'cfp', 'data-toggle' => 'tab', href: '#cfp', role: 'tab' } Call for Papers + %li{ role: 'presentation' } + %a{ 'aria-controls' => 'booths', 'data-toggle' => 'tab', href: '#booth', role: 'tab' } Booth / Tab panes .tab-content #onboarding.tab-pane.active{ role: 'tabpanel' } @@ -100,6 +102,26 @@ 'data-body-text' => "Dear {name},\n\nThe Conference Call for Papers Details of {conference} has changed.\nNew Dates : {cfp_start_date} - {cfp_end_date}.\n Link to Schedule {schedule_link} \n\nBest wishes\n\n{conference} Team" } Load Template %a.btn.btn-link.control_label.template_help_link{ 'data-name' => 'updated_cfp_help' } Show Help = render partial: 'help', locals: {id: 'updated_cfp_help', show_event_variables: false} + #booth.tab-pane{ role: 'tabpanel' } + = f.input :send_on_booths_acceptance + = f.input :booths_acceptance_subject + = f.input :booths_acceptance_body, input_html: { rows:10, cols: 20 } + %a.btn.btn-link.control_label.load_template{ 'data-subject-input-id' => 'email_settings_booths_acceptance_subject', + 'data-subject-text' => 'Your booth has been accepted!', + 'data-body-input-id' => 'email_settings_booths_acceptance_body', + 'data-body-text' => "Dear {name},\n\nWe are really pleased to inform you that your booth request {booth_title} has been accepted for the conference {conference}.\nPlease click the confirm button to let us know you can make it as soon as possible!\n\nFeel free to contact us with any questions or concerns.\n\nWe look forward to seeing you there.\n\nBest wishes\n\n{conference} Team"} Load Template + %a.btn.btn-link.control_label.template_help_link{ 'data-name' => 'booth_acceptance_help' } Show help + = render partial: 'help', locals: {id: 'booth_acceptance_help', show_event_variables: false} + = f.input :send_on_booths_rejection + = f.input :booths_rejection_subject + = f.input :booths_rejection_body, input_html: { rows:10, cols:20 } + %a.btn.btn-link.control_label.load_template{ 'data-subject-input-id' => 'email_settings_booths_rejection_subject', + 'data-subject-text' => 'Your booth request has been rejected', + 'data-body-input-id' => 'email_settings_booths_rejection_body', + 'data-body-text' => "Dear {name},\n\nThank you for your booth request {booth_title} for the conference {conference}.\n\nUnfortunately, we are sorry to inform you that your request has been rejected.\n\n\nBest wishes\n\n{conference} Team" } Load Template + %a.btn.btn-link.control_label.template_help_link{ 'data-name' => 'booth_rejection_help' } Show help + = render partial: 'help', locals: {id: 'booth_rejection_help', show_event_variables: false} + .row .col-md-12 = f.action :submit, as: :button, button_html: { class: 'btn btn-primary' } diff --git a/db/migrate/20170731161207_add_booths_to_email_settings.rb b/db/migrate/20170731161207_add_booths_to_email_settings.rb new file mode 100644 index 00000000..0b3a7a87 --- /dev/null +++ b/db/migrate/20170731161207_add_booths_to_email_settings.rb @@ -0,0 +1,10 @@ +class AddBoothsToEmailSettings < ActiveRecord::Migration + def change + add_column :email_settings, :send_on_booths_acceptance, :boolean, default: false + add_column :email_settings, :booths_acceptance_subject, :string + add_column :email_settings, :booths_acceptance_body, :text + add_column :email_settings, :send_on_booths_rejection, :boolean, default: false + add_column :email_settings, :booths_rejection_subject, :string + add_column :email_settings, :booths_rejection_body, :text + end +end diff --git a/db/schema.rb b/db/schema.rb index 9e6123a3..6cc32e82 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -205,6 +205,12 @@ ActiveRecord::Schema.define(version: 20170807092805) do t.string "cfp_dates_updated_subject" t.text "program_schedule_public_body" t.text "cfp_dates_updated_body" + t.boolean "send_on_booths_acceptance", default: false + t.string "booths_acceptance_subject" + t.text "booths_acceptance_body" + t.boolean "send_on_booths_rejection", default: false + t.string "booths_rejection_subject" + t.text "booths_rejection_body" end create_table "event_schedules", force: :cascade do |t|