Commit 83dd0faf85c086defa56b7f2a1bbf5c4dd1f9b59
1 parent
191cbc16
Exists in
master
and in
21 other branches
Always allow environment admins to change homepage
Showing
4 changed files
with
27 additions
and
2 deletions
Show diff stats
app/models/person.rb
| @@ -74,6 +74,10 @@ class Person < Profile | @@ -74,6 +74,10 @@ class Person < Profile | ||
| 74 | 74 | ||
| 75 | belongs_to :user, :dependent => :delete | 75 | belongs_to :user, :dependent => :delete |
| 76 | 76 | ||
| 77 | + def can_change_homepage? | ||
| 78 | + !environment.enabled?('cant_change_homepage') || is_admin? | ||
| 79 | + end | ||
| 80 | + | ||
| 77 | def can_control_scrap?(scrap) | 81 | def can_control_scrap?(scrap) |
| 78 | begin | 82 | begin |
| 79 | !self.scraps(scrap).nil? | 83 | !self.scraps(scrap).nil? |
app/views/cms/view.html.erb
| @@ -2,7 +2,7 @@ | @@ -2,7 +2,7 @@ | ||
| 2 | <%= _('Content management') %> | 2 | <%= _('Content management') %> |
| 3 | </h1> | 3 | </h1> |
| 4 | 4 | ||
| 5 | -<% if !environment.enabled?('cant_change_homepage') && !remove_content_button(:home) %> | 5 | +<% if user.can_change_homepage? && !remove_content_button(:home) %> |
| 6 | <div class="cms-homepage"> | 6 | <div class="cms-homepage"> |
| 7 | <%= _('Profile homepage:') %> | 7 | <%= _('Profile homepage:') %> |
| 8 | <% if profile.home_page %> | 8 | <% if profile.home_page %> |
| @@ -69,7 +69,7 @@ | @@ -69,7 +69,7 @@ | ||
| 69 | <%= expirable_button article, :edit, _('Edit'), {:action => 'edit', :id => article.id} if !remove_content_button(:edit) %> | 69 | <%= expirable_button article, :edit, _('Edit'), {:action => 'edit', :id => article.id} if !remove_content_button(:edit) %> |
| 70 | <%= button_without_text :eyes, _('Public view'), article.view_url %> | 70 | <%= button_without_text :eyes, _('Public view'), article.view_url %> |
| 71 | <%= display_spread_button(profile, article) unless article.folder? || remove_content_button(:spread)%> | 71 | <%= display_spread_button(profile, article) unless article.folder? || remove_content_button(:spread)%> |
| 72 | - <% if !environment.enabled?('cant_change_homepage') && !remove_content_button(:home) %> | 72 | + <% if user.can_change_homepage? && !remove_content_button(:home) %> |
| 73 | <% if profile.home_page != article %> | 73 | <% if profile.home_page != article %> |
| 74 | <%= expirable_button article, :home, _('Use as homepage'), { :action => 'set_home_page', :id => article.id }, :method => :post %> | 74 | <%= expirable_button article, :home, _('Use as homepage'), { :action => 'set_home_page', :id => article.id }, :method => :post %> |
| 75 | <% else %> | 75 | <% else %> |
test/functional/cms_controller_test.rb
| @@ -101,6 +101,13 @@ class CmsControllerTest < ActionController::TestCase | @@ -101,6 +101,13 @@ class CmsControllerTest < ActionController::TestCase | ||
| 101 | assert_tag :tag => 'div', :content => /Profile homepage/, :attributes => { :class => "cms-homepage"} | 101 | assert_tag :tag => 'div', :content => /Profile homepage/, :attributes => { :class => "cms-homepage"} |
| 102 | end | 102 | end |
| 103 | 103 | ||
| 104 | + should 'display the profile homepage if logged user is an environment admin' do | ||
| 105 | + env = Environment.default; env.enable('cant_change_homepage'); env.save! | ||
| 106 | + env.add_admin(profile) | ||
| 107 | + get :index, :profile => profile.identifier | ||
| 108 | + assert_tag :tag => 'div', :content => /Profile homepage/, :attributes => { :class => "cms-homepage"} | ||
| 109 | + end | ||
| 110 | + | ||
| 104 | should 'not display the profile homepage if cannot change homepage' do | 111 | should 'not display the profile homepage if cannot change homepage' do |
| 105 | env = Environment.default; env.enable('cant_change_homepage') | 112 | env = Environment.default; env.enable('cant_change_homepage') |
| 106 | get :index, :profile => profile.identifier | 113 | get :index, :profile => profile.identifier |
test/unit/person_test.rb
| @@ -1470,4 +1470,18 @@ class PersonTest < ActiveSupport::TestCase | @@ -1470,4 +1470,18 @@ class PersonTest < ActiveSupport::TestCase | ||
| 1470 | person.reload | 1470 | person.reload |
| 1471 | end | 1471 | end |
| 1472 | end | 1472 | end |
| 1473 | + | ||
| 1474 | + should 'allow homepage change if user is an environment admin' do | ||
| 1475 | + person = create_user('person').person | ||
| 1476 | + person.environment.expects(:enabled?).with('cant_change_homepage').returns(true) | ||
| 1477 | + person.expects(:is_admin?).returns(true) | ||
| 1478 | + assert person.can_change_homepage? | ||
| 1479 | + end | ||
| 1480 | + | ||
| 1481 | + should 'allow homepage change if environment feature permit it' do | ||
| 1482 | + person = create_user('person').person | ||
| 1483 | + person.environment.expects(:enabled?).with('cant_change_homepage').returns(false) | ||
| 1484 | + assert person.can_change_homepage? | ||
| 1485 | + end | ||
| 1486 | + | ||
| 1473 | end | 1487 | end |