diff --git a/app/controllers/admin/settings/general_settings_controller.rb b/app/controllers/admin/settings/general_settings_controller.rb index 3a7b2f039..8927ae309 100644 --- a/app/controllers/admin/settings/general_settings_controller.rb +++ b/app/controllers/admin/settings/general_settings_controller.rb @@ -3,7 +3,6 @@ module Admin class GeneralSettingsController < Admin::Settings::BaseController SPECIAL_PARAMS_TO_ADD = %w[ credit_prices_in_cents - email_addresses meta_keywords ].freeze @@ -27,13 +26,9 @@ module Admin end def settings_params - has_emails = params.dig(:settings_general, :email_addresses).present? - params[:settings_general][:email_addresses][:default] = ApplicationConfig["DEFAULT_EMAIL"] if has_emails - params.require(:settings_general)&.permit( settings_keys.map(&:to_sym), social_media_handles: ::Settings::General.social_media_handles.keys, - email_addresses: ::Settings::General.email_addresses.keys, meta_keywords: ::Settings::General.meta_keywords.keys, credit_prices_in_cents: ::Settings::General.credit_prices_in_cents.keys, ) diff --git a/app/controllers/admin/users_controller.rb b/app/controllers/admin/users_controller.rb index 9679c7ed8..56280a3c7 100644 --- a/app/controllers/admin/users_controller.rb +++ b/app/controllers/admin/users_controller.rb @@ -73,7 +73,7 @@ module Admin user = User.find(params[:id]) send_to_admin = params[:send_to_admin].to_boolean if send_to_admin - email = ::Settings::General.email_addresses[:default] + email = ::ForemInstance.email receiver = "admin" else email = user.email diff --git a/app/controllers/api_secrets_controller.rb b/app/controllers/api_secrets_controller.rb index af6bfea13..1bb219ce7 100644 --- a/app/controllers/api_secrets_controller.rb +++ b/app/controllers/api_secrets_controller.rb @@ -24,7 +24,7 @@ class ApiSecretsController < ApplicationController flash[:notice] = "Your API Key has been revoked." else flash[:error] = - "An error occurred. Please try again or send an email to: #{Settings::General.email_addresses[:default]}" + "An error occurred. Please try again or send an email to: #{ForemInstance.email}" end redirect_back(fallback_location: root_path) diff --git a/app/controllers/confirmations_controller.rb b/app/controllers/confirmations_controller.rb index 264c63009..c6f2e7667 100644 --- a/app/controllers/confirmations_controller.rb +++ b/app/controllers/confirmations_controller.rb @@ -6,7 +6,7 @@ class ConfirmationsController < Devise::ConfirmationsController self.resource = resource_class.send_confirmation_instructions(resource_params) resource.errors.clear # Don't leak user information, like paranoid mode. - message = format(FLASH_MESSAGE, email: Settings::General.email_addresses[:default]) + message = format(FLASH_MESSAGE, email: ForemInstance.email) flash.now[:global_notice] = message render :new end diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 7b98fd5fb..b90c4206f 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -134,7 +134,7 @@ class UsersController < ApplicationController def remove_identity set_current_tab("account") - error_message = format(REMOVE_IDENTITY_ERROR, email: Settings::General.email_addresses[:default]) + error_message = format(REMOVE_IDENTITY_ERROR, email: ForemInstance.email) unless Authentication::Providers.enabled?(params[:provider]) flash[:error] = error_message redirect_to user_settings_path(@tab) diff --git a/app/errors/authentication/errors.rb b/app/errors/authentication/errors.rb index 6400d16b1..81386b3e8 100644 --- a/app/errors/authentication/errors.rb +++ b/app/errors/authentication/errors.rb @@ -19,7 +19,7 @@ module Authentication def message format(PREVIOUSLY_SUSPENDED_MESSAGE, community_name: Settings::Community.community_name, - community_email: Settings::General.email_addresses[:default]) + community_email: ForemInstance.email) end end end diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index fab460924..6b28399c3 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -195,7 +195,7 @@ module ApplicationHelper end def email_link(text: nil, additional_info: nil) - email = Settings::General.email_addresses[:default] + email = ForemInstance.email mail_to email, text || email, additional_info end diff --git a/app/lib/constants/settings/general.rb b/app/lib/constants/settings/general.rb index 83b94c638..39f1a1a70 100644 --- a/app/lib/constants/settings/general.rb +++ b/app/lib/constants/settings/general.rb @@ -23,10 +23,6 @@ module Constants placeholder: "" } }, - email_addresses: { - description: "Email address", - placeholder: "" - }, favicon_url: { description: "Used as the site favicon", placeholder: IMAGE_PLACEHOLDER diff --git a/app/mailers/application_mailer.rb b/app/mailers/application_mailer.rb index 9d51949a5..db4337163 100644 --- a/app/mailers/application_mailer.rb +++ b/app/mailers/application_mailer.rb @@ -12,7 +12,7 @@ class ApplicationMailer < ActionMailer::Base default( from: -> { email_from }, template_path: ->(mailer) { "mailers/#{mailer.class.name.underscore}" }, - reply_to: -> { Settings::General.email_addresses[:default] }, + reply_to: -> { ForemInstance.email }, ) def email_from(topic = "") @@ -22,7 +22,7 @@ class ApplicationMailer < ActionMailer::Base Settings::Community.community_name end - "#{community_name} <#{Settings::General.email_addresses[:default]}>" + "#{community_name} <#{ForemInstance.email}>" end def generate_unsubscribe_token(id, email_type) diff --git a/app/mailers/devise_mailer.rb b/app/mailers/devise_mailer.rb index 303fecafa..4c695e947 100644 --- a/app/mailers/devise_mailer.rb +++ b/app/mailers/devise_mailer.rb @@ -3,7 +3,7 @@ class DeviseMailer < Devise::Mailer def use_settings_general_values Devise.mailer_sender = - "#{Settings::Community.community_name} <#{Settings::General.email_addresses[:default]}>" + "#{Settings::Community.community_name} <#{ForemInstance.email}>" ActionMailer::Base.default_url_options[:host] = Settings::General.app_domain end end diff --git a/app/mailers/verification_mailer.rb b/app/mailers/verification_mailer.rb index 78eb06b7e..d0ec0fdbd 100644 --- a/app/mailers/verification_mailer.rb +++ b/app/mailers/verification_mailer.rb @@ -1,6 +1,6 @@ class VerificationMailer < ApplicationMailer default from: lambda { - "#{Settings::Community.community_name} Email Verification <#{Settings::General.email_addresses[:default]}>" + "#{Settings::Community.community_name} Email Verification <#{ForemInstance.email}>" } def account_ownership_verification_email diff --git a/app/models/forem_instance.rb b/app/models/forem_instance.rb index 5c9b02545..1da2c2008 100644 --- a/app/models/forem_instance.rb +++ b/app/models/forem_instance.rb @@ -9,6 +9,10 @@ class ForemInstance @latest_commit_id ||= ApplicationConfig["FOREM_BUILD_SHA"].presence || ENV["HEROKU_SLUG_COMMIT"].presence end + def self.email + ApplicationConfig["DEFAULT_EMAIL"] + end + # Return true if we are operating on a local installation, false otherwise def self.local? Settings::General.app_domain.include?("localhost") diff --git a/app/models/settings/general.rb b/app/models/settings/general.rb index 43d6deb60..01b60c68b 100644 --- a/app/models/settings/general.rb +++ b/app/models/settings/general.rb @@ -27,15 +27,6 @@ module Settings field :health_check_token, type: :string field :video_encoder_key, type: :string - # Emails - field :email_addresses, type: :hash, default: { - default: ApplicationConfig["DEFAULT_EMAIL"], - contact: ApplicationConfig["DEFAULT_EMAIL"], - business: ApplicationConfig["DEFAULT_EMAIL"], - privacy: ApplicationConfig["DEFAULT_EMAIL"], - members: ApplicationConfig["DEFAULT_EMAIL"] - } - # Email digest frequency field :periodic_email_digest, type: :integer, default: 2 diff --git a/app/services/error_messages/clean.rb b/app/services/error_messages/clean.rb index 71a2edada..3e1d813da 100644 --- a/app/services/error_messages/clean.rb +++ b/app/services/error_messages/clean.rb @@ -9,7 +9,7 @@ module ErrorMessages def self.call(error_message) return error_message unless error_message.match?(FRONTMATTER_ERROR) - format(REPLACEMENT_ERROR, Settings::General.email_addresses[:default]) + format(REPLACEMENT_ERROR, ForemInstance.email) end end end diff --git a/app/views/admin/settings/show.html.erb b/app/views/admin/settings/show.html.erb index 3c463fe23..275a4a412 100644 --- a/app/views/admin/settings/show.html.erb +++ b/app/views/admin/settings/show.html.erb @@ -584,30 +584,28 @@ <% end %> - <%= form_for(Settings::General.new, url: admin_settings_general_settings_path) do |f| %> -
Exporting the data to your admin account will send it to your contact - admin email (<%= Settings::General.email_addresses[:default] %>), + admin email (<%= ForemInstance.email %>), and exporting to the user will send it to their email (<%= @user.email %>).
- Make sure it's installed and try again. If the problem persists contact <%= Settings::General.email_addresses[:contact] %> + Make sure it's installed and try again. If the problem persists contact <%= ForemInstance.email %>
Questions? Email us at - <%= Settings::General.email_addresses[:default] %> + <%= ForemInstance.email %> for help.
diff --git a/lib/data_update_scripts/20210509105151_remove_unused_site_config_emails.rb b/lib/data_update_scripts/20210509105151_remove_unused_site_config_emails.rb deleted file mode 100644 index 95044e520..000000000 --- a/lib/data_update_scripts/20210509105151_remove_unused_site_config_emails.rb +++ /dev/null @@ -1,9 +0,0 @@ -module DataUpdateScripts - class RemoveUnusedSiteConfigEmails - def run - Settings::General.email_addresses = { - default: ApplicationConfig["DEFAULT_EMAIL"] - } - end - end -end diff --git a/lib/data_update_scripts/20210604104735_remove_email_addresses_scripts.rb b/lib/data_update_scripts/20210604104735_remove_email_addresses_scripts.rb new file mode 100644 index 000000000..b3c9196c3 --- /dev/null +++ b/lib/data_update_scripts/20210604104735_remove_email_addresses_scripts.rb @@ -0,0 +1,8 @@ +module DataUpdateScripts + class RemoveEmailAddressesScripts + def run + DataUpdateScript.delete_by(file_name: "20210509105151_remove_unused_site_config_emails") + Settings::General.delete_by(var: :email_addresses) + end + end +end diff --git a/spec/helpers/application_helper_spec.rb b/spec/helpers/application_helper_spec.rb index 3380e15cf..36803c4d0 100644 --- a/spec/helpers/application_helper_spec.rb +++ b/spec/helpers/application_helper_spec.rb @@ -161,11 +161,7 @@ RSpec.describe ApplicationHelper, type: :helper do let(:default_email) { "hi@dev.to" } before do - allow(Settings::General).to receive(:email_addresses).and_return( - { - default: default_email - }, - ) + allow(ForemInstance).to receive(:email).and_return(default_email) end it "returns an 'a' tag" do diff --git a/spec/lib/data_update_scripts/remove_unused_site_config_emails_spec.rb b/spec/lib/data_update_scripts/remove_unused_site_config_emails_spec.rb deleted file mode 100644 index dbfdbcb78..000000000 --- a/spec/lib/data_update_scripts/remove_unused_site_config_emails_spec.rb +++ /dev/null @@ -1,23 +0,0 @@ -require "rails_helper" -require Rails.root.join( - "lib/data_update_scripts/20210509105151_remove_unused_site_config_emails.rb", -) - -describe DataUpdateScripts::RemoveUnusedSiteConfigEmails do - let(:contact_email) { "contact@dev.to" } - - before do - Settings::General.email_addresses = { - default: ApplicationConfig["DEFAULT_EMAIL"], - contact: "contact@dev.to", - business: "business@dev.to", - privacy: "privacy@dev.to", - members: "members@dev.to" - } - end - - it "removes the unused emails" do - described_class.new.run - expect(Settings::General.email_addresses.symbolize_keys).to eq(default: ApplicationConfig["DEFAULT_EMAIL"]) - end -end diff --git a/spec/mailers/devise_mailer_spec.rb b/spec/mailers/devise_mailer_spec.rb index a429d80bc..dc5d64fb4 100644 --- a/spec/mailers/devise_mailer_spec.rb +++ b/spec/mailers/devise_mailer_spec.rb @@ -11,7 +11,7 @@ RSpec.describe DeviseMailer, type: :mailer do end it "renders sender" do - expected_from = "#{Settings::Community.community_name} <#{Settings::General.email_addresses[:default]}>" + expected_from = "#{Settings::Community.community_name} <#{ForemInstance.email}>" expect(email["from"].value).to eq(expected_from) end diff --git a/spec/mailers/digest_mailer_spec.rb b/spec/mailers/digest_mailer_spec.rb index 8a2f23b6c..ba2173cd6 100644 --- a/spec/mailers/digest_mailer_spec.rb +++ b/spec/mailers/digest_mailer_spec.rb @@ -14,8 +14,8 @@ RSpec.describe DigestMailer, type: :mailer do expect(email.subject).not_to be_nil expect(email.to).to eq([user.email]) - expect(email.from).to eq([Settings::General.email_addresses[:default]]) - expected_from = "#{Settings::Community.community_name} Digest <#{Settings::General.email_addresses[:default]}>" + expect(email.from).to eq([ForemInstance.email]) + expected_from = "#{Settings::Community.community_name} Digest <#{ForemInstance.email}>" expect(email["from"].value).to eq(expected_from) end end diff --git a/spec/mailers/notify_mailer_spec.rb b/spec/mailers/notify_mailer_spec.rb index c1fd13ea6..5ca4f4545 100644 --- a/spec/mailers/notify_mailer_spec.rb +++ b/spec/mailers/notify_mailer_spec.rb @@ -432,17 +432,17 @@ RSpec.describe NotifyMailer, type: :mailer do end it "renders proper sender" do - expected_from = "#{Settings::Community.community_name} <#{Settings::General.email_addresses[:default]}>" + expected_from = "#{Settings::Community.community_name} <#{ForemInstance.email}>" - expect(moderator_email.from).to eq([Settings::General.email_addresses[:default]]) + expect(moderator_email.from).to eq([ForemInstance.email]) expect(moderator_email["from"].value).to eq(expected_from) - expect(member_email.from).to eq([Settings::General.email_addresses[:default]]) + expect(member_email.from).to eq([ForemInstance.email]) expect(member_email["from"].value).to eq(expected_from) end it "renders proper reply_to" do - expect(moderator_email["reply_to"].value).to eq(Settings::General.email_addresses[:default]) + expect(moderator_email["reply_to"].value).to eq(ForemInstance.email) end it "renders proper receiver" do diff --git a/spec/mailers/shared_examples/renders_proper_email_headers.rb b/spec/mailers/shared_examples/renders_proper_email_headers.rb index 45e9f728b..5fe49296d 100644 --- a/spec/mailers/shared_examples/renders_proper_email_headers.rb +++ b/spec/mailers/shared_examples/renders_proper_email_headers.rb @@ -1,11 +1,11 @@ RSpec.shared_examples "#renders_proper_email_headers" do it "renders proper sender" do - expect(email.from).to eq([Settings::General.email_addresses[:default]]) - expected_from = "#{Settings::Community.community_name} <#{Settings::General.email_addresses[:default]}>" + expect(email.from).to eq([ForemInstance.email]) + expected_from = "#{Settings::Community.community_name} <#{ForemInstance.email}>" expect(email["from"].value).to eq(expected_from) end it "renders proper reply_to" do - expect(email["reply_to"].value).to eq(Settings::General.email_addresses[:default]) + expect(email["reply_to"].value).to eq(ForemInstance.email) end end diff --git a/spec/mailers/verification_mailer_spec.rb b/spec/mailers/verification_mailer_spec.rb index 9cf883788..0960bacd9 100644 --- a/spec/mailers/verification_mailer_spec.rb +++ b/spec/mailers/verification_mailer_spec.rb @@ -9,8 +9,8 @@ RSpec.describe VerificationMailer, type: :mailer do expect(email.subject).not_to be_nil expect(email.to).to eq([user.email]) - expect(email.from).to eq([Settings::General.email_addresses[:default]]) - from = "#{Settings::Community.community_name} Email Verification <#{Settings::General.email_addresses[:default]}>" + expect(email.from).to eq([ForemInstance.email]) + from = "#{Settings::Community.community_name} Email Verification <#{ForemInstance.email}>" expect(email["from"].value).to eq(from) end end diff --git a/spec/requests/admin/configs_spec.rb b/spec/requests/admin/configs_spec.rb index 079ef9d4f..bbe8425b6 100644 --- a/spec/requests/admin/configs_spec.rb +++ b/spec/requests/admin/configs_spec.rb @@ -289,7 +289,7 @@ RSpec.describe "/admin/customization/config", type: :request do confirmation: confirmation_message } - expect(Settings::General.email_addresses[:default]).not_to eq("random@example.com") + expect(ForemInstance.email).not_to eq("random@example.com") end end diff --git a/spec/requests/user/user_settings_spec.rb b/spec/requests/user/user_settings_spec.rb index 6b30d9d9e..6dc442999 100644 --- a/spec/requests/user/user_settings_spec.rb +++ b/spec/requests/user/user_settings_spec.rb @@ -401,7 +401,7 @@ RSpec.describe "UserSettings", type: :request do expect(response).to redirect_to("/settings/account") error = - "An error occurred. Please try again or send an email to: #{Settings::General.email_addresses[:default]}" + "An error occurred. Please try again or send an email to: #{ForemInstance.email}" expect(flash[:error]).to eq(error) end @@ -444,7 +444,7 @@ RSpec.describe "UserSettings", type: :request do delete users_remove_identity_path, params: { provider: provider } error = - "An error occurred. Please try again or send an email to: #{Settings::General.email_addresses[:default]}" + "An error occurred. Please try again or send an email to: #{ForemInstance.email}" expect(flash[:error]).to eq(error) end diff --git a/spec/services/exporter/service_spec.rb b/spec/services/exporter/service_spec.rb index e182d6471..7a08e5f46 100644 --- a/spec/services/exporter/service_spec.rb +++ b/spec/services/exporter/service_spec.rb @@ -94,7 +94,7 @@ RSpec.describe Exporter::Service, type: :service do context "when emailing an admin" do it "delivers one email to the contact admin email" do admin_email = "admin@example.com" - allow(Settings::General).to receive(:email_addresses).and_return({ contact: admin_email }) + allow(ForemInstance).to receive(:email).and_return(admin_email) service = valid_instance(article.user) service.export(admin_email) expect(ActionMailer::Base.deliveries.last.to.first).to eq admin_email diff --git a/spec/system/authentication/user_request_confirmation_spec.rb b/spec/system/authentication/user_request_confirmation_spec.rb index c306a6f2c..1d0d227ed 100644 --- a/spec/system/authentication/user_request_confirmation_spec.rb +++ b/spec/system/authentication/user_request_confirmation_spec.rb @@ -8,7 +8,7 @@ RSpec.describe "/confirm-email", type: :system do expect(page).to have_current_path(user_confirmation_path) expected_message = format(ConfirmationsController::FLASH_MESSAGE, - email: Settings::General.email_addresses[:default]) + email: ForemInstance.email) expect(page).to have_content(expected_message) end end