Commit cf88937888c2db332a200fc9f9351b8284ef2581
1 parent
5eff5bf9
Exists in
theme-brasil-digital-from-staging
and in
9 other branches
Fix redirection for profile with a custom domain
Set profile to nil rather than delete the key so the nil value will take precedence over the value stored in request object.
Showing
2 changed files
with
18 additions
and
1 deletions
Show diff stats
lib/needs_profile.rb
| ... | ... | @@ -25,7 +25,11 @@ module NeedsProfile |
| 25 | 25 | if @profile |
| 26 | 26 | profile_hostname = @profile.hostname |
| 27 | 27 | if profile_hostname && profile_hostname != request.host |
| 28 | - params.delete(:profile) | |
| 28 | + if params[:controller] == 'content_viewer' | |
| 29 | + params[:profile] = nil | |
| 30 | + else | |
| 31 | + params.delete(:profile) | |
| 32 | + end | |
| 29 | 33 | redirect_to(Noosfero.url_options.merge(params).merge(:host => profile_hostname)) |
| 30 | 34 | end |
| 31 | 35 | else | ... | ... |
test/functional/content_viewer_controller_test.rb
| ... | ... | @@ -218,6 +218,19 @@ class ContentViewerControllerTest < ActionController::TestCase |
| 218 | 218 | assert_equal profile, assigns(:profile) |
| 219 | 219 | end |
| 220 | 220 | |
| 221 | + should 'redirect to custom profile url when access a content using the environment domain' do | |
| 222 | + environment = Environment.default | |
| 223 | + environment.domains << Domain.create!(:name => 'environmentdomain.net') | |
| 224 | + profile = create_user('mytestuser').person | |
| 225 | + profile.domains << Domain.create!(:name => 'myowndomain.net') | |
| 226 | + profile.articles.create!(:name => 'myarticle', :body => 'test article') | |
| 227 | + | |
| 228 | + ActionController::TestRequest.any_instance.expects(:host).returns('environmentdomain.net').at_least_once | |
| 229 | + | |
| 230 | + get :view_page, :page => ['myarticle'], :profile => 'mytestuser' | |
| 231 | + assert_redirected_to 'http://myowndomain.net/myarticle' | |
| 232 | + end | |
| 233 | + | |
| 221 | 234 | should 'give link to edit the article for owner' do |
| 222 | 235 | login_as('testinguser') |
| 223 | 236 | xhr :get, :view_page, :profile => 'testinguser', :page => [], :toolbar => true | ... | ... |