Skip to content

Commit

Permalink
[bug fix] Cannot change account email from user settings (#1403)
Browse files Browse the repository at this point in the history
  • Loading branch information
donrestarone and Pralish authored Feb 6, 2023
1 parent a1c806e commit 567bcf8
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 3 deletions.
4 changes: 4 additions & 0 deletions app/models/subdomain.rb
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,10 @@ def send_analytics_report
UserMailer.analytics_report(self).deliver_later
end

def subdomain_name
self.name == Subdomain::ROOT_DOMAIN_NAME ? 'www' : self.name
end

private

def change_2fa_setting
Expand Down
2 changes: 1 addition & 1 deletion app/views/shared/_company_logo.haml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
- if Subdomain.current.logo.attached?
= link_to root_url(subdomain: Subdomain.current.name), target: '_blank', class: 'd-flex justify-content-center align-items-center' do
- path = rails_blob_url(Subdomain.current.logo, subdomain: Subdomain.current.name == Subdomain::ROOT_DOMAIN_NAME ? 'www' : Subdomain.current.name)
- path = rails_blob_url(Subdomain.current.logo, subdomain: Subdomain.current.subdomain_name)
= image_tag(path, class: 'd-none d-lg-block img-fluid p-4', size: '150x150')

2 changes: 1 addition & 1 deletion app/views/users/mailer/confirmation_instructions.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
%p
= "Welcome #{@email}!"
%p You can confirm your account email through the link below:
%p= link_to 'Confirm my account', confirmation_url(@resource, confirmation_token: @token, subdomain: Subdomain.current.name)
%p= link_to 'Confirm my account', confirmation_url(@resource, confirmation_token: @token, subdomain: Subdomain.current.subdomain_name)
2 changes: 1 addition & 1 deletion config/sitemap.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@


Subdomain.all.each do |subdomain|
subdomain_name = subdomain.name == Subdomain::ROOT_DOMAIN_NAME ? 'www' : subdomain.name
subdomain_name = subdomain.subdomain_name
sitemap_path = "/sitemaps/#{subdomain_name}/sitemap.xml.gz"
SitemapGenerator::Sitemap.default_host = "https://#{subdomain_name}.#{ENV['APP_HOST']}"
SitemapGenerator::Sitemap.sitemaps_path = "sitemaps/#{subdomain_name}"
Expand Down
24 changes: 24 additions & 0 deletions test/controllers/users/registrations_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -394,4 +394,28 @@ class Users::RegistrationsControllerTest < ActionDispatch::IntegrationTest
get edit_user_registration_path
assert_nil session[:otp_user_id]
end

test '#update email: should send confirmation email with correct confirmation url' do
payload = {
user: {
email: '[email protected]',
current_password: '123456'
}
}
assert_changes "Devise.mailer.deliveries.size", +1 do
sign_in(@user)
patch user_registration_url, params: payload
end

assert_includes Devise.mailer.deliveries.last.body.to_s, "http://public.localhost/users/confirmation?confirmation_token=#{@user.reload.confirmation_token}"

Subdomain.current.update(name: 'root')

assert_changes "Devise.mailer.deliveries.size", +1 do
sign_in(@user)
patch user_registration_url, params: payload
end

assert_includes Devise.mailer.deliveries.last.body.to_s, "http://www.localhost/users/confirmation?confirmation_token=#{@user.reload.confirmation_token}"
end
end
12 changes: 12 additions & 0 deletions test/models/subdomain_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -195,4 +195,16 @@ class SubdomainTest < ActiveSupport::TestCase
end
end
end

test 'subdomain_name when name is not ROOT_DOMAIN_NAME' do
ENV['APP_HOST']="lvh.me:5250"
subdomain = Subdomain.new(name: "test")
assert_equal 'test', subdomain.subdomain_name
end

test 'subdomain_name when name is ROOT_DOMAIN_NAME' do
ENV['APP_HOST']="lvh.me:5250"
subdomain = Subdomain.new(name: Subdomain::ROOT_DOMAIN_NAME)
assert_equal 'www', subdomain.subdomain_name
end
end

0 comments on commit 567bcf8

Please sign in to comment.