From b7fbba162bf83b3c6b64d49ac26eb65df7ccffb9 Mon Sep 17 00:00:00 2001 From: Jimmy Date: Mon, 12 Apr 2021 14:01:49 +0800 Subject: [PATCH 1/4] [refactor]Move constants to configuration file --- app/controllers/conferences_controller.rb | 2 +- app/helpers/conference_helper.rb | 4 ++-- app/mailers/mailbot.rb | 6 +++--- config/application.rb | 12 ++++++++++++ 4 files changed, 18 insertions(+), 6 deletions(-) diff --git a/app/controllers/conferences_controller.rb b/app/controllers/conferences_controller.rb index ddb2e506..35e6b709 100644 --- a/app/controllers/conferences_controller.rb +++ b/app/controllers/conferences_controller.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -EVENTS_PER_PAGE = 3 +EVENTS_PER_PAGE = Rails.configuration.conference[:events_per_page] class ConferencesController < ApplicationController include ConferenceHelper diff --git a/app/helpers/conference_helper.rb b/app/helpers/conference_helper.rb index c392a814..0db00eeb 100644 --- a/app/helpers/conference_helper.rb +++ b/app/helpers/conference_helper.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true -DEFAULT_LOGO = 'snapcon_logo.png' -DEFAULT_COLOR = '#0B3559' +DEFAULT_LOGO = Rails.configuration.conference[:default_logo] +DEFAULT_COLOR = Rails.configuration.conference[:default_color] module ConferenceHelper # Return true if only call_for_papers or call_for_tracks or call_for_booths is open diff --git a/app/mailers/mailbot.rb b/app/mailers/mailbot.rb index 2f9d1f77..48eeca7c 100644 --- a/app/mailers/mailbot.rb +++ b/app/mailers/mailbot.rb @@ -1,8 +1,8 @@ # frozen_string_literal: true -SNAPCON_BCC_ADDRESS = 'messages@snap.berkeley.edu' -EMAIL_TEMPLATE = 'email_template' -YTLF_TICKET_ID = 50 +SNAPCON_BCC_ADDRESS = Rails.configuration.mailbot[:bcc_address] +EMAIL_TEMPLATE = Rails.configuration.mailbot[:email_template] +YTLF_TICKET_ID = Rails.configuration.mailbot[:ytlf_ticket_id] class Mailbot < ActionMailer::Base helper ConferenceHelper diff --git a/config/application.rb b/config/application.rb index 18f917aa..d8a8930b 100644 --- a/config/application.rb +++ b/config/application.rb @@ -66,6 +66,18 @@ module Osem config.active_job.queue_adapter = :delayed_job + config.conference = { + events_per_page: 3, + default_logo: 'snapcon_logo.png', + default_color: '#0B3559' + } + + config.mailbot = { + bcc_address: 'messages@snap.berkeley.edu', + email_template: 'email_template', + ytlf_ticket_id: 50 + } + config.before_configuration do env_file = File.join(Rails.root, 'config', 'local_env.yml') if File.exist?(env_file) From 4fcc610b2499d0028cec606fe587eea15207b226 Mon Sep 17 00:00:00 2001 From: Jimmy Date: Tue, 13 Apr 2021 11:03:37 +0800 Subject: [PATCH 2/4] [feat]Config read from environment variables --- app/helpers/conference_helper.rb | 2 +- app/mailers/mailbot.rb | 3 ++- config/application.rb | 10 ++++------ config/environments/development.rb | 5 +++++ config/environments/production.rb | 5 +++++ config/environments/test.rb | 5 +++++ 6 files changed, 22 insertions(+), 8 deletions(-) diff --git a/app/helpers/conference_helper.rb b/app/helpers/conference_helper.rb index 0db00eeb..cf2c06ce 100644 --- a/app/helpers/conference_helper.rb +++ b/app/helpers/conference_helper.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -DEFAULT_LOGO = Rails.configuration.conference[:default_logo] +DEFAULT_LOGO = Rails.configuration.conference[:default_logo_filename] DEFAULT_COLOR = Rails.configuration.conference[:default_color] module ConferenceHelper diff --git a/app/mailers/mailbot.rb b/app/mailers/mailbot.rb index 48eeca7c..33f3c010 100644 --- a/app/mailers/mailbot.rb +++ b/app/mailers/mailbot.rb @@ -1,7 +1,8 @@ # frozen_string_literal: true +EMAIL_TEMPLATE = 'email_template' + SNAPCON_BCC_ADDRESS = Rails.configuration.mailbot[:bcc_address] -EMAIL_TEMPLATE = Rails.configuration.mailbot[:email_template] YTLF_TICKET_ID = Rails.configuration.mailbot[:ytlf_ticket_id] class Mailbot < ActionMailer::Base diff --git a/config/application.rb b/config/application.rb index d8a8930b..1f273e84 100644 --- a/config/application.rb +++ b/config/application.rb @@ -67,15 +67,13 @@ module Osem config.active_job.queue_adapter = :delayed_job config.conference = { - events_per_page: 3, - default_logo: 'snapcon_logo.png', - default_color: '#0B3559' + events_per_page: (ENV['EVENTS_PER_PAGE'] || 3), + default_logo_filename: (ENV['DEFAULT_LOGO_FILENAME'] || 'snapcon_logo.png'), + default_color: (ENV['DEFAULT_COLOR'] || '#0B3559') } config.mailbot = { - bcc_address: 'messages@snap.berkeley.edu', - email_template: 'email_template', - ytlf_ticket_id: 50 + ytlf_ticket_id: (ENV['YTLF_TICKET_ID'] || 50) } config.before_configuration do diff --git a/config/environments/development.rb b/config/environments/development.rb index 5b6263e3..474ed765 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -44,6 +44,11 @@ Osem::Application.configure do # Set the secret key base if it's not set via other means config.secret_key_base ||= 'f4be765bc98e516de82ac01daa8f8aa11c5ca13cb6c911887851ac89457b6c0b056b2361a21b5c08926c9386e0f91eef84fc0b103d522bf00bc0c78ea8ce7c58' + # Test email address + config.mailbot = { + bcc_address: 'test@test.com' + } + # Use omniauth mock credentials OmniAuth.config.test_mode = true diff --git a/config/environments/production.rb b/config/environments/production.rb index d41774af..1f02f976 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -101,4 +101,9 @@ Osem::Application.configure do # Set the secret_key_base from the env, if not set by any other means config.secret_key_base ||= ENV["SECRET_KEY_BASE"] + + # Set bcc email address + config.mailbot = { + bcc_address: ENV['OSEM_MESSAGE_BCC_ADDRESS'] + } end diff --git a/config/environments/test.rb b/config/environments/test.rb index 1a9d4d7b..651ab938 100644 --- a/config/environments/test.rb +++ b/config/environments/test.rb @@ -53,4 +53,9 @@ Osem::Application.configure do end config.assets.precompile += ['mailbot.css'] + + # Test email address + config.mailbot = { + bcc_address: 'test@test.com' + } end From d2f1720d7002a5f5c4c51340322545d301f23728 Mon Sep 17 00:00:00 2001 From: Jimmy Date: Tue, 13 Apr 2021 18:26:38 +0800 Subject: [PATCH 3/4] [fix]Fix mailbot settings --- config/application.rb | 4 ---- config/environments/development.rb | 3 ++- config/environments/production.rb | 3 ++- config/environments/test.rb | 3 ++- 4 files changed, 6 insertions(+), 7 deletions(-) diff --git a/config/application.rb b/config/application.rb index 1f273e84..4e5e9b87 100644 --- a/config/application.rb +++ b/config/application.rb @@ -72,10 +72,6 @@ module Osem default_color: (ENV['DEFAULT_COLOR'] || '#0B3559') } - config.mailbot = { - ytlf_ticket_id: (ENV['YTLF_TICKET_ID'] || 50) - } - config.before_configuration do env_file = File.join(Rails.root, 'config', 'local_env.yml') if File.exist?(env_file) diff --git a/config/environments/development.rb b/config/environments/development.rb index 5d60ba96..38f30d0d 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -44,8 +44,9 @@ Osem::Application.configure do # Set the secret key base if it's not set via other means config.secret_key_base ||= 'f4be765bc98e516de82ac01daa8f8aa11c5ca13cb6c911887851ac89457b6c0b056b2361a21b5c08926c9386e0f91eef84fc0b103d522bf00bc0c78ea8ce7c58' - # Test email address + # Test mailbot settings config.mailbot = { + ytlf_ticket_id: 50 bcc_address: 'test@test.com' } diff --git a/config/environments/production.rb b/config/environments/production.rb index 1f02f976..84db2bb9 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -102,8 +102,9 @@ Osem::Application.configure do # Set the secret_key_base from the env, if not set by any other means config.secret_key_base ||= ENV["SECRET_KEY_BASE"] - # Set bcc email address + # Mailbot settings config.mailbot = { + ytlf_ticket_id: (ENV['YTLF_TICKET_ID'] || 50) bcc_address: ENV['OSEM_MESSAGE_BCC_ADDRESS'] } end diff --git a/config/environments/test.rb b/config/environments/test.rb index 96686b40..a282831c 100644 --- a/config/environments/test.rb +++ b/config/environments/test.rb @@ -52,8 +52,9 @@ Osem::Application.configure do ActiveSupport::Deprecation.silenced = true end - # Test email address + # Test mailbot settings config.mailbot = { + ytlf_ticket_id: 50 bcc_address: 'test@test.com' } end From b70852e67e6ab6a43b51299771b83e51bec2556c Mon Sep 17 00:00:00 2001 From: Jimmy Date: Tue, 13 Apr 2021 18:29:20 +0800 Subject: [PATCH 4/4] [fix]Add comma --- config/environments/development.rb | 4 ++-- config/environments/production.rb | 4 ++-- config/environments/test.rb | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/config/environments/development.rb b/config/environments/development.rb index 38f30d0d..34766ec9 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -46,8 +46,8 @@ Osem::Application.configure do # Test mailbot settings config.mailbot = { - ytlf_ticket_id: 50 - bcc_address: 'test@test.com' + ytlf_ticket_id: 50, + bcc_address: 'test@test.com' } # Use omniauth mock credentials diff --git a/config/environments/production.rb b/config/environments/production.rb index 84db2bb9..fd6b8a90 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -104,7 +104,7 @@ Osem::Application.configure do # Mailbot settings config.mailbot = { - ytlf_ticket_id: (ENV['YTLF_TICKET_ID'] || 50) - bcc_address: ENV['OSEM_MESSAGE_BCC_ADDRESS'] + ytlf_ticket_id: (ENV['YTLF_TICKET_ID'] || 50), + bcc_address: ENV['OSEM_MESSAGE_BCC_ADDRESS'] } end diff --git a/config/environments/test.rb b/config/environments/test.rb index a282831c..9076d8e6 100644 --- a/config/environments/test.rb +++ b/config/environments/test.rb @@ -54,7 +54,7 @@ Osem::Application.configure do # Test mailbot settings config.mailbot = { - ytlf_ticket_id: 50 - bcc_address: 'test@test.com' + ytlf_ticket_id: 50, + bcc_address: 'test@test.com' } end