diff --git a/app/controllers/stories/feeds_controller.rb b/app/controllers/stories/feeds_controller.rb index 11b75addb..84b7cfdb1 100644 --- a/app/controllers/stories/feeds_controller.rb +++ b/app/controllers/stories/feeds_controller.rb @@ -65,8 +65,8 @@ module Stories end def signed_out_base_feed - strategy = AbExperiment.get(experiment: AbExperiment::CURRENT_FEED_STRATEGY_EXPERIMENT, controller: self, user: current_user, - default_value: AbExperiment::ORIGINAL_VARIANT) + strategy = AbExperiment.get(experiment: AbExperiment::CURRENT_FEED_STRATEGY_EXPERIMENT, controller: self, + user: current_user, default_value: AbExperiment::ORIGINAL_VARIANT) feed = if strategy.weighted_query_strategy? Articles::Feeds::WeightedQueryStrategy.new(user: current_user, page: @page, tags: params[:tag]) elsif Settings::UserExperience.feed_strategy == "basic" diff --git a/app/javascript/admin/controllers/config_controller.js b/app/javascript/admin/controllers/config_controller.js index fc4f3ba4a..5aeb63a79 100644 --- a/app/javascript/admin/controllers/config_controller.js +++ b/app/javascript/admin/controllers/config_controller.js @@ -16,6 +16,8 @@ const emailAuthModalBody = `
If you disable Email address as a registration option, people cannot create an account with their email address.
However, people who have already created an account using their email address can continue to login.
`; +// NOTE: In an effort to move away from Stimulus and create consistency across the codebase +// we are using vanilla JavaScript (app/javascript/packs/admin/config) to handle any new interactions. export default class ConfigController extends Controller { static targets = [ 'authenticationProviders', diff --git a/app/javascript/packs/admin/config/smtp.js b/app/javascript/packs/admin/config/smtp.js new file mode 100644 index 000000000..e37a07596 --- /dev/null +++ b/app/javascript/packs/admin/config/smtp.js @@ -0,0 +1,23 @@ +document + .getElementById('settings_smtp_own_email_server') + ?.addEventListener('change', (event) => { + const [customSMTPSection] = document.getElementsByClassName( + 'js-custom-smtp-section', + ); + + if (event.target.checked) { + customSMTPSection.classList.remove('hidden'); + } else { + // when the user indicates that they do not want to use their own server + // we clear the form values except for those fields that have a default value. + const inputs = customSMTPSection.getElementsByTagName('input'); + const haveDefaultValues = ['authentication']; + + for (const input of inputs) { + if (!haveDefaultValues.some((el) => input.name.includes(el))) { + input.value = ''; + } + } + customSMTPSection.classList.add('hidden'); + } + }); diff --git a/app/lib/constants/settings/smtp.rb b/app/lib/constants/settings/smtp.rb index 909506d0f..42e5b131a 100644 --- a/app/lib/constants/settings/smtp.rb +++ b/app/lib/constants/settings/smtp.rb @@ -4,7 +4,7 @@ module Constants DETAILS = { address: { description: "Address of the remote mail server", - placeholder: "ie. smtp.gmail.com" + placeholder: "i.e. smtp.gmail.com" }, port: { description: "The port that your mail server runs on", @@ -12,8 +12,9 @@ module Constants }, authentication: { description: " If your mail server requires authentication, " \ - "you need to specify the authentication type here", - placeholder: "ie. plain, login, or cram_md5" + "you need to specify the authentication type here. " \ + " i.e. plain, login, or cram_md5", + placeholder: "i.e. plain, login, or cram_md5" }, user_name: { description: "If your mail server requires authentication, copy the username from your server", diff --git a/app/models/forem_instance.rb b/app/models/forem_instance.rb index 008a67d89..accd82e9d 100644 --- a/app/models/forem_instance.rb +++ b/app/models/forem_instance.rb @@ -32,6 +32,14 @@ class ForemInstance Settings::SMTP.provided_minimum_settings? || ENV["SENDGRID_API_KEY"].present? end + def self.sendgrid_enabled? + ENV["SENDGRID_API_KEY"].present? + end + + def self.only_sendgrid_enabled? + ForemInstance.sendgrid_enabled? && !Settings::SMTP.provided_minimum_settings? + end + def self.invitation_only? Settings::Authentication.invite_only_mode? end diff --git a/app/models/settings/smtp.rb b/app/models/settings/smtp.rb index da2e8b246..220c397d1 100644 --- a/app/models/settings/smtp.rb +++ b/app/models/settings/smtp.rb @@ -2,11 +2,12 @@ module Settings class SMTP < Base self.table_name = :settings_smtp - OPTIONS = %i[address port authentication user_name password domain].freeze + OPTIONS = %i[user_name password address authentication domain port].freeze + AUTHENTICATION_METHODS = %w[plain login cram_md5].freeze setting :address, type: :string, default: ApplicationConfig["SMTP_ADDRESS"].presence setting :authentication, type: :string, default: ApplicationConfig["SMTP_AUTHENTICATION"].presence, - validates: { inclusion: %w[plain login cram_md5] } + validates: { inclusion: AUTHENTICATION_METHODS } setting :domain, type: :string, default: ApplicationConfig["SMTP_DOMAIN"].presence setting :password, type: :string, default: ApplicationConfig["SMTP_PASSWORD"].presence setting :port, type: :integer, default: ApplicationConfig["SMTP_PORT"].presence || 25 diff --git a/app/services/articles/feeds/weighted_query_strategy.rb b/app/services/articles/feeds/weighted_query_strategy.rb index 5268f639d..2a29a9bd1 100644 --- a/app/services/articles/feeds/weighted_query_strategy.rb +++ b/app/services/articles/feeds/weighted_query_strategy.rb @@ -119,7 +119,7 @@ module Articles # Weight to give to the number of comments on the article. comments_count_factor: { clause: "articles.comments_count", - cases: (0..9).map { |n| [n, 0.8 + 0.02 * n] }, + cases: (0..9).map { |n| [n, 0.8 + (0.02 * n)] }, fallback: 1, requires_user: false, group_by: "articles.comments_count" @@ -190,7 +190,7 @@ module Articles # user follows and the article has. matching_tags_factor: { clause: "LEAST(10.0, SUM(followed_tags.points))::integer", - cases: (0..9).map { |n| [n, 0.70 + 0.0303 * n] }, + cases: (0..9).map { |n| [n, 0.70 + (0.0303 * n)] }, fallback: 1, requires_user: true, joins: ["LEFT OUTER JOIN taggings diff --git a/app/views/admin/settings/forms/_smtp.html.erb b/app/views/admin/settings/forms/_smtp.html.erb index eb57f6763..02f3ecb91 100644 --- a/app/views/admin/settings/forms/_smtp.html.erb +++ b/app/views/admin/settings/forms/_smtp.html.erb @@ -1,22 +1,47 @@ +<%= javascript_packs_with_chunks_tag "admin/config/smtp", defer: true %> + <%= form_for(Settings::SMTP.new, url: admin_settings_smtp_settings_path, - html: { data: { action: "submit->config#updateConfigurationSettings" } }) do |f| %> + html: { data: { + action: "submit->config#updateConfigurationSettings", + testid: "emailServerSettings" + } }) do |f| %>