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/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 c055ec84..07249862 100644 --- a/app/mailers/mailbot.rb +++ b/app/mailers/mailbot.rb @@ -5,21 +5,25 @@ EMAIL_TEMPLATE = 'email_template' YTLF_TICKET_ID = 50 class Mailbot < ActionMailer::Base - 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 + helper ConferenceHelper - mail(to: user.email, - bcc: SNAPCON_BCC_ADDRESS, - from: conference.contact.email, - subject: conference.email_settings.registration_subject, - template_name: EMAIL_TEMPLATE) + default bcc: -> { SNAPCON_BCC_ADDRESS }, + template_name: -> { EMAIL_TEMPLATE }, + to: -> { @user.email }, + from: -> { @conference.contact.email } + + def registration_mail(conference, user) + @user = user + @conference = conference + @email_body = @conference.email_settings.generate_email_on_conf_updates(@conference, @user, @conference.email_settings.registration_body) + + 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 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}") @@ -31,138 +35,100 @@ class Mailbot < ActionMailer::Base template_name = 'young_thinkers_ticket_confirmation_template' end - mail(to: @user.email, - bcc: SNAPCON_BCC_ADDRESS, - 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 + @email_body = @conference.email_settings.generate_event_mail(event, @conference.email_settings.accepted_body) - @logo = conference.picture.thumb.url - @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) + mail(subject: @conference.email_settings.accepted_subject) end def submitted_proposal_mail(event) - conference = event.program.conference + @user = event.submitter + @conference = event.program.conference + @email_body = @conference.email_settings.generate_event_mail(event, @conference.email_settings.submitted_proposal_body) - @logo = conference.picture.thumb.url - @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) + mail(subject: @conference.email_settings.submitted_proposal_subject) end def rejection_mail(event) - conference = event.program.conference + @user = event.submitter + @conference = event.program.conference + @email_body = @conference.email_settings.generate_event_mail(event, @conference.email_settings.rejected_body) - @logo = conference.picture.thumb.url - @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) + mail(subject: @conference.email_settings.rejected_subject) end def confirm_reminder_mail(event) - conference = event.program.conference + @user = event.submitter + @conference = event.program.conference + @email_body = @conference.email_settings.generate_event_mail(event, @conference.email_settings.confirmed_without_registration_body) - @logo = conference.picture.thumb.url - @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) + mail(subject: @conference.email_settings.confirmed_without_registration_subject) end def conference_date_update_mail(conference, user) - @logo = conference.picture.thumb.url - @email_body = conference.email_settings.generate_email_on_conf_updates(conference, user, conference.email_settings.conference_dates_updated_body) + @user = user + @conference = 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) + mail(subject: @conference.email_settings.conference_dates_updated_subject) end def conference_registration_date_update_mail(conference, user) - @logo = conference.picture.thumb.url - @email_body = conference.email_settings.generate_email_on_conf_updates(conference, user, conference.email_settings.conference_registration_dates_updated_body) + @user = user + @conference = 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) + mail(subject: @conference.email_settings.conference_registration_dates_updated_subject) end def conference_venue_update_mail(conference, user) - @logo = conference.picture.thumb.url - @email_body = conference.email_settings.generate_email_on_conf_updates(conference, user, conference.email_settings.venue_updated_body) + @user = user + @conference = 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) + mail(subject: @conference.email_settings.venue_updated_subject) end def conference_schedule_update_mail(conference, user) - @logo = conference.picture.thumb.url - @email_body = conference.email_settings.generate_email_on_conf_updates(conference, user, conference.email_settings.program_schedule_public_body) + @user = user + @conference = conference + @email_body = @conference.email_settings.generate_email_on_conf_updates(@conference, @user, @conference.email_settings.program_schedule_public_body) - mail(to: user.email, - from: conference.contact.email, - subject: conference.email_settings.program_schedule_public_subject, - template_name: EMAIL_TEMPLATE) + mail(bcc: nil, + subject: @conference.email_settings.program_schedule_public_subject) end def conference_cfp_update_mail(conference, user) - @logo = conference.picture.thumb.url - @email_body = conference.email_settings.generate_email_on_conf_updates(conference, user, conference.email_settings.cfp_dates_updated_body) + @user = user + @conference = conference + @email_body = @conference.email_settings.generate_email_on_conf_updates(@conference, @user, @conference.email_settings.cfp_dates_updated_body) - mail(to: user.email, - from: conference.contact.email, - subject: conference.email_settings.cfp_dates_updated_subject, - template_name: EMAIL_TEMPLATE) + mail(bcc: nil, + subject: @conference.email_settings.cfp_dates_updated_subject) end def conference_booths_acceptance_mail(booth) - conference = booth.conference - @logo = conference.picture.thumb.url - @email_body = conference.email_settings.generate_booth_mail(booth, conference.email_settings.booths_acceptance_body) + @user = booth.submitter + @conference = booth.conference + @email_body = @conference.email_settings.generate_booth_mail(booth, @conference.email_settings.booths_acceptance_body) - mail(to: booth.submitter.email, - from: conference.contact.email, - subject: conference.email_settings.booths_acceptance_subject, - template_name: EMAIL_TEMPLATE) + mail(bcc: nil, + subject: @conference.email_settings.booths_acceptance_subject) end def conference_booths_rejection_mail(booth) - conference = booth.conference - @logo = conference.picture.thumb.url - @email_body = conference.email_settings.generate_booth_mail(booth, conference.email_settings.booths_rejection_body) + @user = booth.submitter + @conference = booth.conference + @email_body = @conference.email_settings.generate_booth_mail(booth, @conference.email_settings.booths_rejection_body) - mail(to: booth.submitter.email, - from: conference.contact.email, - subject: conference.email_settings.booths_rejection_subject, - template_name: EMAIL_TEMPLATE) + mail(bcc: nil, + subject: @conference.email_settings.booths_rejection_subject) end def event_comment_mail(comment, user) @@ -171,8 +137,7 @@ class Mailbot < ActionMailer::Base @conference = @event.program.conference @user = user - mail(to: @user.email, - from: @conference.contact.email, + mail(bcc: nil, template_name: 'comment_template', subject: "New comment has been posted for #{@event.title}") end diff --git a/app/views/layouts/_mailbot_footer.html.erb b/app/views/layouts/_mailbot_footer.html.erb new file mode 100644 index 00000000..3cc8b3c3 --- /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..12f9d4a5 --- /dev/null +++ b/app/views/layouts/_mailbot_header.html.erb @@ -0,0 +1,25 @@ + + + + + + <%= 'Email' %> + + + + <%= stylesheet_link_tag "mailbot" %> + + +
+
+
+ <% if @conference.present? %> + <%= image_tag(conference_logo_url(@conference), 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 new file mode 100644 index 00000000..b9e9cce0 --- /dev/null +++ b/app/views/mailbot/comment_template.html.erb @@ -0,0 +1,16 @@ +<%= 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/email_template.erb b/app/views/mailbot/email_template.erb deleted file mode 100644 index 429553be..00000000 --- a/app/views/mailbot/email_template.erb +++ /dev/null @@ -1,77 +0,0 @@ - - - - - - - - - - - - - - Email - - -
-
- -
- <% if !@logo.nil? %> - <%= image_tag(@logo, style: "display:block") %> - <% end %> -
-

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

-
- - diff --git a/app/views/mailbot/email_template.html.erb b/app/views/mailbot/email_template.html.erb new file mode 100644 index 00000000..6176cf08 --- /dev/null +++ b/app/views/mailbot/email_template.html.erb @@ -0,0 +1,7 @@ +<%= render partial: "layouts/mailbot_header" %> +
+ + <%= @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 new file mode 100644 index 00000000..f92284d7 --- /dev/null +++ b/app/views/mailbot/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. + + 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..d35d8a1f --- /dev/null +++ b/app/views/mailbot/young_thinkers_ticket_confirmation_template.html.erb @@ -0,0 +1,16 @@ +<%= 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 - -
-
-

-
- - diff --git a/config/environments/development.rb b/config/environments/development.rb index d99d92f0..5b6263e3 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -113,5 +113,7 @@ Osem::Application.configure do devise_config.ichain_test_mode = true end end + + config.assets.precompile += ['mailbot.css'] config.active_record.verbose_query_logs = true 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/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 101d083a..4ea48496 100644 --- a/spec/helpers/conference_helper_spec.rb +++ b/spec/helpers/conference_helper_spec.rb @@ -67,4 +67,36 @@ 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 + 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 + + 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 diff --git a/spec/mailers/mailbot_spec.rb b/spec/mailers/mailbot_spec.rb index 1f739997..4c4bd699 100644 --- a/spec/mailers/mailbot_spec.rb +++ b/spec/mailers/mailbot_spec.rb @@ -26,6 +26,14 @@ describe Mailbot 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 + 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 + it 'delivers the email' do expect(ActionMailer::Base.deliveries).to include(mail) end