Commit 39d689dc5e701720cdd95830c6e52360aea0a753
1 parent
a7e0c611
Exists in
checkbox_to_user_can_edit_page
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>
Showing
5 changed files
with
39 additions
and
4 deletions
Show diff stats
app/controllers/my_profile/profile_editor_controller.rb
@@ -10,6 +10,7 @@ class ProfileEditorController < MyProfileController | @@ -10,6 +10,7 @@ class ProfileEditorController < MyProfileController | ||
10 | 10 | ||
11 | def index | 11 | def index |
12 | @pending_tasks = Task.to(profile).pending.without_spam.select{|i| user.has_permission?(i.permission, profile)} | 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 | end | 14 | end |
14 | 15 | ||
15 | helper :profile | 16 | helper :profile |
app/controllers/themes_controller.rb
1 | class ThemesController < ApplicationController | 1 | class ThemesController < ApplicationController |
2 | 2 | ||
3 | before_filter :login_required | 3 | before_filter :login_required |
4 | + before_filter :check_user_can_edit_appearance, :only => [:index] | ||
4 | 5 | ||
5 | no_design_blocks | 6 | no_design_blocks |
6 | 7 | ||
@@ -39,4 +40,11 @@ class ThemesController < ApplicationController | @@ -39,4 +40,11 @@ class ThemesController < ApplicationController | ||
39 | redirect_to :action => 'index' | 40 | redirect_to :action => 'index' |
40 | end | 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 | end | 50 | end |
app/models/environment.rb
@@ -123,6 +123,7 @@ class Environment < ActiveRecord::Base | @@ -123,6 +123,7 @@ class Environment < ActiveRecord::Base | ||
123 | 'disable_asset_events' => _('Disable search for events'), | 123 | 'disable_asset_events' => _('Disable search for events'), |
124 | 'disable_categories' => _('Disable categories'), | 124 | 'disable_categories' => _('Disable categories'), |
125 | 'disable_header_and_footer' => _('Disable header/footer editing by users'), | 125 | 'disable_header_and_footer' => _('Disable header/footer editing by users'), |
126 | + 'disable_appearance' => _('Disable appearance editing by users'), | ||
126 | 'disable_gender_icon' => _('Disable gender icon'), | 127 | 'disable_gender_icon' => _('Disable gender icon'), |
127 | 'disable_categories_menu' => _('Disable the categories menu'), | 128 | 'disable_categories_menu' => _('Disable the categories menu'), |
128 | 'disable_select_city_for_contact' => _('Disable state/city select for contact form'), | 129 | 'disable_select_city_for_contact' => _('Disable state/city select for contact form'), |
@@ -158,7 +159,7 @@ class Environment < ActiveRecord::Base | @@ -158,7 +159,7 @@ class Environment < ActiveRecord::Base | ||
158 | 'allow_change_of_redirection_after_login' => _('Allow users to set the page to redirect after login'), | 159 | 'allow_change_of_redirection_after_login' => _('Allow users to set the page to redirect after login'), |
159 | 'display_my_communities_on_user_menu' => _('Display on menu the list of communities the user can manage'), | 160 | 'display_my_communities_on_user_menu' => _('Display on menu the list of communities the user can manage'), |
160 | 'display_my_enterprises_on_user_menu' => _('Display on menu the list of enterprises the user can manage'), | 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 | end | 164 | end |
164 | 165 |
app/views/profile_editor/index.html.erb
@@ -22,7 +22,7 @@ | @@ -22,7 +22,7 @@ | ||
22 | 22 | ||
23 | <%= control_panel_button(_('Edit sideboxes'), 'blocks', :controller => 'profile_design', :action => 'index') %> | 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 | <%= 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')) %> | 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 < ActionController::TestCase | @@ -116,7 +116,7 @@ class ProfileThemesControllerTest < ActionController::TestCase | ||
116 | 116 | ||
117 | should 'create a new theme' do | 117 | should 'create a new theme' do |
118 | post :new, :profile => 'testinguser', :name => 'My theme' | 118 | post :new, :profile => 'testinguser', :name => 'My theme' |
119 | - | 119 | + |
120 | ok('theme should be created') do | 120 | ok('theme should be created') do |
121 | profile.themes.first.id == 'my-theme' | 121 | profile.themes.first.id == 'my-theme' |
122 | end | 122 | end |
@@ -197,7 +197,7 @@ class ProfileThemesControllerTest < ActionController::TestCase | @@ -197,7 +197,7 @@ class ProfileThemesControllerTest < ActionController::TestCase | ||
197 | should 'display "add image" button' do | 197 | should 'display "add image" button' do |
198 | theme = Theme.create('mytheme', :owner => profile) | 198 | theme = Theme.create('mytheme', :owner => profile) |
199 | get :edit, :profile => 'testinguser', :id => 'mytheme' | 199 | get :edit, :profile => 'testinguser', :id => 'mytheme' |
200 | - | 200 | + |
201 | assert_tag :tag => 'a', :attributes => { :href => '/myprofile/testinguser/profile_themes/add_image/mytheme' } | 201 | assert_tag :tag => 'a', :attributes => { :href => '/myprofile/testinguser/profile_themes/add_image/mytheme' } |
202 | end | 202 | end |
203 | 203 | ||
@@ -329,4 +329,29 @@ class ProfileThemesControllerTest < ActionController::TestCase | @@ -329,4 +329,29 @@ class ProfileThemesControllerTest < ActionController::TestCase | ||
329 | assert_equal [t2, t1], assigns(:themes) | 329 | assert_equal [t2, t1], assigns(:themes) |
330 | end | 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 | end | 357 | end |