From e8013d83451fa1b455aefd7ce620801ddaff8570 Mon Sep 17 00:00:00 2001 From: rajavi-mishra Date: Fri, 5 Mar 2021 03:35:29 -0800 Subject: [PATCH 01/18] stylesheet, layout and rendering for email_template (test) --- app/assets/stylesheets/mailbot.css | 40 ++++++++++ app/views/layouts/_mailbot_footer.html.haml | 9 +++ app/views/layouts/_mailbot_header.html.haml | 19 +++++ app/views/mailbot/email_template.erb | 81 +-------------------- 4 files changed, 72 insertions(+), 77 deletions(-) create mode 100644 app/assets/stylesheets/mailbot.css create mode 100644 app/views/layouts/_mailbot_footer.html.haml create mode 100644 app/views/layouts/_mailbot_header.html.haml diff --git a/app/assets/stylesheets/mailbot.css b/app/assets/stylesheets/mailbot.css new file mode 100644 index 00000000..870eb7ef --- /dev/null +++ b/app/assets/stylesheets/mailbot.css @@ -0,0 +1,40 @@ +html { + scroll-behavior: smooth; + } + + body { + background: #fff; + box-shadow: 0 0 2px rgba(0, 0, 0, 0.06); + color: #000; + font-family: 'Montserrat', sans-serif; + font-size: 16px; + line-height: 1.5; + margin: 0 auto; + } + + h1, + h3, + h4, + h5, + h6 { + font-weight: 400; + line-height: 1.3; + } + p { + color: #0B3559; + font-weight: 400; + line-height: 2; + } + + #border { + background-color: #0B3559; + padding: 25px; + color:#fff; + } + + #content { + background-color: #fff; + padding: 100px; + color: #0B3559; + } + \ No newline at end of file diff --git a/app/views/layouts/_mailbot_footer.html.haml b/app/views/layouts/_mailbot_footer.html.haml new file mode 100644 index 00000000..f086135d --- /dev/null +++ b/app/views/layouts/_mailbot_footer.html.haml @@ -0,0 +1,9 @@ +%html{lang: 'en'} + %head + %meta{charset: 'utf-8'} + %meta{name: 'viewport', content: 'width=device-width, initial-scale=1'} + %meta{content: 'Snap!Con -- A conference all about Snap!, a programing language from UC Berkeley.', name: 'description'} + %meta{content: 'Michael Ball, Brian Harvey, Jens Moenig, Bernat Romagosa, Dan Garcia, Lauren Mock', name: 'author'} + = stylesheet_link_tag "mailbot" + %body + #border \ No newline at end of file diff --git a/app/views/layouts/_mailbot_header.html.haml b/app/views/layouts/_mailbot_header.html.haml new file mode 100644 index 00000000..1492a469 --- /dev/null +++ b/app/views/layouts/_mailbot_header.html.haml @@ -0,0 +1,19 @@ +%html{lang: 'en'} + %head + %meta{charset: 'utf-8'} + %meta{name: 'viewport', content: 'width=device-width, initial-scale=1'} + %title= 'Email' + %meta{content: 'Snap!Con -- A conference all about Snap!, a programing language from UC Berkeley.', name: 'description'} + %meta{content: 'Michael Ball, Brian Harvey, Jens Moenig, Bernat Romagosa, Dan Garcia, Lauren Mock', name: 'author'} + = stylesheet_link_tag "mailbot" + %body + #border + .row + .col-md-2 + - if !@logo.nil? + = image_tag(@logo, style: "display:block") + .col-md-10 + %h1 + #content + %span{:style => "white-space: pre-line"} + \ No newline at end of file diff --git a/app/views/mailbot/email_template.erb b/app/views/mailbot/email_template.erb index 429553be..9834d3fc 100644 --- a/app/views/mailbot/email_template.erb +++ b/app/views/mailbot/email_template.erb @@ -1,77 +1,4 @@ - - - - - - - - - - - - - - Email - - -
-
- -
- <% if !@logo.nil? %> - <%= image_tag(@logo, style: "display:block") %> - <% end %> -
-

-
-
-
- - <%= @email_body %> - -
-
-

-
- - += render "layouts/_mailbot_header" + = @email_body += render "layouts/_mailbot_footer" + \ No newline at end of file From 9dc3ac6bca2250b8f8954a2ef1f896c4ef5454c7 Mon Sep 17 00:00:00 2001 From: rajavi-mishra Date: Fri, 5 Mar 2021 03:41:41 -0800 Subject: [PATCH 02/18] change file type --- .../mailbot/{email_template.erb => email_template.html.haml} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename app/views/mailbot/{email_template.erb => email_template.html.haml} (100%) diff --git a/app/views/mailbot/email_template.erb b/app/views/mailbot/email_template.html.haml similarity index 100% rename from app/views/mailbot/email_template.erb rename to app/views/mailbot/email_template.html.haml From 7bccf277909ad9bbd3d7f9cd89c5ffdde7e109fa Mon Sep 17 00:00:00 2001 From: rajavi-mishra Date: Fri, 5 Mar 2021 09:02:02 -0800 Subject: [PATCH 03/18] change to erb --- app/views/mailbot/email_template.html.erb | 5 +++++ app/views/mailbot/email_template.html.haml | 4 ---- 2 files changed, 5 insertions(+), 4 deletions(-) create mode 100644 app/views/mailbot/email_template.html.erb delete mode 100644 app/views/mailbot/email_template.html.haml diff --git a/app/views/mailbot/email_template.html.erb b/app/views/mailbot/email_template.html.erb new file mode 100644 index 00000000..41e0b0e6 --- /dev/null +++ b/app/views/mailbot/email_template.html.erb @@ -0,0 +1,5 @@ +<%= render "layouts/_mailbot_header" %> + <%= @email_body %> +<% end %> +<%= render "layouts/_mailbot_footer" %> + \ No newline at end of file diff --git a/app/views/mailbot/email_template.html.haml b/app/views/mailbot/email_template.html.haml deleted file mode 100644 index 9834d3fc..00000000 --- a/app/views/mailbot/email_template.html.haml +++ /dev/null @@ -1,4 +0,0 @@ -= render "layouts/_mailbot_header" - = @email_body -= render "layouts/_mailbot_footer" - \ No newline at end of file From 26bb7fcdca5d3a2c219d6a664b9371289cd08713 Mon Sep 17 00:00:00 2001 From: rajavi-mishra Date: Fri, 5 Mar 2021 09:12:52 -0800 Subject: [PATCH 04/18] change layouts to erb --- app/views/layouts/_mailbot_footer.html.erb | 12 +++++++++ app/views/layouts/_mailbot_header.html.erb | 31 ++++++++++++++++++++++ 2 files changed, 43 insertions(+) create mode 100644 app/views/layouts/_mailbot_footer.html.erb create mode 100644 app/views/layouts/_mailbot_header.html.erb diff --git a/app/views/layouts/_mailbot_footer.html.erb b/app/views/layouts/_mailbot_footer.html.erb new file mode 100644 index 00000000..fe304c9d --- /dev/null +++ b/app/views/layouts/_mailbot_footer.html.erb @@ -0,0 +1,12 @@ + + + + + + + <%= stylesheet_link_tag "mailbot" %> + + +
+ + \ No newline at end of file diff --git a/app/views/layouts/_mailbot_header.html.erb b/app/views/layouts/_mailbot_header.html.erb new file mode 100644 index 00000000..cc968b80 --- /dev/null +++ b/app/views/layouts/_mailbot_header.html.erb @@ -0,0 +1,31 @@ + + + + + + <%= 'Email' %> + + + + <%= stylesheet_link_tag "mailbot" %> + + +
+
+
+ <% if !@logo.nil? %> + <%= image_tag(@logo, style: "display:block") %> + <% end %> +
+
+

+
+
+
+
+ +
+ + + + \ No newline at end of file From c97b081b2cf13711e16393ef6391f13cbd4c23c0 Mon Sep 17 00:00:00 2001 From: Jimmy Date: Fri, 5 Mar 2021 09:30:01 -0800 Subject: [PATCH 05/18] FOR DEMO ONLY --- app/models/registration.rb | 2 +- app/views/layouts/_mailbot_footer.html.erb | 2 ++ app/views/layouts/_mailbot_footer.html.haml | 9 --------- app/views/layouts/_mailbot_header.html.erb | 4 +--- app/views/layouts/_mailbot_header.html.haml | 19 ------------------- app/views/mailbot/email_template.html.erb | 10 +++++----- config/environments/development.rb | 1 + 7 files changed, 10 insertions(+), 37 deletions(-) delete mode 100644 app/views/layouts/_mailbot_footer.html.haml delete mode 100644 app/views/layouts/_mailbot_header.html.haml diff --git a/app/models/registration.rb b/app/models/registration.rb index 3906f558..d220e49f 100644 --- a/app/models/registration.rb +++ b/app/models/registration.rb @@ -69,7 +69,7 @@ class Registration < ApplicationRecord def send_registration_mail if conference.email_settings.send_on_registration? - Mailbot.registration_mail(conference, user).deliver_later + Mailbot.registration_mail(conference, user).deliver_now end end diff --git a/app/views/layouts/_mailbot_footer.html.erb b/app/views/layouts/_mailbot_footer.html.erb index fe304c9d..4f479cc7 100644 --- a/app/views/layouts/_mailbot_footer.html.erb +++ b/app/views/layouts/_mailbot_footer.html.erb @@ -7,6 +7,8 @@ <%= stylesheet_link_tag "mailbot" %> + +
\ No newline at end of file diff --git a/app/views/layouts/_mailbot_footer.html.haml b/app/views/layouts/_mailbot_footer.html.haml deleted file mode 100644 index f086135d..00000000 --- a/app/views/layouts/_mailbot_footer.html.haml +++ /dev/null @@ -1,9 +0,0 @@ -%html{lang: 'en'} - %head - %meta{charset: 'utf-8'} - %meta{name: 'viewport', content: 'width=device-width, initial-scale=1'} - %meta{content: 'Snap!Con -- A conference all about Snap!, a programing language from UC Berkeley.', name: 'description'} - %meta{content: 'Michael Ball, Brian Harvey, Jens Moenig, Bernat Romagosa, Dan Garcia, Lauren Mock', name: 'author'} - = stylesheet_link_tag "mailbot" - %body - #border \ No newline at end of file diff --git a/app/views/layouts/_mailbot_header.html.erb b/app/views/layouts/_mailbot_header.html.erb index cc968b80..0c29963f 100644 --- a/app/views/layouts/_mailbot_header.html.erb +++ b/app/views/layouts/_mailbot_header.html.erb @@ -24,8 +24,6 @@
-
- - + \ No newline at end of file diff --git a/app/views/layouts/_mailbot_header.html.haml b/app/views/layouts/_mailbot_header.html.haml deleted file mode 100644 index 1492a469..00000000 --- a/app/views/layouts/_mailbot_header.html.haml +++ /dev/null @@ -1,19 +0,0 @@ -%html{lang: 'en'} - %head - %meta{charset: 'utf-8'} - %meta{name: 'viewport', content: 'width=device-width, initial-scale=1'} - %title= 'Email' - %meta{content: 'Snap!Con -- A conference all about Snap!, a programing language from UC Berkeley.', name: 'description'} - %meta{content: 'Michael Ball, Brian Harvey, Jens Moenig, Bernat Romagosa, Dan Garcia, Lauren Mock', name: 'author'} - = stylesheet_link_tag "mailbot" - %body - #border - .row - .col-md-2 - - if !@logo.nil? - = image_tag(@logo, style: "display:block") - .col-md-10 - %h1 - #content - %span{:style => "white-space: pre-line"} - \ No newline at end of file diff --git a/app/views/mailbot/email_template.html.erb b/app/views/mailbot/email_template.html.erb index 41e0b0e6..fd8ae362 100644 --- a/app/views/mailbot/email_template.html.erb +++ b/app/views/mailbot/email_template.html.erb @@ -1,5 +1,5 @@ -<%= render "layouts/_mailbot_header" %> - <%= @email_body %> -<% end %> -<%= render "layouts/_mailbot_footer" %> - \ No newline at end of file +<%= render partial: "layouts/mailbot_header" %> + + <%= @email_body %> + +<%= render partial: "layouts/mailbot_footer" %> \ No newline at end of file diff --git a/config/environments/development.rb b/config/environments/development.rb index 6f2a1042..12119595 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -114,4 +114,5 @@ Osem::Application.configure do end end + config.assets.precompile += ['mailbot.css'] end From 0a20f80d6e3de9199ea3d662a8ed0061e7cd9e1a Mon Sep 17 00:00:00 2001 From: rajavi-mishra Date: Wed, 10 Mar 2021 10:25:41 -0800 Subject: [PATCH 06/18] all layouts implemented in the emails --- app/views/mailbot/comment_template.html.erb | 14 ++++ app/views/mailbot/comment_template.text.erb | 83 ------------------- .../ticket_confirmation_template.html.erb | 12 +++ .../ticket_confirmation_template.text.erb | 81 ------------------ ...kers_ticket_confirmation_template.html.erb | 14 ++++ ...kers_ticket_confirmation_template.text.erb | 83 ------------------- 6 files changed, 40 insertions(+), 247 deletions(-) create mode 100644 app/views/mailbot/comment_template.html.erb delete mode 100644 app/views/mailbot/comment_template.text.erb create mode 100644 app/views/mailbot/ticket_confirmation_template.html.erb delete mode 100644 app/views/mailbot/ticket_confirmation_template.text.erb create mode 100644 app/views/mailbot/young_thinkers_ticket_confirmation_template.html.erb delete mode 100644 app/views/mailbot/young_thinkers_ticket_confirmation_template.text.erb diff --git a/app/views/mailbot/comment_template.html.erb b/app/views/mailbot/comment_template.html.erb new file mode 100644 index 00000000..2f5158e8 --- /dev/null +++ b/app/views/mailbot/comment_template.html.erb @@ -0,0 +1,14 @@ +<%= render partial: "layouts/mailbot_header" %> + + Dear <%= @user.name %>, + + User <%= @comment.user.name %> posted a new comment for event <%= @event.title %> of <%= @conference.short_title %> . + + "<%= @comment.body %>" + + To reply to this comment, please go to <%= h(admin_conference_program_event_url(@conference.short_title, @event, only_path: false)) %> + + Best wishes, + <%= @conference.title %> Team + +<%= render partial: "layouts/mailbot_footer" %> \ No newline at end of file diff --git a/app/views/mailbot/comment_template.text.erb b/app/views/mailbot/comment_template.text.erb deleted file mode 100644 index d162d710..00000000 --- a/app/views/mailbot/comment_template.text.erb +++ /dev/null @@ -1,83 +0,0 @@ - - - - - - - - - - - - - - Email - - -
-
- -
-
-

-
-
-
- - Dear <%= @user.name %>, - - User <%= @comment.user.name %> posted a new comment for event <%= @event.title %> of <%= @conference.short_title %> . - - "<%= @comment.body %>" - - To reply to this comment, please go to <%= h(admin_conference_program_event_url(@conference.short_title, @event, only_path: false)) %> - - Best wishes, - <%= @conference.title %> Team - -
-
-

-
- - diff --git a/app/views/mailbot/ticket_confirmation_template.html.erb b/app/views/mailbot/ticket_confirmation_template.html.erb new file mode 100644 index 00000000..51e83f9c --- /dev/null +++ b/app/views/mailbot/ticket_confirmation_template.html.erb @@ -0,0 +1,12 @@ +<%= render partial: "layouts/mailbot_header" %> + + Dear <%= @user.name %>, + + Thanks! You have successfully booked <%= @ticket_purchase.quantity %> <%= @ticket_purchase.ticket.title %> ticket(s) for the event <%= @conference.title %>. Your transaction id is <%= @ticket_purchase.id %>. + + Please, find the ticket(s) pdf attached. + + Best wishes, + <%= @conference.title %> Team + +<%= render partial: "layouts/mailbot_footer" %> \ No newline at end of file diff --git a/app/views/mailbot/ticket_confirmation_template.text.erb b/app/views/mailbot/ticket_confirmation_template.text.erb deleted file mode 100644 index 0e4e54f8..00000000 --- a/app/views/mailbot/ticket_confirmation_template.text.erb +++ /dev/null @@ -1,81 +0,0 @@ - - - - - - - - - - - - - - Email - - -
-
- -
-
-

-
-
-
- - Dear <%= @user.name %>, - - Thanks! You have successfully booked <%= @ticket_purchase.quantity %> <%= @ticket_purchase.ticket.title %> ticket(s) for the event <%= @conference.title %>. Your transaction id is <%= @ticket_purchase.id %>. - - Please, find the ticket(s) pdf attached. - - Best wishes, - <%= @conference.title %> Team - -
-
-

-
- - diff --git a/app/views/mailbot/young_thinkers_ticket_confirmation_template.html.erb b/app/views/mailbot/young_thinkers_ticket_confirmation_template.html.erb new file mode 100644 index 00000000..44d3c2a0 --- /dev/null +++ b/app/views/mailbot/young_thinkers_ticket_confirmation_template.html.erb @@ -0,0 +1,14 @@ +<%= render partial: "layouts/mailbot_header" %> + + Dear <%= @user.name %>, + + Thanks! You have successfully booked <%= @ticket_purchase.quantity %> <%= @ticket_purchase.ticket.title %> ticket(s) for the event <%= @conference.title %>. Your transaction id is <%= @ticket_purchase.id %>. + + Please, find the ticket(s) pdf attached. + + The SAP Young Thinkers team will reach out to you with information on how to participate in the event soon. In the meantime, you can check the event page (https://events.sap.com/yt-learning-festival-at-snapcon-2020/en/home) or send an email with your questions to youngthinkers@sap.com. + + Best wishes, + <%= @conference.title %> Team + +<%= render partial: "layouts/mailbot_footer" %> \ No newline at end of file diff --git a/app/views/mailbot/young_thinkers_ticket_confirmation_template.text.erb b/app/views/mailbot/young_thinkers_ticket_confirmation_template.text.erb deleted file mode 100644 index 6a4c7fb5..00000000 --- a/app/views/mailbot/young_thinkers_ticket_confirmation_template.text.erb +++ /dev/null @@ -1,83 +0,0 @@ - - - - - - - - - - - - - - Email - - -
-
- -
-
-

-
-
-
- - Dear <%= @user.name %>, - - Thanks! You have successfully booked <%= @ticket_purchase.quantity %> <%= @ticket_purchase.ticket.title %> ticket(s) for the event <%= @conference.title %>. Your transaction id is <%= @ticket_purchase.id %>. - - Please, find the ticket(s) pdf attached. - - The SAP Young Thinkers team will reach out to you with information on how to participate in the event soon. In the meantime, you can check the event page (https://events.sap.com/yt-learning-festival-at-snapcon-2020/en/home) or send an email with your questions to youngthinkers@sap.com. - - Best wishes, - <%= @conference.title %> Team - -
-
-

-
- - From 1c28f3839e1d71ffcfe4f61971e32fe6adc8288d Mon Sep 17 00:00:00 2001 From: rajavi-mishra Date: Wed, 10 Mar 2021 11:18:39 -0800 Subject: [PATCH 07/18] image tag --- app/views/layouts/_mailbot_header.html.erb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/views/layouts/_mailbot_header.html.erb b/app/views/layouts/_mailbot_header.html.erb index 0c29963f..343af234 100644 --- a/app/views/layouts/_mailbot_header.html.erb +++ b/app/views/layouts/_mailbot_header.html.erb @@ -13,12 +13,12 @@
- <% if !@logo.nil? %> + <% if @logo.present? %> <%= image_tag(@logo, style: "display:block") %> <% end %>
-

+

Snap!Con -- A conference all about Snap!, a programing language from UC Berkeley.

From ba4de34fa77abdfd34913362db471f6a3069c76e Mon Sep 17 00:00:00 2001 From: Jimmy Date: Wed, 10 Mar 2021 17:44:15 -0800 Subject: [PATCH 08/18] [fix] Add alt text to logo --- app/views/layouts/_mailbot_header.html.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/layouts/_mailbot_header.html.erb b/app/views/layouts/_mailbot_header.html.erb index 343af234..96beec33 100644 --- a/app/views/layouts/_mailbot_header.html.erb +++ b/app/views/layouts/_mailbot_header.html.erb @@ -14,7 +14,7 @@
<% if @logo.present? %> - <%= image_tag(@logo, style: "display:block") %> + <%= image_tag(@logo, style: "display:block", alt: 'conference logo') %> <% end %>
From ac4fb8a75722cc31838cd22c19354b4a1d4bf111 Mon Sep 17 00:00:00 2001 From: Jimmy Date: Wed, 10 Mar 2021 20:13:49 -0800 Subject: [PATCH 09/18] [feat] Refactor mailbot.rb and support displaying conf/org/default logo --- app/mailers/mailbot.rb | 92 +++++++++++----------- app/models/registration.rb | 2 +- app/views/layouts/_mailbot_header.html.erb | 7 +- 3 files changed, 50 insertions(+), 51 deletions(-) diff --git a/app/mailers/mailbot.rb b/app/mailers/mailbot.rb index c055ec84..216bb9f9 100644 --- a/app/mailers/mailbot.rb +++ b/app/mailers/mailbot.rb @@ -3,23 +3,26 @@ SNAPCON_BCC_ADDRESS = 'messages@snap.berkeley.edu' EMAIL_TEMPLATE = 'email_template' YTLF_TICKET_ID = 50 +DEFAULT_LOGO = 'snapcon_logo.png' class Mailbot < ActionMailer::Base + default bcc: -> { SNAPCON_BCC_ADDRESS }, + template_name: -> { EMAIL_TEMPLATE } + def registration_mail(conference, user) @email_body = conference.email_settings.generate_email_on_conf_updates(conference, user, conference.email_settings.registration_body) - @logo = conference.picture.thumb.url + @logo_url = logo_url(conference) mail(to: user.email, - bcc: SNAPCON_BCC_ADDRESS, from: conference.contact.email, - subject: conference.email_settings.registration_subject, - template_name: EMAIL_TEMPLATE) + subject: conference.email_settings.registration_subject) end def ticket_confirmation_mail(ticket_purchase) @ticket_purchase = ticket_purchase @conference = ticket_purchase.conference @user = ticket_purchase.user + @logo_url = logo_url(@conference) PhysicalTicket.last(ticket_purchase.quantity).each do |physical_ticket| pdf = TicketPdf.new(@conference, @user, physical_ticket, @conference.ticket_layout.to_sym, "ticket_for_#{@conference.short_title}_#{physical_ticket.id}") @@ -32,7 +35,6 @@ class Mailbot < ActionMailer::Base end mail(to: @user.email, - bcc: SNAPCON_BCC_ADDRESS, from: @conference.contact.email, template_name: template_name, subject: "#{@conference.title} | Ticket Confirmation and PDF!") @@ -41,128 +43,114 @@ class Mailbot < ActionMailer::Base def acceptance_mail(event) conference = event.program.conference - @logo = conference.picture.thumb.url + @logo_url = logo_url(conference) @email_body = conference.email_settings.generate_event_mail(event, conference.email_settings.accepted_body) mail(to: event.submitter.email, - bcc: SNAPCON_BCC_ADDRESS, from: conference.contact.email, - subject: conference.email_settings.accepted_subject, - template_name: EMAIL_TEMPLATE) + subject: conference.email_settings.accepted_subject) end def submitted_proposal_mail(event) conference = event.program.conference - @logo = conference.picture.thumb.url + @logo_url = logo_url(conference) @email_body = conference.email_settings.generate_event_mail(event, conference.email_settings.submitted_proposal_body) mail(to: event.submitter.email, - bcc: SNAPCON_BCC_ADDRESS, from: conference.contact.email, - subject: conference.email_settings.submitted_proposal_subject, - template_name: EMAIL_TEMPLATE) + subject: conference.email_settings.submitted_proposal_subject) end def rejection_mail(event) conference = event.program.conference - @logo = conference.picture.thumb.url + @logo_url = logo_url(conference) @email_body = conference.email_settings.generate_event_mail(event, conference.email_settings.rejected_body) mail(to: event.submitter.email, - bcc: SNAPCON_BCC_ADDRESS, from: conference.contact.email, - subject: conference.email_settings.rejected_subject, - template_name: EMAIL_TEMPLATE) + subject: conference.email_settings.rejected_subject) end def confirm_reminder_mail(event) conference = event.program.conference - @logo = conference.picture.thumb.url + @logo_url = logo_url(conference) @email_body = conference.email_settings.generate_event_mail(event, conference.email_settings.confirmed_without_registration_body) mail(to: event.submitter.email, - bcc: SNAPCON_BCC_ADDRESS, from: conference.contact.email, - subject: conference.email_settings.confirmed_without_registration_subject, - template_name: EMAIL_TEMPLATE) + subject: conference.email_settings.confirmed_without_registration_subject) end def conference_date_update_mail(conference, user) - @logo = conference.picture.thumb.url + @logo_url = logo_url(conference) @email_body = conference.email_settings.generate_email_on_conf_updates(conference, user, conference.email_settings.conference_dates_updated_body) mail(to: user.email, - bcc: SNAPCON_BCC_ADDRESS, from: conference.contact.email, - subject: conference.email_settings.conference_dates_updated_subject, - template_name: EMAIL_TEMPLATE) + subject: conference.email_settings.conference_dates_updated_subject) end def conference_registration_date_update_mail(conference, user) - @logo = conference.picture.thumb.url + @logo_url = logo_url(conference) @email_body = conference.email_settings.generate_email_on_conf_updates(conference, user, conference.email_settings.conference_registration_dates_updated_body) mail(to: user.email, - bcc: SNAPCON_BCC_ADDRESS, from: conference.contact.email, - subject: conference.email_settings.conference_registration_dates_updated_subject, - template_name: EMAIL_TEMPLATE) + subject: conference.email_settings.conference_registration_dates_updated_subject) end def conference_venue_update_mail(conference, user) - @logo = conference.picture.thumb.url + @logo_url = logo_url(conference) @email_body = conference.email_settings.generate_email_on_conf_updates(conference, user, conference.email_settings.venue_updated_body) mail(to: user.email, - bcc: SNAPCON_BCC_ADDRESS, from: conference.contact.email, - subject: conference.email_settings.venue_updated_subject, - template_name: EMAIL_TEMPLATE) + subject: conference.email_settings.venue_updated_subject) end def conference_schedule_update_mail(conference, user) - @logo = conference.picture.thumb.url + @logo_url = logo_url(conference) @email_body = conference.email_settings.generate_email_on_conf_updates(conference, user, conference.email_settings.program_schedule_public_body) mail(to: user.email, + bcc: nil, from: conference.contact.email, - subject: conference.email_settings.program_schedule_public_subject, - template_name: EMAIL_TEMPLATE) + subject: conference.email_settings.program_schedule_public_subject) end def conference_cfp_update_mail(conference, user) - @logo = conference.picture.thumb.url + @logo_url = logo_url(conference) @email_body = conference.email_settings.generate_email_on_conf_updates(conference, user, conference.email_settings.cfp_dates_updated_body) mail(to: user.email, + bcc: nil, from: conference.contact.email, - subject: conference.email_settings.cfp_dates_updated_subject, - template_name: EMAIL_TEMPLATE) + subject: conference.email_settings.cfp_dates_updated_subject) end def conference_booths_acceptance_mail(booth) conference = booth.conference - @logo = conference.picture.thumb.url + @logo_url = logo_url(conference) @email_body = conference.email_settings.generate_booth_mail(booth, conference.email_settings.booths_acceptance_body) mail(to: booth.submitter.email, + bcc: nil, from: conference.contact.email, - subject: conference.email_settings.booths_acceptance_subject, - template_name: EMAIL_TEMPLATE) + subject: conference.email_settings.booths_acceptance_subject) end def conference_booths_rejection_mail(booth) conference = booth.conference - @logo = conference.picture.thumb.url + @logo_url = logo_url(conference) @email_body = conference.email_settings.generate_booth_mail(booth, conference.email_settings.booths_rejection_body) mail(to: booth.submitter.email, + bcc: nil, from: conference.contact.email, - subject: conference.email_settings.booths_rejection_subject, - template_name: EMAIL_TEMPLATE) + subject: conference.email_settings.booths_rejection_subject) end def event_comment_mail(comment, user) @@ -170,10 +158,24 @@ class Mailbot < ActionMailer::Base @event = @comment.commentable @conference = @event.program.conference @user = user + @logo_url = logo_url(@conference) mail(to: @user.email, + bcc: nil, from: @conference.contact.email, template_name: 'comment_template', subject: "New comment has been posted for #{@event.title}") end + + private + + def logo_url(conference) + if conference.picture.present? + return conference.picture.thumb.url + elsif conference.organization.picture.present? + return conference.organization.picture.thumb.url + else + return DEFAULT_LOGO + end + end end diff --git a/app/models/registration.rb b/app/models/registration.rb index d220e49f..3906f558 100644 --- a/app/models/registration.rb +++ b/app/models/registration.rb @@ -69,7 +69,7 @@ class Registration < ApplicationRecord def send_registration_mail if conference.email_settings.send_on_registration? - Mailbot.registration_mail(conference, user).deliver_now + Mailbot.registration_mail(conference, user).deliver_later end end diff --git a/app/views/layouts/_mailbot_header.html.erb b/app/views/layouts/_mailbot_header.html.erb index 96beec33..e0f182a7 100644 --- a/app/views/layouts/_mailbot_header.html.erb +++ b/app/views/layouts/_mailbot_header.html.erb @@ -13,13 +13,10 @@
- <% if @logo.present? %> - <%= image_tag(@logo, style: "display:block", alt: 'conference logo') %> + <% if @logo_url.present? %> + <%= image_tag(@logo_url, style: "display:block;height:70px;width:auto;", alt: 'conference logo') %> <% end %>
-
-

