Commit 836e487565ed454d02cd3b71d769d3173324cfb6
Committed by
Daniela Feitosa
1 parent
630b8afa
Exists in
master
and in
22 other branches
Redirecting to own domain if profile has one
(ActionItem2052)
Showing
2 changed files
with
18 additions
and
1 deletions
Show diff stats
lib/needs_profile.rb
| ... | ... | @@ -22,7 +22,15 @@ module NeedsProfile |
| 22 | 22 | |
| 23 | 23 | def load_profile |
| 24 | 24 | @profile ||= environment.profiles.find_by_identifier(params[:profile]) |
| 25 | - render_not_found unless @profile | |
| 25 | + if @profile | |
| 26 | + profile_hostname = @profile.hostname | |
| 27 | + if profile_hostname && request.host == @environment.default_hostname | |
| 28 | + params.delete(:profile) | |
| 29 | + redirect_to(Noosfero.url_options.merge(params).merge(:host => profile_hostname)) | |
| 30 | + end | |
| 31 | + else | |
| 32 | + render_not_found | |
| 33 | + end | |
| 26 | 34 | end |
| 27 | 35 | |
| 28 | 36 | end | ... | ... |
test/functional/profile_controller_test.rb
| ... | ... | @@ -1183,4 +1183,13 @@ class ProfileControllerTest < Test::Unit::TestCase |
| 1183 | 1183 | end |
| 1184 | 1184 | end |
| 1185 | 1185 | |
| 1186 | + should 'redirect to profile domain if it has one' do | |
| 1187 | + community = fast_create(Community, :name => 'community with domain') | |
| 1188 | + community.domains << Domain.new(:name => 'community.example.net') | |
| 1189 | + @request.stubs(:host).returns(community.environment.default_hostname) | |
| 1190 | + get :index, :profile => community.identifier | |
| 1191 | + assert_response :redirect | |
| 1192 | + assert_redirected_to :host => 'community.example.net' | |
| 1193 | + end | |
| 1194 | + | |
| 1186 | 1195 | end | ... | ... |