Commit 39d689dc5e701720cdd95830c6e52360aea0a753

Authored by Luciano Prestes
1 parent a7e0c611

Add option to block appearence edit

Signed-off-by: DylanGuedes <djmgguedes@gmail.com>
Signed-off-by: Luciano Prestes Cavalcanti <lucianopcbr@gmail.com>
Signed-off-by: Omar Junior <omarroinuj@gmail.com>
Signed-off-by: vitorbaraujo <vitornga15@gmail.com>
app/controllers/my_profile/profile_editor_controller.rb
... ... @@ -10,6 +10,7 @@ class ProfileEditorController &lt; MyProfileController
10 10  
11 11 def index
12 12 @pending_tasks = Task.to(profile).pending.without_spam.select{|i| user.has_permission?(i.permission, profile)}
  13 + @show_appearance_option = user.is_admin?(environment) || !environment.enabled?('disable_appearance')
13 14 end
14 15  
15 16 helper :profile
... ...
app/controllers/themes_controller.rb
1 1 class ThemesController < ApplicationController
2 2  
3 3 before_filter :login_required
  4 + before_filter :check_user_can_edit_appearance, :only => [:index]
4 5  
5 6 no_design_blocks
6 7  
... ... @@ -39,4 +40,11 @@ class ThemesController &lt; ApplicationController
39 40 redirect_to :action => 'index'
40 41 end
41 42  
  43 + private
  44 +
  45 + def check_user_can_edit_appearance
  46 + disable_appearance_enabled = !user.is_admin?(environment) && environment.enabled?('disable_appearance')
  47 + redirect_to request.referer || "/" if disable_appearance_enabled
  48 + end
  49 +
42 50 end
... ...
app/models/environment.rb
... ... @@ -123,6 +123,7 @@ class Environment &lt; ActiveRecord::Base
123 123 'disable_asset_events' => _('Disable search for events'),
124 124 'disable_categories' => _('Disable categories'),
125 125 'disable_header_and_footer' => _('Disable header/footer editing by users'),
  126 + 'disable_appearance' => _('Disable appearance editing by users'),
126 127 'disable_gender_icon' => _('Disable gender icon'),
127 128 'disable_categories_menu' => _('Disable the categories menu'),
128 129 'disable_select_city_for_contact' => _('Disable state/city select for contact form'),
... ... @@ -158,7 +159,7 @@ class Environment &lt; ActiveRecord::Base
158 159 'allow_change_of_redirection_after_login' => _('Allow users to set the page to redirect after login'),
159 160 'display_my_communities_on_user_menu' => _('Display on menu the list of communities the user can manage'),
160 161 'display_my_enterprises_on_user_menu' => _('Display on menu the list of enterprises the user can manage'),
161   - 'restrict_to_members' => _('Show content only to members')
  162 + 'restrict_to_members' => _('Show content only to members'),
162 163 }
163 164 end
164 165  
... ...
app/views/profile_editor/index.html.erb
... ... @@ -22,7 +22,7 @@
22 22  
23 23 <%= control_panel_button(_('Edit sideboxes'), 'blocks', :controller => 'profile_design', :action => 'index') %>
24 24  
25   - <%= control_panel_button(_('Edit Appearance'), 'design-editor', :controller => 'profile_themes', :action => 'index') %>
  25 + <%= control_panel_button(_('Edit Appearance'), 'design-editor', :controller => 'profile_themes', :action => 'index') if @show_appearance_option %>
26 26  
27 27 <%= control_panel_button(_('Edit Header and Footer'), 'header-and-footer', :controller => 'profile_editor', :action => 'header_footer') if user.is_admin?(environment) || (!profile.enterprise? && !environment.enabled?('disable_header_and_footer')) %>
28 28  
... ...
test/functional/profile_themes_controller_test.rb
... ... @@ -116,7 +116,7 @@ class ProfileThemesControllerTest &lt; ActionController::TestCase
116 116  
117 117 should 'create a new theme' do
118 118 post :new, :profile => 'testinguser', :name => 'My theme'
119   -
  119 +
120 120 ok('theme should be created') do
121 121 profile.themes.first.id == 'my-theme'
122 122 end
... ... @@ -197,7 +197,7 @@ class ProfileThemesControllerTest &lt; ActionController::TestCase
197 197 should 'display "add image" button' do
198 198 theme = Theme.create('mytheme', :owner => profile)
199 199 get :edit, :profile => 'testinguser', :id => 'mytheme'
200   -
  200 +
201 201 assert_tag :tag => 'a', :attributes => { :href => '/myprofile/testinguser/profile_themes/add_image/mytheme' }
202 202 end
203 203  
... ... @@ -329,4 +329,29 @@ class ProfileThemesControllerTest &lt; ActionController::TestCase
329 329 assert_equal [t2, t1], assigns(:themes)
330 330 end
331 331  
  332 + should 'user cant edit appearance if environment dont permit' do
  333 + environment = Environment.default
  334 + environment.settings[:disable_appearance_enabled] = true
  335 + environment.save!
  336 +
  337 + user = create_user('user').person
  338 + login_as('user')
  339 +
  340 + post :index, :profile => user.identifier
  341 + assert_response :redirect
  342 + end
  343 +
  344 + should 'admin can edit appearance if environment dont permit' do
  345 + user = create_user('user').person
  346 +
  347 + environment = Environment.default
  348 + environment.add_admin(user)
  349 + environment.settings[:disable_appearance_enabled] = true
  350 + environment.save!
  351 +
  352 + login_as('user')
  353 +
  354 + post :index, :profile => user.identifier
  355 + assert_response :success
  356 + end
332 357 end
... ...