mirror of
https://github.com/discourse/discourse.git
synced 2025-05-30 07:11:34 +08:00
UX: Use a dropdown for SSL mode for group SMTP (#27932)
Our old group SMTP SSL option was a checkbox, but this was not ideal because there are actually 3 different ways SSL can be used when sending SMTP: * None * SSL/TLS * STARTTLS We got around this before with specific overrides for Gmail, but it's not flexible enough and now people want to use other providers. It's best to be clear, though it is a technical detail. We provide a way to test the SMTP settings before saving them so there should be little chance of messing this up. This commit also converts GroupEmailSettings to a glimmer component.
This commit is contained in:
@ -715,7 +715,6 @@ class GroupsController < ApplicationController
|
||||
params.require(:host)
|
||||
params.require(:username)
|
||||
params.require(:password)
|
||||
params.require(:ssl)
|
||||
|
||||
group = Group.find(params[:group_id])
|
||||
guardian.ensure_can_edit!(group)
|
||||
@ -723,7 +722,6 @@ class GroupsController < ApplicationController
|
||||
RateLimiter.new(current_user, "group_test_email_settings", 5, 1.minute).performed!
|
||||
|
||||
settings = params.except(:group_id, :protocol)
|
||||
enable_tls = settings[:ssl] == "true"
|
||||
email_host = params[:host]
|
||||
|
||||
if !%w[smtp imap].include?(params[:protocol])
|
||||
@ -734,13 +732,19 @@ class GroupsController < ApplicationController
|
||||
begin
|
||||
case params[:protocol]
|
||||
when "smtp"
|
||||
enable_starttls_auto = false
|
||||
settings.delete(:ssl)
|
||||
raise Discourse::InvalidParameters if params[:ssl_mode].blank?
|
||||
|
||||
settings.delete(:ssl_mode)
|
||||
|
||||
if params[:ssl_mode].blank? ||
|
||||
!Group.smtp_ssl_modes.values.include?(params[:ssl_mode].to_i)
|
||||
raise Discourse::InvalidParameters.new("SSL mode must be present and valid")
|
||||
end
|
||||
|
||||
final_settings =
|
||||
settings.merge(
|
||||
enable_tls: enable_tls,
|
||||
enable_starttls_auto: enable_starttls_auto,
|
||||
enable_tls: params[:ssl_mode].to_i == Group.smtp_ssl_modes[:ssl_tls],
|
||||
enable_starttls_auto: params[:ssl_mode].to_i == Group.smtp_ssl_modes[:starttls],
|
||||
).permit(:host, :port, :username, :password, :enable_tls, :enable_starttls_auto, :debug)
|
||||
EmailSettingsValidator.validate_as_user(
|
||||
current_user,
|
||||
@ -748,8 +752,17 @@ class GroupsController < ApplicationController
|
||||
**final_settings.to_h.symbolize_keys,
|
||||
)
|
||||
when "imap"
|
||||
raise Discourse::InvalidParameters if params[:ssl].blank?
|
||||
|
||||
final_settings =
|
||||
settings.merge(ssl: enable_tls).permit(:host, :port, :username, :password, :ssl, :debug)
|
||||
settings.merge(ssl: settings[:ssl] == "true").permit(
|
||||
:host,
|
||||
:port,
|
||||
:username,
|
||||
:password,
|
||||
:ssl,
|
||||
:debug,
|
||||
)
|
||||
EmailSettingsValidator.validate_as_user(
|
||||
current_user,
|
||||
"imap",
|
||||
@ -812,7 +825,7 @@ class GroupsController < ApplicationController
|
||||
:incoming_email,
|
||||
:smtp_server,
|
||||
:smtp_port,
|
||||
:smtp_ssl,
|
||||
:smtp_ssl_mode,
|
||||
:smtp_enabled,
|
||||
:smtp_updated_by,
|
||||
:smtp_updated_at,
|
||||
@ -890,7 +903,7 @@ class GroupsController < ApplicationController
|
||||
|
||||
if should_clear_smtp
|
||||
attributes[:smtp_server] = nil
|
||||
attributes[:smtp_ssl] = false
|
||||
attributes[:smtp_ssl_mode] = false
|
||||
attributes[:smtp_port] = nil
|
||||
attributes[:email_username] = nil
|
||||
attributes[:email_password] = nil
|
||||
|
Reference in New Issue
Block a user