Commit 52591d04efebac62ef1b9b10b8a025b773bf41a8
1 parent
8c2a1563
Exists in
master
and in
29 other branches
ActionItem893: retrieving urls from profile to get right hostname
Showing
15 changed files
with
86 additions
and
34 deletions
Show diff stats
app/controllers/public/account_controller.rb
@@ -261,7 +261,11 @@ class AccountController < ApplicationController | @@ -261,7 +261,11 @@ class AccountController < ApplicationController | ||
261 | end | 261 | end |
262 | 262 | ||
263 | def go_to_user_initial_page | 263 | def go_to_user_initial_page |
264 | - redirect_back_or_default(:controller => "profile_editor", :profile => current_user.login, :action => 'index') | 264 | + if environment == current_user.environment |
265 | + redirect_back_or_default(user.admin_url) | ||
266 | + else | ||
267 | + redirect_back_or_default(:controller => 'home') | ||
268 | + end | ||
265 | end | 269 | end |
266 | 270 | ||
267 | end | 271 | end |
app/helpers/application_helper.rb
@@ -121,13 +121,22 @@ module ApplicationHelper | @@ -121,13 +121,22 @@ module ApplicationHelper | ||
121 | end | 121 | end |
122 | 122 | ||
123 | def link_to_homepage(text, profile = nil, options = {}) | 123 | def link_to_homepage(text, profile = nil, options = {}) |
124 | - profile ||= current_user.login | ||
125 | - link_to text, homepage_path(:profile => profile) , options | 124 | + p = if profile |
125 | + Profile[profile] | ||
126 | + else | ||
127 | + user | ||
128 | + end | ||
129 | + | ||
130 | + link_to text, p.url, options | ||
126 | end | 131 | end |
127 | 132 | ||
128 | def link_to_myprofile(text, url = {}, profile = nil, options = {}) | 133 | def link_to_myprofile(text, url = {}, profile = nil, options = {}) |
129 | - profile ||= current_user.login | ||
130 | - link_to text, { :profile => profile, :controller => 'profile_editor' }.merge(url), options | 134 | + p = if profile |
135 | + Profile[profile] | ||
136 | + else | ||
137 | + user | ||
138 | + end | ||
139 | + link_to text, p.admin_url.merge(url), options | ||
131 | end | 140 | end |
132 | 141 | ||
133 | def link_to_document(doc, text = nil) | 142 | def link_to_document(doc, text = nil) |
app/models/person.rb
@@ -154,8 +154,8 @@ class Person < Profile | @@ -154,8 +154,8 @@ class Person < Profile | ||
154 | person.user.save! | 154 | person.user.save! |
155 | end | 155 | end |
156 | 156 | ||
157 | - def is_admin? | ||
158 | - role_assignments.map{|ra|ra.role.permissions}.any? do |ps| | 157 | + def is_admin?(environment) |
158 | + role_assignments.select { |ra| ra.resource == environment }.map{|ra|ra.role.permissions}.any? do |ps| | ||
159 | ps.any? do |p| | 159 | ps.any? do |p| |
160 | ActiveRecord::Base::PERMISSIONS['Environment'].keys.include?(p) | 160 | ActiveRecord::Base::PERMISSIONS['Environment'].keys.include?(p) |
161 | end | 161 | end |
app/views/blocks/profile_info_actions/person.rhtml
@@ -2,7 +2,7 @@ | @@ -2,7 +2,7 @@ | ||
2 | <%if logged_in? && (user != profile) %> | 2 | <%if logged_in? && (user != profile) %> |
3 | 3 | ||
4 | <% if !user.already_request_friendship?(profile) and !user.is_a_friend?(profile) %> | 4 | <% if !user.already_request_friendship?(profile) and !user.is_a_friend?(profile) %> |
5 | - <li><%= link_to content_tag('span', __('Add friend')), { :profile => user.identifier, :controller => 'friends', :action => 'add', :id => profile.id }, :class => 'button with-text icon-add' %></li> | 5 | + <li><%= link_to content_tag('span', __('Add friend')), user.url.merge(:controller => 'friends', :action => 'add', :id => profile.id), :class => 'button with-text icon-add' %></li> |
6 | <% end %> | 6 | <% end %> |
7 | 7 | ||
8 | <% if user.is_a_friend?(profile) && profile.enable_contact? %> | 8 | <% if user.is_a_friend?(profile) && profile.enable_contact? %> |
app/views/home/index.rhtml
app/views/profile_editor/index.rhtml
@@ -21,7 +21,7 @@ | @@ -21,7 +21,7 @@ | ||
21 | 21 | ||
22 | <%= file_manager_button(_('Edit Appearance'), 'icons-app/design-editor.png', :controller => 'themes', :action => 'index') %> | 22 | <%= file_manager_button(_('Edit Appearance'), 'icons-app/design-editor.png', :controller => 'themes', :action => 'index') %> |
23 | 23 | ||
24 | - <%= file_manager_button(_('Edit Header and Footer'), 'icons-app/header-and-footer.png', :controller => 'profile_editor', :action => 'header_footer') unless profile.enterprise? && environment.enabled?('disable_header_and_footer') && !user.is_admin? %> | 24 | + <%= file_manager_button(_('Edit Header and Footer'), 'icons-app/header-and-footer.png', :controller => 'profile_editor', :action => 'header_footer') unless profile.enterprise? && environment.enabled?('disable_header_and_footer') && !user.is_admin?(environment) %> |
25 | 25 | ||
26 | <%= file_manager_button(_('Manage Content'), 'icons-app/cms.png', :controller => 'cms') unless environment.enabled?('disable_cms') || profile.community? %> | 26 | <%= file_manager_button(_('Manage Content'), 'icons-app/cms.png', :controller => 'cms') unless environment.enabled?('disable_cms') || profile.community? %> |
27 | 27 |
app/views/search/communities.rhtml
@@ -14,7 +14,8 @@ | @@ -14,7 +14,8 @@ | ||
14 | 14 | ||
15 | <% if logged_in? %> | 15 | <% if logged_in? %> |
16 | <% button_bar do %> | 16 | <% button_bar do %> |
17 | - <%= button(:add, _('New community'), :controller => 'memberships', :action => 'new_community', :profile => current_user.person.identifier) %> | 17 | + <%# FIXME shouldn't the user create the community in the current environment instead of going to its home environment? %> |
18 | + <%= button(:add, _('New community'), user.url.merge(:controller => 'memberships', :action => 'new_community')) %> | ||
18 | <% end %> | 19 | <% end %> |
19 | <% end %> | 20 | <% end %> |
20 | 21 |
app/views/shared/user_menu.rhtml
@@ -15,9 +15,9 @@ | @@ -15,9 +15,9 @@ | ||
15 | <div id="user_menu_ul"> | 15 | <div id="user_menu_ul"> |
16 | <ul> | 16 | <ul> |
17 | 17 | ||
18 | - <li><a href="<%= homepage_path(:profile => current_user.login) %>" | ||
19 | - help="<%= _('Go to your home page.') %>" | ||
20 | - ><span class="icon-menu-home"></span><%= __('My Home Page') %></a></li> | 18 | + <li> |
19 | + <%= link_to( '<span class="icon-menu-home"></span>' + __('My Home Page'), user.url, :help => _('Go to your home page.'))%> | ||
20 | + </li> | ||
21 | 21 | ||
22 | <!-- li><a href="#"><span class="icon-menu-blog"></span> Meu Blog</a></li --> | 22 | <!-- li><a href="#"><span class="icon-menu-blog"></span> Meu Blog</a></li --> |
23 | 23 | ||
@@ -32,16 +32,16 @@ | @@ -32,16 +32,16 @@ | ||
32 | :help => _('Control panel: change your picture, edit your personal information, create content or change the way your home page looks.') | 32 | :help => _('Control panel: change your picture, edit your personal information, create content or change the way your home page looks.') |
33 | ) %></li> | 33 | ) %></li> |
34 | 34 | ||
35 | - <%= | ||
36 | - '<li>'+ link_to( '<span class="icon-menu-"></span>'+ _('Admin'), | ||
37 | - { :controller => 'admin_panel' }, :id => 'link_admin_panel', | ||
38 | - :help => _('Access the site administration panel.') | ||
39 | - ) + | ||
40 | - '</li>' if user.is_admin? | ||
41 | - %> | 35 | + <% if user.is_admin?(environment) %> |
36 | + <li><%= link_to( '<span class="icon-menu-"></span>'+ _('Admin'), | ||
37 | + {:controller => 'admin_panel' }, | ||
38 | + :id => 'link_admin_panel', | ||
39 | + :help => _('Access the site administration panel.') | ||
40 | + )%></li> | ||
41 | + <% end %> | ||
42 | 42 | ||
43 | <li><%= link_to( '<span class="icon-menu-logout"></span>'+ _('Logout'), | 43 | <li><%= link_to( '<span class="icon-menu-logout"></span>'+ _('Logout'), |
44 | - { :controller => 'account', :action => 'logout'}, | 44 | + {:controller => 'account', :action => 'logout'}, |
45 | :id => 'link_logout', | 45 | :id => 'link_logout', |
46 | :help => _('This link takes you out of the system. You should logout if other people are willing to use the same computer after you.') | 46 | :help => _('This link takes you out of the system. You should logout if other people are willing to use the same computer after you.') |
47 | ) %></li> | 47 | ) %></li> |
test/functional/account_controller_test.rb
@@ -40,6 +40,16 @@ class AccountControllerTest < Test::Unit::TestCase | @@ -40,6 +40,16 @@ class AccountControllerTest < Test::Unit::TestCase | ||
40 | assert_redirected_to :controller => 'profile_editor', :action => 'index', :profile => 'quire' | 40 | assert_redirected_to :controller => 'profile_editor', :action => 'index', :profile => 'quire' |
41 | end | 41 | end |
42 | 42 | ||
43 | + should 'redirect to home when login on other environment' do | ||
44 | + e = Environment.create!(:name => 'other_environment') | ||
45 | + e.domains << Domain.new(:name => 'other.environment') | ||
46 | + e.save! | ||
47 | + u = create_user('test_user', :environment => e).person | ||
48 | + post :login, :user => {:login => 'test_user', :password => 'test_user'} | ||
49 | + | ||
50 | + assert_redirected_to :controller => 'home' | ||
51 | + end | ||
52 | + | ||
43 | def test_should_fail_login_and_not_redirect | 53 | def test_should_fail_login_and_not_redirect |
44 | @request.env["HTTP_REFERER"] = 'bli' | 54 | @request.env["HTTP_REFERER"] = 'bli' |
45 | post :login, :user => {:login => 'johndoe', :password => 'bad password'} | 55 | post :login, :user => {:login => 'johndoe', :password => 'bad password'} |
@@ -275,7 +285,8 @@ class AccountControllerTest < Test::Unit::TestCase | @@ -275,7 +285,8 @@ class AccountControllerTest < Test::Unit::TestCase | ||
275 | end | 285 | end |
276 | 286 | ||
277 | should 'correct redirect after login' do | 287 | should 'correct redirect after login' do |
278 | - post :login, :user => {:login => 'johndoe', :password => 'test'} | 288 | + user = create_user('correct_redirect').person |
289 | + post :login, :user => {:login => 'correct_redirect', :password => 'correct_redirect'} | ||
279 | assert_redirected_to :controller => 'profile_editor' | 290 | assert_redirected_to :controller => 'profile_editor' |
280 | end | 291 | end |
281 | 292 |
test/functional/admin_panel_controller_test.rb
@@ -24,11 +24,6 @@ class AdminPanelControllerTest < Test::Unit::TestCase | @@ -24,11 +24,6 @@ class AdminPanelControllerTest < Test::Unit::TestCase | ||
24 | end | 24 | end |
25 | 25 | ||
26 | should 'manage the correct environment' do | 26 | should 'manage the correct environment' do |
27 | - Environment.destroy_all | ||
28 | - | ||
29 | - default = Environment.create!(:name => 'default env', :is_default => true) | ||
30 | - Environment.stubs(:default).returns(default) | ||
31 | - | ||
32 | current = Environment.create!(:name => 'test environment', :is_default => false) | 27 | current = Environment.create!(:name => 'test environment', :is_default => false) |
33 | current.domains.create!(:name => 'example.com') | 28 | current.domains.create!(:name => 'example.com') |
34 | 29 |
test/functional/application_controller_test.rb
@@ -408,4 +408,20 @@ class ApplicationControllerTest < Test::Unit::TestCase | @@ -408,4 +408,20 @@ class ApplicationControllerTest < Test::Unit::TestCase | ||
408 | get :index, :profile => p.identifier | 408 | get :index, :profile => p.identifier |
409 | assert_tag 'title', :content => p.name + ' - ' + p.environment.name | 409 | assert_tag 'title', :content => p.name + ' - ' + p.environment.name |
410 | end | 410 | end |
411 | + | ||
412 | + should 'display menu links for my environment when logged in other environment' do | ||
413 | + e = Environment.create!(:name => 'other_environment') | ||
414 | + e.domains << Domain.new(:name => 'other.environment') | ||
415 | + e.save! | ||
416 | + | ||
417 | + login_as(create_admin_user(e)) | ||
418 | + uses_host 'other.environment' | ||
419 | + get :index | ||
420 | + assert_tag :tag => 'div', :attributes => {:id => 'user_menu_ul'} | ||
421 | + assert_tag :tag => 'div', :attributes => {:id => 'user_menu_ul'}, | ||
422 | + :descendant => {:tag => 'a', :attributes => { :href => 'http://other.environment/adminuser' }}, | ||
423 | + :descendant => {:tag => 'a', :attributes => { :href => 'http://other.environment/myprofile/adminuser' }}, | ||
424 | + :descendant => {:tag => 'a', :attributes => { :href => '/admin' }} | ||
425 | + end | ||
426 | + | ||
411 | end | 427 | end |
test/functional/profile_controller_test.rb
@@ -172,7 +172,7 @@ class ProfileControllerTest < Test::Unit::TestCase | @@ -172,7 +172,7 @@ class ProfileControllerTest < Test::Unit::TestCase | ||
172 | community = Community.create!(:name => 'my test community') | 172 | community = Community.create!(:name => 'my test community') |
173 | community.add_admin(@profile) | 173 | community.add_admin(@profile) |
174 | get :index, :profile => community.identifier | 174 | get :index, :profile => community.identifier |
175 | - assert_tag :tag => 'a', :attributes => { :href => "/myprofile/#{@profile.identifier}" }, :content => 'Control panel' | 175 | + assert_tag :tag => 'a', :attributes => { :href => /\/myprofile\/#{@profile.identifier}/ }, :content => 'Control panel' |
176 | end | 176 | end |
177 | 177 | ||
178 | should 'show create community in own profile' do | 178 | should 'show create community in own profile' do |
test/integration/login_to_the_application_test.rb
@@ -12,7 +12,8 @@ class LoginToTheApplicationTest < ActionController::IntegrationTest | @@ -12,7 +12,8 @@ class LoginToTheApplicationTest < ActionController::IntegrationTest | ||
12 | get '/account/login_popup' | 12 | get '/account/login_popup' |
13 | assert_response :success | 13 | assert_response :success |
14 | 14 | ||
15 | - login('ze', 'test') | 15 | + create_user('test_user').person |
16 | + login('test_user', 'test_user') | ||
16 | assert_cannot_login | 17 | assert_cannot_login |
17 | assert_can_logout | 18 | assert_can_logout |
18 | 19 |
test/test_helper.rb
@@ -66,7 +66,7 @@ class Test::Unit::TestCase | @@ -66,7 +66,7 @@ class Test::Unit::TestCase | ||
66 | end | 66 | end |
67 | 67 | ||
68 | def create_admin_user(env) | 68 | def create_admin_user(env) |
69 | - admin_user = User.find_by_login('adminuser') || create_user('adminuser', :email => 'adminuser@noosfero.org', :password => 'adminuser', :password_confirmation => 'adminuser') | 69 | + admin_user = User.find_by_login('adminuser') || create_user('adminuser', :email => 'adminuser@noosfero.org', :password => 'adminuser', :password_confirmation => 'adminuser', :environment => env) |
70 | admin_role = Role.find_by_name('admin_role') || Role.create!(:name => 'admin_role', :permissions => ['view_environment_admin_panel','edit_environment_features', 'edit_environment_design', 'manage_environment_categories', 'manage_environment_roles', 'manage_environment_validators']) | 70 | admin_role = Role.find_by_name('admin_role') || Role.create!(:name => 'admin_role', :permissions => ['view_environment_admin_panel','edit_environment_features', 'edit_environment_design', 'manage_environment_categories', 'manage_environment_roles', 'manage_environment_validators']) |
71 | RoleAssignment.create!(:accessor => admin_user.person, :role => admin_role, :resource => env) unless admin_user.person.role_assignments.map{|ra|[ra.role, ra.accessor, ra.resource]}.include?([admin_role, admin_user, env]) | 71 | RoleAssignment.create!(:accessor => admin_user.person, :role => admin_role, :resource => env) unless admin_user.person.role_assignments.map{|ra|[ra.role, ra.accessor, ra.resource]}.include?([admin_role, admin_user, env]) |
72 | admin_user.login | 72 | admin_user.login |
test/unit/person_test.rb
@@ -134,10 +134,27 @@ class PersonTest < Test::Unit::TestCase | @@ -134,10 +134,27 @@ class PersonTest < Test::Unit::TestCase | ||
134 | env = Environment.create!(:name => 'blah') | 134 | env = Environment.create!(:name => 'blah') |
135 | person = create_user('just_another_person').person | 135 | person = create_user('just_another_person').person |
136 | env.affiliate(person, role) | 136 | env.affiliate(person, role) |
137 | - assert ! person.is_admin? | 137 | + assert ! person.is_admin?(env) |
138 | role.update_attributes(:permissions => ['view_environment_admin_panel']) | 138 | role.update_attributes(:permissions => ['view_environment_admin_panel']) |
139 | person = Person.find(person.id) | 139 | person = Person.find(person.id) |
140 | - assert person.is_admin? | 140 | + assert person.is_admin?(env) |
141 | + end | ||
142 | + | ||
143 | + should 'separate admins of different environments' do | ||
144 | + env1 = Environment.create!(:name => 'blah1') | ||
145 | + env2 = Environment.create!(:name => 'blah2') | ||
146 | + | ||
147 | + # role is an admin role | ||
148 | + role = Role.create!(:name => 'just_another_admin_role') | ||
149 | + role.update_attributes(:permissions => ['view_environment_admin_panel']) | ||
150 | + | ||
151 | + # user is admin of env1, but not of env2 | ||
152 | + person = create_user('just_another_person').person | ||
153 | + env1.affiliate(person, role) | ||
154 | + | ||
155 | + person = Person.find(person.id) | ||
156 | + assert person.is_admin?(env1) | ||
157 | + assert !person.is_admin?(env2) | ||
141 | end | 158 | end |
142 | 159 | ||
143 | should 'get a default home page and a RSS feed' do | 160 | should 'get a default home page and a RSS feed' do |