diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 7d51312..9b4cee5 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -98,6 +98,12 @@ class ApplicationController < ActionController::Base else @environment = @domain.environment @profile = @domain.profile + + # Check if the requested profile belongs to another domain + if @profile and !params[:profile].blank? and params[:profile] != @profile.identifier + @profile = @environment.profiles.find_by_identifier params[:profile] + redirect_to params.merge(:host => @profile.default_hostname) + end end end diff --git a/test/functional/profile_controller_test.rb b/test/functional/profile_controller_test.rb index d651865..c03003c 100644 --- a/test/functional/profile_controller_test.rb +++ b/test/functional/profile_controller_test.rb @@ -1217,6 +1217,23 @@ class ProfileControllerTest < ActionController::TestCase end end + should 'check different profile from the domain profile' do + default = Environment.default + default.domains.create!(:name => 'environment.com') + profile = create_user('another_user').person + domain_profile = create_user('domain_user').person + domain_profile.domains.create!(:name => 'profiledomain.com') + + @request.expects(:host).returns('profiledomain.com').at_least_once + get :index, :profile => profile.identifier + assert_response :redirect + assert_redirected_to @request.params.merge(:host => profile.default_hostname) + + @request.expects(:host).returns(profile.default_hostname).at_least_once + get :index, :profile => profile.identifier + assert_response :success + end + should 'redirect to profile domain if it has one' do community = fast_create(Community, :name => 'community with domain') community.domains << Domain.new(:name => 'community.example.net') -- libgit2 0.21.2