From a38b18bd0d767753150f3e43f38e317dca2cf294 Mon Sep 17 00:00:00 2001 From: Luis Ramos Date: Wed, 15 Apr 2020 18:29:25 +0100 Subject: [PATCH 1/2] Remove smtp config from admin config page --- .../spree/admin/mail_methods_controller.rb | 4 - .../spree/admin/mail_methods/_form.html.haml | 84 ++++++------------- config/locales/en.yml | 8 -- .../admin/configuration/mail_methods_spec.rb | 9 -- 4 files changed, 26 insertions(+), 79 deletions(-) diff --git a/app/controllers/spree/admin/mail_methods_controller.rb b/app/controllers/spree/admin/mail_methods_controller.rb index 3bc52ce659..e95739148d 100644 --- a/app/controllers/spree/admin/mail_methods_controller.rb +++ b/app/controllers/spree/admin/mail_methods_controller.rb @@ -4,10 +4,6 @@ module Spree after_filter :initialize_mail_settings def update - if params[:smtp_password].blank? - params.delete(:smtp_password) - end - params.each do |name, value| next unless Spree::Config.has_preference? name diff --git a/app/views/spree/admin/mail_methods/_form.html.haml b/app/views/spree/admin/mail_methods/_form.html.haml index 670e37140e..02b7ea11dd 100644 --- a/app/views/spree/admin/mail_methods/_form.html.haml +++ b/app/views/spree/admin/mail_methods/_form.html.haml @@ -1,60 +1,28 @@ %div .row - .alpha.six.columns - %fieldset.no-border-bottom - %legend{align: "center"}= t("spree.general") - .field - = preference_field_tag("enable_mail_delivery", Spree::Config[:enable_mail_delivery], type: :boolean) - = label_tag :enable_mail_delivery, t("spree.enable_mail_delivery") - .field - = label_tag :mails_from, t("spree.send_mails_as") - %br/ - = text_field_tag :mails_from, Spree::Config[:mails_from], maxlength: 256, class: 'fullwidth' - %br/ - %span.info - = t("spree.smtp_send_all_emails_as_from_following_address") - .field - = label_tag :mail_bcc, t("spree.send_copy_of_all_mails_to") - %br/ - = text_field_tag :mail_bcc, Spree::Config[:mail_bcc], maxlength: 256, class: 'fullwidth' - %br/ - %span.info - = t("spree.smtp_send_copy_to_this_addresses") - .field - = label_tag :intercept_email, t("spree.intercept_email_address") - %br/ - = text_field_tag :intercept_email, Spree::Config[:intercept_email], maxlength: 256, class: 'fullwidth' - %br/ - %span.info - = t("spree.intercept_email_instructions") - .six.columns.omega - %fieldset.no-border-bottom - %legend{align: "center"}= t("spree.smtp") - .field - = label_tag :mail_domain, t("spree.smtp_domain") - %br/ - = text_field_tag :mail_domain, Spree::Config[:mail_domain], class: 'fullwidth' - .field - = label_tag :mail_host, t("spree.smtp_mail_host") - %br/ - = text_field_tag :mail_host, Spree::Config[:mail_host], class: 'fullwidth' - .field - = label_tag :mail_port, t("spree.smtp_port") - %br/ - = text_field_tag :mail_port, Spree::Config[:mail_port], class: 'fullwidth' - .field - = label_tag :secure_connection_type, t("spree.secure_connection_type") - %br/ - = select_tag(:secure_connection_type, options_from_collection_for_select(Spree::Core::MailSettings::SECURE_CONNECTION_TYPES.map{|w| Spree.t(w.downcase.to_sym, default: w)}, :to_s, :to_s, Spree::Config[:secure_connection_type]), class: 'select2 fullwidth') - .field - = label_tag :mail_auth_type, t("spree.smtp_authentication_type") - %br/ - = select_tag(:mail_auth_type, options_from_collection_for_select(Spree::Core::MailSettings::MAIL_AUTH.map{|w| Spree.t(w.downcase.to_sym, default: w)}, :to_s, :to_s, Spree::Config[:mail_auth_type]), class: 'select2 fullwidth') - .field - = label_tag :smtp_username, t("spree.smtp_username") - %br/ - = text_field_tag :smtp_username, Spree::Config[:smtp_username], class: 'fullwidth' - .field - = label_tag :preferred_smtp_password, t("spree.smtp_password") - %br/ - = password_field_tag :smtp_password, Spree::Config[:smtp_password], class: 'fullwidth' + %fieldset.no-border-bottom + %legend{align: "center"}= t("spree.general") + .field + = preference_field_tag("enable_mail_delivery", Spree::Config[:enable_mail_delivery], type: :boolean) + = label_tag :enable_mail_delivery, t("spree.enable_mail_delivery") + .field + = label_tag :mails_from, t("spree.send_mails_as") + %br/ + = text_field_tag :mails_from, Spree::Config[:mails_from], maxlength: 256, class: 'fullwidth' + %br/ + %span.info + = t("spree.smtp_send_all_emails_as_from_following_address") + .field + = label_tag :mail_bcc, t("spree.send_copy_of_all_mails_to") + %br/ + = text_field_tag :mail_bcc, Spree::Config[:mail_bcc], maxlength: 256, class: 'fullwidth' + %br/ + %span.info + = t("spree.smtp_send_copy_to_this_addresses") + .field + = label_tag :intercept_email, t("spree.intercept_email_address") + %br/ + = text_field_tag :intercept_email, Spree::Config[:intercept_email], maxlength: 256, class: 'fullwidth' + %br/ + %span.info + = t("spree.intercept_email_instructions") diff --git a/config/locales/en.yml b/config/locales/en.yml index 831dec00f8..da87782fb8 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -2978,14 +2978,6 @@ See the %{link} to find out more about %{sitename}'s features and to start using smtp_send_copy_to_this_addresses: "Sends a copy of all outgoing mails to this address. For multiple addresses, separate with commas." intercept_email_address: "Intercept Email Address" intercept_email_instructions: "Override email recipient and replace with this address." - smtp: "SMTP" - smtp_domain: "SMTP Domain" - smtp_mail_host: "SMTP Mail Host" - smtp_port: "SMTP Port" - secure_connection_type: "Secure Connection Type" - smtp_authentication_type: "SMTP Authentication Type" - smtp_username: "SMTP Username" - smtp_password: "SMTP Password" image_settings: "Image Settings" image_settings_warning: "You will need to regenerate thumbnails if you update the paperclip styles. Use rake paperclip:refresh:thumbnails CLASS=Spree::Image to do this." diff --git a/spec/features/admin/configuration/mail_methods_spec.rb b/spec/features/admin/configuration/mail_methods_spec.rb index 158e4e42a6..6ff8db2d6b 100644 --- a/spec/features/admin/configuration/mail_methods_spec.rb +++ b/spec/features/admin/configuration/mail_methods_spec.rb @@ -19,14 +19,5 @@ describe "Mail Methods" do click_button "Update" expect(page).to have_content("successfully updated!") end - - # Regression test for #2094 - it "does not clear password if not provided" do - Spree::Config[:smtp_password] = "haxme" - click_button "Update" - expect(page).to have_content("successfully updated!") - - expect(Spree::Config[:smtp_password]).not_to be_blank - end end end From 0e5d7c1eb1a3b287224e8fede47e4ac731b07d91 Mon Sep 17 00:00:00 2001 From: Luis Ramos Date: Wed, 29 Apr 2020 13:30:55 +0100 Subject: [PATCH 2/2] Add migration to drop dead spree_mail_methods table and some dead mail_methods preferences --- db/migrate/20200429122446_drop_mail_methods.rb | 16 ++++++++++++++++ db/schema.rb | 9 +-------- lib/tasks/data/anonymize_data.rake | 2 -- 3 files changed, 17 insertions(+), 10 deletions(-) create mode 100644 db/migrate/20200429122446_drop_mail_methods.rb diff --git a/db/migrate/20200429122446_drop_mail_methods.rb b/db/migrate/20200429122446_drop_mail_methods.rb new file mode 100644 index 0000000000..12dba55bbe --- /dev/null +++ b/db/migrate/20200429122446_drop_mail_methods.rb @@ -0,0 +1,16 @@ +class DropMailMethods < ActiveRecord::Migration + def up + drop_table :spree_mail_methods + + # delete mail_method preferences associated with the old MailMethod model + execute "DELETE FROM spree_preferences WHERE key LIKE 'spree/mail_method%'" + end + + def down + create_table :spree_mail_methods do |t| + t.string :environment + t.boolean :active, default: true + t.timestamps + end + end +end diff --git a/db/schema.rb b/db/schema.rb index b00e0bf89e..1004c0bc38 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended to check this file into your version control system. -ActiveRecord::Schema.define(:version => 20200406085833) do +ActiveRecord::Schema.define(:version => 20200429122446) do create_table "adjustment_metadata", :force => true do |t| t.integer "adjustment_id" t.integer "enterprise_id" @@ -505,13 +505,6 @@ ActiveRecord::Schema.define(:version => 20200406085833) do t.datetime "updated_at", :null => false end - create_table "spree_mail_methods", :force => true do |t| - t.string "environment" - t.boolean "active", :default => true - t.datetime "created_at", :null => false - t.datetime "updated_at", :null => false - end - create_table "spree_option_types", :force => true do |t| t.string "name", :limit => 100 t.string "presentation", :limit => 100 diff --git a/lib/tasks/data/anonymize_data.rake b/lib/tasks/data/anonymize_data.rake index f494de99fc..bdc6e37c1f 100644 --- a/lib/tasks/data/anonymize_data.rake +++ b/lib/tasks/data/anonymize_data.rake @@ -18,8 +18,6 @@ namespace :ofn do anonymize_payments_accounts Spree::TokenizedPermission.update_all("token = null") - ActiveRecord::Base.connection.execute("update spree_mail_methods - set environment = '#{Rails.env}'") # Delete all preferences that may contain sensitive information Spree::Preference