Snap!Con -- A conference all about Snap!, a programing language from UC Berkeley.

-
From 899d4c91f6d87f34ea6889c51cec96e60a1e2bd2 Mon Sep 17 00:00:00 2001 From: Jimmy Date: Wed, 10 Mar 2021 23:09:52 -0800 Subject: [PATCH 10/18] [test] Simplify mailbot.rb; Add corresponding tests --- app/mailers/mailbot.rb | 154 ++++++++++++++++------------------- config/environments/test.rb | 1 + spec/mailers/mailbot_spec.rb | 28 ++++++- 3 files changed, 98 insertions(+), 85 deletions(-) diff --git a/app/mailers/mailbot.rb b/app/mailers/mailbot.rb index 216bb9f9..22dfb866 100644 --- a/app/mailers/mailbot.rb +++ b/app/mailers/mailbot.rb @@ -7,21 +7,23 @@ DEFAULT_LOGO = 'snapcon_logo.png' class Mailbot < ActionMailer::Base default bcc: -> { SNAPCON_BCC_ADDRESS }, - template_name: -> { EMAIL_TEMPLATE } + template_name: -> { EMAIL_TEMPLATE }, + to: -> { @user.email }, + from: -> { @conference.contact.email} def registration_mail(conference, user) - @email_body = conference.email_settings.generate_email_on_conf_updates(conference, user, conference.email_settings.registration_body) - @logo_url = logo_url(conference) + @user = user + @conference = conference + @email_body = @conference.email_settings.generate_email_on_conf_updates(@conference, @user, @conference.email_settings.registration_body) + @logo_url = logo_url(@conference) - mail(to: user.email, - from: conference.contact.email, - subject: conference.email_settings.registration_subject) + mail(subject: @conference.email_settings.registration_subject) end def ticket_confirmation_mail(ticket_purchase) @ticket_purchase = ticket_purchase - @conference = ticket_purchase.conference @user = ticket_purchase.user + @conference = ticket_purchase.conference @logo_url = logo_url(@conference) PhysicalTicket.last(ticket_purchase.quantity).each do |physical_ticket| @@ -34,123 +36,111 @@ class Mailbot < ActionMailer::Base template_name = 'young_thinkers_ticket_confirmation_template' end - mail(to: @user.email, - from: @conference.contact.email, - template_name: template_name, - subject: "#{@conference.title} | Ticket Confirmation and PDF!") + mail(subject: "#{@conference.title} | Ticket Confirmation and PDF!", + template_name: template_name) end def acceptance_mail(event) - conference = event.program.conference + @user = event.submitter + @conference = event.program.conference + @logo_url = logo_url(@conference) + @email_body = @conference.email_settings.generate_event_mail(event, @conference.email_settings.accepted_body) - @logo_url = logo_url(conference) - @email_body = conference.email_settings.generate_event_mail(event, conference.email_settings.accepted_body) - - mail(to: event.submitter.email, - from: conference.contact.email, - subject: conference.email_settings.accepted_subject) + mail(subject: @conference.email_settings.accepted_subject) end def submitted_proposal_mail(event) - conference = event.program.conference + @user = event.submitter + @conference = event.program.conference + @logo_url = logo_url(@conference) + @email_body = @conference.email_settings.generate_event_mail(event, @conference.email_settings.submitted_proposal_body) - @logo_url = logo_url(conference) - @email_body = conference.email_settings.generate_event_mail(event, conference.email_settings.submitted_proposal_body) - - mail(to: event.submitter.email, - from: conference.contact.email, - subject: conference.email_settings.submitted_proposal_subject) + mail(subject: @conference.email_settings.submitted_proposal_subject) end def rejection_mail(event) - conference = event.program.conference + @user = event.submitter + @conference = event.program.conference + @logo_url = logo_url(@conference) + @email_body = @conference.email_settings.generate_event_mail(event, @conference.email_settings.rejected_body) - @logo_url = logo_url(conference) - @email_body = conference.email_settings.generate_event_mail(event, conference.email_settings.rejected_body) - - mail(to: event.submitter.email, - from: conference.contact.email, - subject: conference.email_settings.rejected_subject) + mail(subject: @conference.email_settings.rejected_subject) end def confirm_reminder_mail(event) - conference = event.program.conference + @user = event.submitter + @conference = event.program.conference + @logo_url = logo_url(@conference) + @email_body = @conference.email_settings.generate_event_mail(event, @conference.email_settings.confirmed_without_registration_body) - @logo_url = logo_url(conference) - @email_body = conference.email_settings.generate_event_mail(event, conference.email_settings.confirmed_without_registration_body) - - mail(to: event.submitter.email, - from: conference.contact.email, - subject: conference.email_settings.confirmed_without_registration_subject) + mail(subject: @conference.email_settings.confirmed_without_registration_subject) end def conference_date_update_mail(conference, user) - @logo_url = logo_url(conference) - @email_body = conference.email_settings.generate_email_on_conf_updates(conference, user, conference.email_settings.conference_dates_updated_body) + @user = user + @conference = @conference + @logo_url = logo_url(@conference) + @email_body = @conference.email_settings.generate_email_on_conf_updates(@conference, @user, @conference.email_settings.conference_dates_updated_body) - mail(to: user.email, - from: conference.contact.email, - subject: conference.email_settings.conference_dates_updated_subject) + mail(subject: @conference.email_settings.conference_dates_updated_subject) end def conference_registration_date_update_mail(conference, user) - @logo_url = logo_url(conference) - @email_body = conference.email_settings.generate_email_on_conf_updates(conference, user, conference.email_settings.conference_registration_dates_updated_body) + @user = user + @conference = conference + @logo_url = logo_url(@conference) + @email_body = @conference.email_settings.generate_email_on_conf_updates(@conference, @user, @conference.email_settings.conference_registration_dates_updated_body) - mail(to: user.email, - from: conference.contact.email, - subject: conference.email_settings.conference_registration_dates_updated_subject) + mail(subject: @conference.email_settings.conference_registration_dates_updated_subject) end def conference_venue_update_mail(conference, user) - @logo_url = logo_url(conference) - @email_body = conference.email_settings.generate_email_on_conf_updates(conference, user, conference.email_settings.venue_updated_body) + @user = user + @conference = conference + @logo_url = logo_url(@conference) + @email_body = @conference.email_settings.generate_email_on_conf_updates(@conference, @user, @conference.email_settings.venue_updated_body) - mail(to: user.email, - from: conference.contact.email, - subject: conference.email_settings.venue_updated_subject) + mail(subject: @conference.email_settings.venue_updated_subject) end def conference_schedule_update_mail(conference, user) - @logo_url = logo_url(conference) - @email_body = conference.email_settings.generate_email_on_conf_updates(conference, user, conference.email_settings.program_schedule_public_body) + @user = user + @conference = conference + @logo_url = logo_url(@conference) + @email_body = @conference.email_settings.generate_email_on_conf_updates(@conference, @user, @conference.email_settings.program_schedule_public_body) - mail(to: user.email, - bcc: nil, - from: conference.contact.email, - subject: conference.email_settings.program_schedule_public_subject) + mail(bcc: nil, + subject: @conference.email_settings.program_schedule_public_subject) end def conference_cfp_update_mail(conference, user) - @logo_url = logo_url(conference) - @email_body = conference.email_settings.generate_email_on_conf_updates(conference, user, conference.email_settings.cfp_dates_updated_body) + @user = user + @conference = conference + @logo_url = logo_url(@conference) + @email_body = @conference.email_settings.generate_email_on_conf_updates(@conference, @user, @conference.email_settings.cfp_dates_updated_body) - mail(to: user.email, - bcc: nil, - from: conference.contact.email, - subject: conference.email_settings.cfp_dates_updated_subject) + mail(bcc: nil, + subject: @conference.email_settings.cfp_dates_updated_subject) end def conference_booths_acceptance_mail(booth) - conference = booth.conference - @logo_url = logo_url(conference) - @email_body = conference.email_settings.generate_booth_mail(booth, conference.email_settings.booths_acceptance_body) + @user = booth.submitter + @conference = booth.conference + @logo_url = logo_url(@conference) + @email_body = @conference.email_settings.generate_booth_mail(booth, @conference.email_settings.booths_acceptance_body) - mail(to: booth.submitter.email, - bcc: nil, - from: conference.contact.email, - subject: conference.email_settings.booths_acceptance_subject) + mail(bcc: nil, + subject: @conference.email_settings.booths_acceptance_subject) end def conference_booths_rejection_mail(booth) - conference = booth.conference - @logo_url = logo_url(conference) - @email_body = conference.email_settings.generate_booth_mail(booth, conference.email_settings.booths_rejection_body) + @user = booth.submitter + @conference = booth.conference + @logo_url = logo_url(@conference) + @email_body = @conference.email_settings.generate_booth_mail(booth, @conference.email_settings.booths_rejection_body) - mail(to: booth.submitter.email, - bcc: nil, - from: conference.contact.email, - subject: conference.email_settings.booths_rejection_subject) + mail(bcc: nil, + subject: @conference.email_settings.booths_rejection_subject) end def event_comment_mail(comment, user) @@ -160,9 +150,7 @@ class Mailbot < ActionMailer::Base @user = user @logo_url = logo_url(@conference) - mail(to: @user.email, - bcc: nil, - from: @conference.contact.email, + mail(bcc: nil, template_name: 'comment_template', subject: "New comment has been posted for #{@event.title}") end diff --git a/config/environments/test.rb b/config/environments/test.rb index 225ae26f..1a9d4d7b 100644 --- a/config/environments/test.rb +++ b/config/environments/test.rb @@ -52,4 +52,5 @@ Osem::Application.configure do ActiveSupport::Deprecation.silenced = true end + config.assets.precompile += ['mailbot.css'] end diff --git a/spec/mailers/mailbot_spec.rb b/spec/mailers/mailbot_spec.rb index 1f739997..22aade61 100644 --- a/spec/mailers/mailbot_spec.rb +++ b/spec/mailers/mailbot_spec.rb @@ -22,8 +22,8 @@ describe Mailbot do expect(mail.from).to eq ['conf@domain.com'] end - it 'assigns the email body' do - expect(mail.body).to include 'Lorem ipsum dolor sit amet, consectetuer adipiscing elit' + it 'assigns the email body with the correct logo' do + expect(mail.body).to include 'snapcon_logo' end it 'delivers the email' do @@ -77,4 +77,28 @@ describe Mailbot do context 'update notifications' do it 'is a pending test' end + + context 'helper methods' do + let(:organization) { create(:organization) } + let(:conference2) { create(:conference, organization: organization) } + + describe '#logo_url' do + it 'gives the correct logo url' do + mailbot = Mailbot.new + expect(mailbot.send(:logo_url, conference2)).to eq('snapcon_logo.png') + + File.open('spec/support/logos/1.png') do |file| + organization.picture = file + end + + expect(mailbot.send(:logo_url, conference2)).to include('1.png') + + File.open('spec/support/logos/2.png') do |file| + conference2.picture = file + end + + expect(mailbot.send(:logo_url, conference2)).to include('2.png') + end + end + end end From ee7c906f1773230e52b544d0767a60709ddc6e8a Mon Sep 17 00:00:00 2001 From: Jimmy Date: Thu, 11 Mar 2021 21:10:26 -0800 Subject: [PATCH 11/18] [feat] Modify alt text for logo; Support user-defined color for header and footer --- app/views/layouts/_mailbot_footer.html.erb | 7 ++++-- app/views/layouts/_mailbot_header.html.erb | 13 ++++++---- app/views/mailbot/comment_template.html.erb | 24 ++++++++++--------- app/views/mailbot/email_template.html.erb | 8 ++++--- .../ticket_confirmation_template.html.erb | 20 +++++++++------- ...kers_ticket_confirmation_template.html.erb | 24 ++++++++++--------- 6 files changed, 55 insertions(+), 41 deletions(-) diff --git a/app/views/layouts/_mailbot_footer.html.erb b/app/views/layouts/_mailbot_footer.html.erb index 4f479cc7..fc3d88a4 100644 --- a/app/views/layouts/_mailbot_footer.html.erb +++ b/app/views/layouts/_mailbot_footer.html.erb @@ -7,8 +7,11 @@ <%= stylesheet_link_tag "mailbot" %> - + <% if @conference.present? && @conference.color.present? %> +
+ <% else %> +
+ <% end %>
-
\ No newline at end of file diff --git a/app/views/layouts/_mailbot_header.html.erb b/app/views/layouts/_mailbot_header.html.erb index e0f182a7..674b56a5 100644 --- a/app/views/layouts/_mailbot_header.html.erb +++ b/app/views/layouts/_mailbot_header.html.erb @@ -9,18 +9,21 @@ <%= stylesheet_link_tag "mailbot" %> - -
+ + <% if @conference.present? && @conference.color.present? %> +
+ <% else %> +
+ <% end %>
<% if @logo_url.present? %> - <%= image_tag(@logo_url, style: "display:block;height:70px;width:auto;", alt: 'conference logo') %> + <%= image_tag(@logo_url, style: "display:block;height:70px;width:auto;", alt: @conference.title + ' logo') %> <% end %>
-
- + \ No newline at end of file diff --git a/app/views/mailbot/comment_template.html.erb b/app/views/mailbot/comment_template.html.erb index 2f5158e8..b9e9cce0 100644 --- a/app/views/mailbot/comment_template.html.erb +++ b/app/views/mailbot/comment_template.html.erb @@ -1,14 +1,16 @@ <%= render partial: "layouts/mailbot_header" %> - - Dear <%= @user.name %>, +
+ + Dear <%= @user.name %>, - User <%= @comment.user.name %> posted a new comment for event <%= @event.title %> of <%= @conference.short_title %> . - - "<%= @comment.body %>" - - To reply to this comment, please go to <%= h(admin_conference_program_event_url(@conference.short_title, @event, only_path: false)) %> - - Best wishes, - <%= @conference.title %> Team - + User <%= @comment.user.name %> posted a new comment for event <%= @event.title %> of <%= @conference.short_title %> . + + "<%= @comment.body %>" + + To reply to this comment, please go to <%= h(admin_conference_program_event_url(@conference.short_title, @event, only_path: false)) %> + + Best wishes, + <%= @conference.title %> Team + +
<%= render partial: "layouts/mailbot_footer" %> \ No newline at end of file diff --git a/app/views/mailbot/email_template.html.erb b/app/views/mailbot/email_template.html.erb index fd8ae362..6176cf08 100644 --- a/app/views/mailbot/email_template.html.erb +++ b/app/views/mailbot/email_template.html.erb @@ -1,5 +1,7 @@ <%= render partial: "layouts/mailbot_header" %> - - <%= @email_body %> - +
+ + <%= @email_body %> + +
<%= render partial: "layouts/mailbot_footer" %> \ No newline at end of file diff --git a/app/views/mailbot/ticket_confirmation_template.html.erb b/app/views/mailbot/ticket_confirmation_template.html.erb index 51e83f9c..f92284d7 100644 --- a/app/views/mailbot/ticket_confirmation_template.html.erb +++ b/app/views/mailbot/ticket_confirmation_template.html.erb @@ -1,12 +1,14 @@ <%= render partial: "layouts/mailbot_header" %> - - Dear <%= @user.name %>, +
+ + Dear <%= @user.name %>, - Thanks! You have successfully booked <%= @ticket_purchase.quantity %> <%= @ticket_purchase.ticket.title %> ticket(s) for the event <%= @conference.title %>. Your transaction id is <%= @ticket_purchase.id %>. - - Please, find the ticket(s) pdf attached. - - Best wishes, - <%= @conference.title %> Team - + Thanks! You have successfully booked <%= @ticket_purchase.quantity %> <%= @ticket_purchase.ticket.title %> ticket(s) for the event <%= @conference.title %>. Your transaction id is <%= @ticket_purchase.id %>. + + Please, find the ticket(s) pdf attached. + + Best wishes, + <%= @conference.title %> Team + +
<%= render partial: "layouts/mailbot_footer" %> \ No newline at end of file diff --git a/app/views/mailbot/young_thinkers_ticket_confirmation_template.html.erb b/app/views/mailbot/young_thinkers_ticket_confirmation_template.html.erb index 44d3c2a0..d35d8a1f 100644 --- a/app/views/mailbot/young_thinkers_ticket_confirmation_template.html.erb +++ b/app/views/mailbot/young_thinkers_ticket_confirmation_template.html.erb @@ -1,14 +1,16 @@ <%= render partial: "layouts/mailbot_header" %> - - Dear <%= @user.name %>, +
+ + Dear <%= @user.name %>, - Thanks! You have successfully booked <%= @ticket_purchase.quantity %> <%= @ticket_purchase.ticket.title %> ticket(s) for the event <%= @conference.title %>. Your transaction id is <%= @ticket_purchase.id %>. - - Please, find the ticket(s) pdf attached. - - The SAP Young Thinkers team will reach out to you with information on how to participate in the event soon. In the meantime, you can check the event page (https://events.sap.com/yt-learning-festival-at-snapcon-2020/en/home) or send an email with your questions to youngthinkers@sap.com. - - Best wishes, - <%= @conference.title %> Team - + Thanks! You have successfully booked <%= @ticket_purchase.quantity %> <%= @ticket_purchase.ticket.title %> ticket(s) for the event <%= @conference.title %>. Your transaction id is <%= @ticket_purchase.id %>. + + Please, find the ticket(s) pdf attached. + + The SAP Young Thinkers team will reach out to you with information on how to participate in the event soon. In the meantime, you can check the event page (https://events.sap.com/yt-learning-festival-at-snapcon-2020/en/home) or send an email with your questions to youngthinkers@sap.com. + + Best wishes, + <%= @conference.title %> Team + +
<%= render partial: "layouts/mailbot_footer" %> \ No newline at end of file From 4856bc718dae8370453827046cd2aa925461fb96 Mon Sep 17 00:00:00 2001 From: Jimmy Date: Thu, 11 Mar 2021 22:00:15 -0800 Subject: [PATCH 12/18] [fix] Restore a mistakenly deleted test --- spec/mailers/mailbot_spec.rb | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/spec/mailers/mailbot_spec.rb b/spec/mailers/mailbot_spec.rb index 22aade61..a1281e65 100644 --- a/spec/mailers/mailbot_spec.rb +++ b/spec/mailers/mailbot_spec.rb @@ -22,6 +22,10 @@ describe Mailbot do expect(mail.from).to eq ['conf@domain.com'] end + it 'assigns the email body' do + expect(mail.body).to include 'Lorem ipsum dolor sit amet, consectetuer adipiscing elit' + end + it 'assigns the email body with the correct logo' do expect(mail.body).to include 'snapcon_logo' end From 394dc0506f82ae2e54ea2b42c3b59abe35c55941 Mon Sep 17 00:00:00 2001 From: Jimmy Date: Thu, 11 Mar 2021 23:15:07 -0800 Subject: [PATCH 13/18] temp --- spec/mailers/mailbot_spec.rb | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/spec/mailers/mailbot_spec.rb b/spec/mailers/mailbot_spec.rb index a1281e65..65ea4213 100644 --- a/spec/mailers/mailbot_spec.rb +++ b/spec/mailers/mailbot_spec.rb @@ -25,7 +25,19 @@ describe Mailbot do it 'assigns the email body' do expect(mail.body).to include 'Lorem ipsum dolor sit amet, consectetuer adipiscing elit' end - + + it 'assigns the email body with the correct color' do + # p mail.body + # expect(mail.body).to have_selector('#border.background-color', '#0B3559') + # Capybara.within_frame(mail.body) do + # color = find('#border').native.css_value('background-color') + # expect(color).to eq('#0B3559') + # end + + # TODO: select border ... + expect(mail.body).to include('background-color: ' + conference.color) + end + it 'assigns the email body with the correct logo' do expect(mail.body).to include 'snapcon_logo' end From 33ce7a61c64bf758fb9fbc36c084334434109a7c Mon Sep 17 00:00:00 2001 From: Jimmy Date: Thu, 11 Mar 2021 23:39:06 -0800 Subject: [PATCH 14/18] [style] Fix style --- app/mailers/mailbot.rb | 50 +++++++++++++++++++++--------------------- 1 file changed, 25 insertions(+), 25 deletions(-) diff --git a/app/mailers/mailbot.rb b/app/mailers/mailbot.rb index 22dfb866..8a7cb840 100644 --- a/app/mailers/mailbot.rb +++ b/app/mailers/mailbot.rb @@ -6,10 +6,10 @@ YTLF_TICKET_ID = 50 DEFAULT_LOGO = 'snapcon_logo.png' class Mailbot < ActionMailer::Base - default bcc: -> { SNAPCON_BCC_ADDRESS }, - template_name: -> { EMAIL_TEMPLATE }, - to: -> { @user.email }, - from: -> { @conference.contact.email} + default bcc: -> { SNAPCON_BCC_ADDRESS }, + template_name: -> { EMAIL_TEMPLATE }, + to: -> { @user.email }, + from: -> { @conference.contact.email } def registration_mail(conference, user) @user = user @@ -17,7 +17,7 @@ class Mailbot < ActionMailer::Base @email_body = @conference.email_settings.generate_email_on_conf_updates(@conference, @user, @conference.email_settings.registration_body) @logo_url = logo_url(@conference) - mail(subject: @conference.email_settings.registration_subject) + mail(subject: @conference.email_settings.registration_subject) end def ticket_confirmation_mail(ticket_purchase) @@ -46,7 +46,7 @@ class Mailbot < ActionMailer::Base @logo_url = logo_url(@conference) @email_body = @conference.email_settings.generate_event_mail(event, @conference.email_settings.accepted_body) - mail(subject: @conference.email_settings.accepted_subject) + mail(subject: @conference.email_settings.accepted_subject) end def submitted_proposal_mail(event) @@ -55,7 +55,7 @@ class Mailbot < ActionMailer::Base @logo_url = logo_url(@conference) @email_body = @conference.email_settings.generate_event_mail(event, @conference.email_settings.submitted_proposal_body) - mail(subject: @conference.email_settings.submitted_proposal_subject) + mail(subject: @conference.email_settings.submitted_proposal_subject) end def rejection_mail(event) @@ -64,7 +64,7 @@ class Mailbot < ActionMailer::Base @logo_url = logo_url(@conference) @email_body = @conference.email_settings.generate_event_mail(event, @conference.email_settings.rejected_body) - mail(subject: @conference.email_settings.rejected_subject) + mail(subject: @conference.email_settings.rejected_subject) end def confirm_reminder_mail(event) @@ -73,16 +73,16 @@ class Mailbot < ActionMailer::Base @logo_url = logo_url(@conference) @email_body = @conference.email_settings.generate_event_mail(event, @conference.email_settings.confirmed_without_registration_body) - mail(subject: @conference.email_settings.confirmed_without_registration_subject) + mail(subject: @conference.email_settings.confirmed_without_registration_subject) end - def conference_date_update_mail(conference, user) + def conference_date_update_mail(_conference, user) @user = user @conference = @conference @logo_url = logo_url(@conference) @email_body = @conference.email_settings.generate_email_on_conf_updates(@conference, @user, @conference.email_settings.conference_dates_updated_body) - mail(subject: @conference.email_settings.conference_dates_updated_subject) + mail(subject: @conference.email_settings.conference_dates_updated_subject) end def conference_registration_date_update_mail(conference, user) @@ -91,7 +91,7 @@ class Mailbot < ActionMailer::Base @logo_url = logo_url(@conference) @email_body = @conference.email_settings.generate_email_on_conf_updates(@conference, @user, @conference.email_settings.conference_registration_dates_updated_body) - mail(subject: @conference.email_settings.conference_registration_dates_updated_subject) + mail(subject: @conference.email_settings.conference_registration_dates_updated_subject) end def conference_venue_update_mail(conference, user) @@ -100,7 +100,7 @@ class Mailbot < ActionMailer::Base @logo_url = logo_url(@conference) @email_body = @conference.email_settings.generate_email_on_conf_updates(@conference, @user, @conference.email_settings.venue_updated_body) - mail(subject: @conference.email_settings.venue_updated_subject) + mail(subject: @conference.email_settings.venue_updated_subject) end def conference_schedule_update_mail(conference, user) @@ -109,8 +109,8 @@ class Mailbot < ActionMailer::Base @logo_url = logo_url(@conference) @email_body = @conference.email_settings.generate_email_on_conf_updates(@conference, @user, @conference.email_settings.program_schedule_public_body) - mail(bcc: nil, - subject: @conference.email_settings.program_schedule_public_subject) + mail(bcc: nil, + subject: @conference.email_settings.program_schedule_public_subject) end def conference_cfp_update_mail(conference, user) @@ -119,8 +119,8 @@ class Mailbot < ActionMailer::Base @logo_url = logo_url(@conference) @email_body = @conference.email_settings.generate_email_on_conf_updates(@conference, @user, @conference.email_settings.cfp_dates_updated_body) - mail(bcc: nil, - subject: @conference.email_settings.cfp_dates_updated_subject) + mail(bcc: nil, + subject: @conference.email_settings.cfp_dates_updated_subject) end def conference_booths_acceptance_mail(booth) @@ -129,8 +129,8 @@ class Mailbot < ActionMailer::Base @logo_url = logo_url(@conference) @email_body = @conference.email_settings.generate_booth_mail(booth, @conference.email_settings.booths_acceptance_body) - mail(bcc: nil, - subject: @conference.email_settings.booths_acceptance_subject) + mail(bcc: nil, + subject: @conference.email_settings.booths_acceptance_subject) end def conference_booths_rejection_mail(booth) @@ -139,8 +139,8 @@ class Mailbot < ActionMailer::Base @logo_url = logo_url(@conference) @email_body = @conference.email_settings.generate_booth_mail(booth, @conference.email_settings.booths_rejection_body) - mail(bcc: nil, - subject: @conference.email_settings.booths_rejection_subject) + mail(bcc: nil, + subject: @conference.email_settings.booths_rejection_subject) end def event_comment_mail(comment, user) @@ -156,14 +156,14 @@ class Mailbot < ActionMailer::Base end private - + def logo_url(conference) if conference.picture.present? - return conference.picture.thumb.url + conference.picture.thumb.url elsif conference.organization.picture.present? - return conference.organization.picture.thumb.url + conference.organization.picture.thumb.url else - return DEFAULT_LOGO + DEFAULT_LOGO end end end From fdb08b0c9a2fd6bf8cdb199aa418852535929f22 Mon Sep 17 00:00:00 2001 From: Jimmy Date: Fri, 12 Mar 2021 00:14:29 -0800 Subject: [PATCH 15/18] [refactor] Move Mailbot#logo_url and #conference_color to ConferenceHelper --- app/helpers/conference_helper.rb | 21 ++++++++++++++ app/mailers/mailbot.rb | 33 +++------------------- app/views/layouts/_mailbot_footer.html.erb | 7 +---- app/views/layouts/_mailbot_header.html.erb | 10 ++----- spec/helpers/conference_helper_spec.rb | 22 +++++++++++++++ spec/mailers/mailbot_spec.rb | 25 +--------------- 6 files changed, 52 insertions(+), 66 deletions(-) diff --git a/app/helpers/conference_helper.rb b/app/helpers/conference_helper.rb index 14253b23..417a8d55 100644 --- a/app/helpers/conference_helper.rb +++ b/app/helpers/conference_helper.rb @@ -1,5 +1,8 @@ # frozen_string_literal: true +DEFAULT_LOGO = 'snapcon_logo.png' +DEFAULT_COLOR = '#0B3559' + module ConferenceHelper # Return true if only call_for_papers or call_for_tracks or call_for_booths is open def one_call_open(*calls) @@ -28,6 +31,24 @@ module ConferenceHelper markdown(ticket.description.split("\n").first&.strip) end + def conference_logo_url(conference) + if conference.picture.present? + conference.picture.thumb.url + elsif conference.organization.picture.present? + conference.organization.picture.thumb.url + else + DEFAULT_LOGO + end + end + + def conference_color(conference) + if conference.color.present? + conference.color + else + DEFAULT_COLOR + end + end + # adds events to icalendar for proposals in a conference def icalendar_proposals(calendar, proposals, conference) proposals.each do |proposal| diff --git a/app/mailers/mailbot.rb b/app/mailers/mailbot.rb index 8a7cb840..07249862 100644 --- a/app/mailers/mailbot.rb +++ b/app/mailers/mailbot.rb @@ -3,9 +3,10 @@ SNAPCON_BCC_ADDRESS = 'messages@snap.berkeley.edu' EMAIL_TEMPLATE = 'email_template' YTLF_TICKET_ID = 50 -DEFAULT_LOGO = 'snapcon_logo.png' class Mailbot < ActionMailer::Base + helper ConferenceHelper + default bcc: -> { SNAPCON_BCC_ADDRESS }, template_name: -> { EMAIL_TEMPLATE }, to: -> { @user.email }, @@ -15,7 +16,6 @@ class Mailbot < ActionMailer::Base @user = user @conference = conference @email_body = @conference.email_settings.generate_email_on_conf_updates(@conference, @user, @conference.email_settings.registration_body) - @logo_url = logo_url(@conference) mail(subject: @conference.email_settings.registration_subject) end @@ -24,7 +24,6 @@ class Mailbot < ActionMailer::Base @ticket_purchase = ticket_purchase @user = ticket_purchase.user @conference = ticket_purchase.conference - @logo_url = logo_url(@conference) PhysicalTicket.last(ticket_purchase.quantity).each do |physical_ticket| pdf = TicketPdf.new(@conference, @user, physical_ticket, @conference.ticket_layout.to_sym, "ticket_for_#{@conference.short_title}_#{physical_ticket.id}") @@ -43,7 +42,6 @@ class Mailbot < ActionMailer::Base def acceptance_mail(event) @user = event.submitter @conference = event.program.conference - @logo_url = logo_url(@conference) @email_body = @conference.email_settings.generate_event_mail(event, @conference.email_settings.accepted_body) mail(subject: @conference.email_settings.accepted_subject) @@ -52,7 +50,6 @@ class Mailbot < ActionMailer::Base def submitted_proposal_mail(event) @user = event.submitter @conference = event.program.conference - @logo_url = logo_url(@conference) @email_body = @conference.email_settings.generate_event_mail(event, @conference.email_settings.submitted_proposal_body) mail(subject: @conference.email_settings.submitted_proposal_subject) @@ -61,7 +58,6 @@ class Mailbot < ActionMailer::Base def rejection_mail(event) @user = event.submitter @conference = event.program.conference - @logo_url = logo_url(@conference) @email_body = @conference.email_settings.generate_event_mail(event, @conference.email_settings.rejected_body) mail(subject: @conference.email_settings.rejected_subject) @@ -70,16 +66,14 @@ class Mailbot < ActionMailer::Base def confirm_reminder_mail(event) @user = event.submitter @conference = event.program.conference - @logo_url = logo_url(@conference) @email_body = @conference.email_settings.generate_event_mail(event, @conference.email_settings.confirmed_without_registration_body) mail(subject: @conference.email_settings.confirmed_without_registration_subject) end - def conference_date_update_mail(_conference, user) + def conference_date_update_mail(conference, user) @user = user - @conference = @conference - @logo_url = logo_url(@conference) + @conference = conference @email_body = @conference.email_settings.generate_email_on_conf_updates(@conference, @user, @conference.email_settings.conference_dates_updated_body) mail(subject: @conference.email_settings.conference_dates_updated_subject) @@ -88,7 +82,6 @@ class Mailbot < ActionMailer::Base def conference_registration_date_update_mail(conference, user) @user = user @conference = conference - @logo_url = logo_url(@conference) @email_body = @conference.email_settings.generate_email_on_conf_updates(@conference, @user, @conference.email_settings.conference_registration_dates_updated_body) mail(subject: @conference.email_settings.conference_registration_dates_updated_subject) @@ -97,7 +90,6 @@ class Mailbot < ActionMailer::Base def conference_venue_update_mail(conference, user) @user = user @conference = conference - @logo_url = logo_url(@conference) @email_body = @conference.email_settings.generate_email_on_conf_updates(@conference, @user, @conference.email_settings.venue_updated_body) mail(subject: @conference.email_settings.venue_updated_subject) @@ -106,7 +98,6 @@ class Mailbot < ActionMailer::Base def conference_schedule_update_mail(conference, user) @user = user @conference = conference - @logo_url = logo_url(@conference) @email_body = @conference.email_settings.generate_email_on_conf_updates(@conference, @user, @conference.email_settings.program_schedule_public_body) mail(bcc: nil, @@ -116,7 +107,6 @@ class Mailbot < ActionMailer::Base def conference_cfp_update_mail(conference, user) @user = user @conference = conference - @logo_url = logo_url(@conference) @email_body = @conference.email_settings.generate_email_on_conf_updates(@conference, @user, @conference.email_settings.cfp_dates_updated_body) mail(bcc: nil, @@ -126,7 +116,6 @@ class Mailbot < ActionMailer::Base def conference_booths_acceptance_mail(booth) @user = booth.submitter @conference = booth.conference - @logo_url = logo_url(@conference) @email_body = @conference.email_settings.generate_booth_mail(booth, @conference.email_settings.booths_acceptance_body) mail(bcc: nil, @@ -136,7 +125,6 @@ class Mailbot < ActionMailer::Base def conference_booths_rejection_mail(booth) @user = booth.submitter @conference = booth.conference - @logo_url = logo_url(@conference) @email_body = @conference.email_settings.generate_booth_mail(booth, @conference.email_settings.booths_rejection_body) mail(bcc: nil, @@ -148,22 +136,9 @@ class Mailbot < ActionMailer::Base @event = @comment.commentable @conference = @event.program.conference @user = user - @logo_url = logo_url(@conference) mail(bcc: nil, template_name: 'comment_template', subject: "New comment has been posted for #{@event.title}") end - - private - - def logo_url(conference) - if conference.picture.present? - conference.picture.thumb.url - elsif conference.organization.picture.present? - conference.organization.picture.thumb.url - else - DEFAULT_LOGO - end - end end diff --git a/app/views/layouts/_mailbot_footer.html.erb b/app/views/layouts/_mailbot_footer.html.erb index fc3d88a4..3cc8b3c3 100644 --- a/app/views/layouts/_mailbot_footer.html.erb +++ b/app/views/layouts/_mailbot_footer.html.erb @@ -7,11 +7,6 @@ <%= stylesheet_link_tag "mailbot" %> - <% if @conference.present? && @conference.color.present? %> -
- <% else %> -
- <% end %> -
+
\ No newline at end of file diff --git a/app/views/layouts/_mailbot_header.html.erb b/app/views/layouts/_mailbot_header.html.erb index 674b56a5..12f9d4a5 100644 --- a/app/views/layouts/_mailbot_header.html.erb +++ b/app/views/layouts/_mailbot_header.html.erb @@ -10,15 +10,11 @@ <%= stylesheet_link_tag "mailbot" %> - <% if @conference.present? && @conference.color.present? %> -
- <% else %> -
- <% end %> +
- <% if @logo_url.present? %> - <%= image_tag(@logo_url, style: "display:block;height:70px;width:auto;", alt: @conference.title + ' logo') %> + <% if @conference.present? %> + <%= image_tag(conference_logo_url(@conference), style: "display:block;height:70px;width:auto;", alt: @conference.title + ' logo') %> <% end %>
diff --git a/spec/helpers/conference_helper_spec.rb b/spec/helpers/conference_helper_spec.rb index 101d083a..996ffeba 100644 --- a/spec/helpers/conference_helper_spec.rb +++ b/spec/helpers/conference_helper_spec.rb @@ -67,4 +67,26 @@ describe ConferenceHelper, type: :helper do expect(sponsorship_mailto(conference)).to match conference.short_title end end + + describe '#conference_logo_url' do + let(:organization) { create(:organization) } + let(:conference2) { create(:conference, organization: organization) } + + it 'gives the correct logo url' do + mailbot = Mailbot.new + expect(conference_logo_url(conference2)).to eq('snapcon_logo.png') + + File.open('spec/support/logos/1.png') do |file| + organization.picture = file + end + + expect(conference_logo_url(conference2)).to include('1.png') + + File.open('spec/support/logos/2.png') do |file| + conference2.picture = file + end + + expect(conference_logo_url(conference2)).to include('2.png') + end + end end diff --git a/spec/mailers/mailbot_spec.rb b/spec/mailers/mailbot_spec.rb index 65ea4213..6d3b64ad 100644 --- a/spec/mailers/mailbot_spec.rb +++ b/spec/mailers/mailbot_spec.rb @@ -38,6 +38,7 @@ describe Mailbot do expect(mail.body).to include('background-color: ' + conference.color) end + # TODO: test on non-default logo it 'assigns the email body with the correct logo' do expect(mail.body).to include 'snapcon_logo' end @@ -93,28 +94,4 @@ describe Mailbot do context 'update notifications' do it 'is a pending test' end - - context 'helper methods' do - let(:organization) { create(:organization) } - let(:conference2) { create(:conference, organization: organization) } - - describe '#logo_url' do - it 'gives the correct logo url' do - mailbot = Mailbot.new - expect(mailbot.send(:logo_url, conference2)).to eq('snapcon_logo.png') - - File.open('spec/support/logos/1.png') do |file| - organization.picture = file - end - - expect(mailbot.send(:logo_url, conference2)).to include('1.png') - - File.open('spec/support/logos/2.png') do |file| - conference2.picture = file - end - - expect(mailbot.send(:logo_url, conference2)).to include('2.png') - end - end - end end From 72dd36993bf6500e53491c18910b328b019e1606 Mon Sep 17 00:00:00 2001 From: Jimmy Date: Fri, 12 Mar 2021 00:20:30 -0800 Subject: [PATCH 16/18] [style] Remove unused variable --- spec/helpers/conference_helper_spec.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/spec/helpers/conference_helper_spec.rb b/spec/helpers/conference_helper_spec.rb index 996ffeba..e569be09 100644 --- a/spec/helpers/conference_helper_spec.rb +++ b/spec/helpers/conference_helper_spec.rb @@ -73,7 +73,6 @@ describe ConferenceHelper, type: :helper do let(:conference2) { create(:conference, organization: organization) } it 'gives the correct logo url' do - mailbot = Mailbot.new expect(conference_logo_url(conference2)).to eq('snapcon_logo.png') File.open('spec/support/logos/1.png') do |file| From 2bcd7d39b33f14e0aef7bc43ffe781ca91f2e61f Mon Sep 17 00:00:00 2001 From: Jimmy Date: Fri, 12 Mar 2021 07:49:55 -0800 Subject: [PATCH 17/18] [test] Add unit test for conference_helper#conference_color --- spec/factories/conferences.rb | 1 + spec/helpers/conference_helper_spec.rb | 11 +++++++++++ 2 files changed, 12 insertions(+) diff --git a/spec/factories/conferences.rb b/spec/factories/conferences.rb index d1ac5032..1968e54e 100644 --- a/spec/factories/conferences.rb +++ b/spec/factories/conferences.rb @@ -49,6 +49,7 @@ FactoryBot.define do ticket_layout { 'portrait' } description { Faker::Hipster.paragraph } organization + color { '#FFFFFF' } after(:create) do |conference| Role.where(name: 'organizer', resource: conference).first_or_create(description: 'For the organizers of the conference (who shall have full access)') Role.where(name: 'cfp', resource: conference).first_or_create(description: 'For the members of the CfP team') diff --git a/spec/helpers/conference_helper_spec.rb b/spec/helpers/conference_helper_spec.rb index e569be09..4ea48496 100644 --- a/spec/helpers/conference_helper_spec.rb +++ b/spec/helpers/conference_helper_spec.rb @@ -88,4 +88,15 @@ describe ConferenceHelper, type: :helper do expect(conference_logo_url(conference2)).to include('2.png') end end + + describe '#conference_color' do + let(:conference2) { create(:conference, color: '#000000') } + + it 'gives the correct conference color' do + expect(conference_color(conference2)).to eq('#000000') + + conference2.color = '' + expect(conference_color(conference2)).to eq('#0B3559') + end + end end From fcb3dc96c0fc0ef7f0b11bd158d3b1cf0df22e4e Mon Sep 17 00:00:00 2001 From: Jimmy Date: Fri, 12 Mar 2021 21:16:21 -0800 Subject: [PATCH 18/18] [style] Delete comments --- spec/mailers/mailbot_spec.rb | 9 --------- 1 file changed, 9 deletions(-) diff --git a/spec/mailers/mailbot_spec.rb b/spec/mailers/mailbot_spec.rb index 6d3b64ad..4c4bd699 100644 --- a/spec/mailers/mailbot_spec.rb +++ b/spec/mailers/mailbot_spec.rb @@ -27,18 +27,9 @@ describe Mailbot do end it 'assigns the email body with the correct color' do - # p mail.body - # expect(mail.body).to have_selector('#border.background-color', '#0B3559') - # Capybara.within_frame(mail.body) do - # color = find('#border').native.css_value('background-color') - # expect(color).to eq('#0B3559') - # end - - # TODO: select border ... expect(mail.body).to include('background-color: ' + conference.color) end - # TODO: test on non-default logo it 'assigns the email body with the correct logo' do expect(mail.body).to include 'snapcon_logo' end