diff --git a/app/models/person.rb b/app/models/person.rb
index df39448..37e45b3 100644
--- a/app/models/person.rb
+++ b/app/models/person.rb
@@ -74,6 +74,10 @@ class Person < Profile
belongs_to :user, :dependent => :delete
+ def can_change_homepage?
+ !environment.enabled?('cant_change_homepage') || is_admin?
+ end
+
def can_control_scrap?(scrap)
begin
!self.scraps(scrap).nil?
diff --git a/app/views/cms/view.html.erb b/app/views/cms/view.html.erb
index 12a8597..89d416a 100644
--- a/app/views/cms/view.html.erb
+++ b/app/views/cms/view.html.erb
@@ -2,7 +2,7 @@
<%= _('Content management') %>
-<% if !environment.enabled?('cant_change_homepage') && !remove_content_button(:home) %>
+<% if user.can_change_homepage? && !remove_content_button(:home) %>
<%= _('Profile homepage:') %>
<% if profile.home_page %>
@@ -69,7 +69,7 @@
<%= expirable_button article, :edit, _('Edit'), {:action => 'edit', :id => article.id} if !remove_content_button(:edit) %>
<%= button_without_text :eyes, _('Public view'), article.view_url %>
<%= display_spread_button(profile, article) unless article.folder? || remove_content_button(:spread)%>
- <% if !environment.enabled?('cant_change_homepage') && !remove_content_button(:home) %>
+ <% if user.can_change_homepage? && !remove_content_button(:home) %>
<% if profile.home_page != article %>
<%= expirable_button article, :home, _('Use as homepage'), { :action => 'set_home_page', :id => article.id }, :method => :post %>
<% else %>
diff --git a/test/functional/cms_controller_test.rb b/test/functional/cms_controller_test.rb
index fa7b79b..a8bcd31 100644
--- a/test/functional/cms_controller_test.rb
+++ b/test/functional/cms_controller_test.rb
@@ -101,6 +101,13 @@ class CmsControllerTest < ActionController::TestCase
assert_tag :tag => 'div', :content => /Profile homepage/, :attributes => { :class => "cms-homepage"}
end
+ should 'display the profile homepage if logged user is an environment admin' do
+ env = Environment.default; env.enable('cant_change_homepage'); env.save!
+ env.add_admin(profile)
+ get :index, :profile => profile.identifier
+ assert_tag :tag => 'div', :content => /Profile homepage/, :attributes => { :class => "cms-homepage"}
+ end
+
should 'not display the profile homepage if cannot change homepage' do
env = Environment.default; env.enable('cant_change_homepage')
get :index, :profile => profile.identifier
diff --git a/test/unit/person_test.rb b/test/unit/person_test.rb
index b93f9db..61e153d 100644
--- a/test/unit/person_test.rb
+++ b/test/unit/person_test.rb
@@ -1470,4 +1470,18 @@ class PersonTest < ActiveSupport::TestCase
person.reload
end
end
+
+ should 'allow homepage change if user is an environment admin' do
+ person = create_user('person').person
+ person.environment.expects(:enabled?).with('cant_change_homepage').returns(true)
+ person.expects(:is_admin?).returns(true)
+ assert person.can_change_homepage?
+ end
+
+ should 'allow homepage change if environment feature permit it' do
+ person = create_user('person').person
+ person.environment.expects(:enabled?).with('cant_change_homepage').returns(false)
+ assert person.can_change_homepage?
+ end
+
end
--
libgit2 0.21.2