Commit 498e40b7b47bcafc8988cc6943193c5a6e91528b

Authored by Joenio Costa
1 parent 5b9b6c8f

HTML forms with id #ajax-form will be submited by ajax automatically

- fixing some bugfixes
 - all controllers under admin/ should require login
 - plugins admin interface should require at least one permission

(ActionItem2056)
app/controllers/admin/admin_panel_controller.rb
1 1 class AdminPanelController < AdminController
2 2  
3   - before_filter :login_required
4   -
5 3 protect 'view_environment_admin_panel', :environment
6 4  
7 5 def boxes_holder
... ...
app/controllers/admin/plugins_controller.rb
1 1 class PluginsController < AdminController
  2 + protect 'edit_environment_features', :environment
2 3  
3 4 def index
4 5 @active_plugins = Noosfero::Plugin.all.map {|plugin_name| plugin_name.constantize }.compact
... ...
app/controllers/admin_controller.rb
1 1 class AdminController < ApplicationController
2 2 require_ssl
  3 + before_filter :login_required
3 4 end
... ...
features/send_email_to_environment_members.feature
... ... @@ -5,7 +5,7 @@ Feature: send emails to environment members users
5 5 Scenario: Cant access if not logged in
6 6 Given I am not logged in
7 7 When I go to /admin/users/send_mail
8   - Then I should see "Access denied"
  8 + Then I should be on login page
9 9  
10 10 Scenario: Cant access as normal user
11 11 Given the following user
... ...
public/javascripts/application.js
... ... @@ -677,3 +677,18 @@ function original_image_dimensions(src) {
677 677 img.src = src;
678 678 return { 'width' : img.width, 'height' : img.height };
679 679 }
  680 +
  681 +jQuery(function() {
  682 + jQuery("#ajax-form").before("<div id='ajax-form-loading-area' style='display:block;width:16px;height:16px;'></div>");
  683 + jQuery("#ajax-form").before("<div id='ajax-form-message-area'></div>");
  684 + jQuery("#ajax-form").ajaxForm({
  685 + beforeSubmit: function(a,f,o) {
  686 + jQuery('#ajax-form-message-area').html('');
  687 + o.loading = small_loading('ajax-form-loading-area');
  688 + },
  689 + success: function() {
  690 + loading_done('ajax-form-loading-area');
  691 + },
  692 + target: "#ajax-form-message-area"
  693 + })
  694 +});
... ...
test/functional/admin_controller_test.rb
... ... @@ -25,6 +25,7 @@ class AdminControllerTest &lt; Test::Unit::TestCase
25 25 end
26 26  
27 27 should 'detect ssl' do
  28 + login_as 'ze'
28 29 @request.expects(:ssl?).returns(true).at_least_once
29 30 get :index
30 31 assert_response :success
... ...
test/functional/cms_controller_test.rb
... ... @@ -16,6 +16,7 @@ class CmsControllerTest &lt; Test::Unit::TestCase
16 16  
17 17 @profile = create_user_with_permission('testinguser', 'post_content')
18 18 login_as :testinguser
  19 + @controller.stubs(:user).returns(@profile)
19 20 end
20 21  
21 22 attr_reader :profile
... ... @@ -614,7 +615,7 @@ class CmsControllerTest &lt; Test::Unit::TestCase
614 615 end
615 616  
616 617 should 'not make enterprise homepage available to person' do
617   - @controller.stubs(:profile).returns(create_user('test_user').person)
  618 + @controller.stubs(:profile).returns(profile)
618 619 assert_not_includes @controller.available_article_types, EnterpriseHomepage
619 620 end
620 621  
... ... @@ -1278,6 +1279,7 @@ class CmsControllerTest &lt; Test::Unit::TestCase
1278 1279 c = Community.create!(:name => 'test_comm', :identifier => 'test_comm')
1279 1280 u = create_user_with_permission('test_user', 'publish_content', c)
1280 1281 login_as :test_user
  1282 + @controller.stubs(:user).returns(u)
1281 1283  
1282 1284 get :new, :profile => c.identifier, :type => 'TinyMceArticle'
1283 1285 assert_response :success
... ... @@ -1311,6 +1313,7 @@ class CmsControllerTest &lt; Test::Unit::TestCase
1311 1313 u = create_user_with_permission('test_user', 'publish_content', c)
1312 1314 a = c.articles.create!(:name => 'test_article', :last_changed_by => u)
1313 1315 login_as :test_user
  1316 + @controller.stubs(:user).returns(u)
1314 1317  
1315 1318 get :edit, :profile => c.identifier, :id => a.id
1316 1319  
... ...
test/functional/users_controller_test.rb
... ... @@ -15,6 +15,8 @@ class UsersControllerTest &lt; Test::Unit::TestCase
15 15 end
16 16  
17 17 should 'not access without right permission' do
  18 + create_user('guest')
  19 + login_as 'guest'
18 20 get :index
19 21 assert_response 403 # forbidden
20 22 end
... ...