Commit 3149f7251e66ac7a6ea22ddb462bbebc195fd4da
1 parent
26908f96
Exists in
master
and in
28 other branches
Redirect when a page from another profile is requested from a profile domain
Showing
2 changed files
with
23 additions
and
0 deletions
Show diff stats
app/controllers/application_controller.rb
... | ... | @@ -98,6 +98,12 @@ class ApplicationController < ActionController::Base |
98 | 98 | else |
99 | 99 | @environment = @domain.environment |
100 | 100 | @profile = @domain.profile |
101 | + | |
102 | + # Check if the requested profile belongs to another domain | |
103 | + if @profile and !params[:profile].blank? and params[:profile] != @profile.identifier | |
104 | + @profile = @environment.profiles.find_by_identifier params[:profile] | |
105 | + redirect_to params.merge(:host => @profile.default_hostname) | |
106 | + end | |
101 | 107 | end |
102 | 108 | end |
103 | 109 | ... | ... |
test/functional/profile_controller_test.rb
... | ... | @@ -1217,6 +1217,23 @@ class ProfileControllerTest < ActionController::TestCase |
1217 | 1217 | end |
1218 | 1218 | end |
1219 | 1219 | |
1220 | + should 'check different profile from the domain profile' do | |
1221 | + default = Environment.default | |
1222 | + default.domains.create!(:name => 'environment.com') | |
1223 | + profile = create_user('another_user').person | |
1224 | + domain_profile = create_user('domain_user').person | |
1225 | + domain_profile.domains.create!(:name => 'profiledomain.com') | |
1226 | + | |
1227 | + @request.expects(:host).returns('profiledomain.com').at_least_once | |
1228 | + get :index, :profile => profile.identifier | |
1229 | + assert_response :redirect | |
1230 | + assert_redirected_to @request.params.merge(:host => profile.default_hostname) | |
1231 | + | |
1232 | + @request.expects(:host).returns(profile.default_hostname).at_least_once | |
1233 | + get :index, :profile => profile.identifier | |
1234 | + assert_response :success | |
1235 | + end | |
1236 | + | |
1220 | 1237 | should 'redirect to profile domain if it has one' do |
1221 | 1238 | community = fast_create(Community, :name => 'community with domain') |
1222 | 1239 | community.domains << Domain.new(:name => 'community.example.net') | ... | ... |