Commit 088c792e86414670f5dad67dad6def42add07acc

Authored by Braulio Bhavamitra
2 parents 918d7d3b e22aa922

Merge branch 'case-insensitive-profile' into noosfero

app/controllers/my_profile/enterprise_validation_controller.rb
1 1 class EnterpriseValidationController < MyProfileController
2 2  
3 3 protect 'validate_enterprise', :profile
4   -
  4 +
5 5 def index
6 6 @pending_validations = profile.pending_validations
7 7 end
... ... @@ -27,7 +27,7 @@ class EnterpriseValidationController &lt; MyProfileController
27 27 post_only :reject
28 28 def reject
29 29 @pending = profile.find_pending_validation(params[:id])
30   - if @pending
  30 + if @pending
31 31 @pending.reject_explanation = params[:reject_explanation]
32 32 begin
33 33 @pending.reject
... ...
app/models/validation_info.rb
... ... @@ -2,9 +2,10 @@ class ValidationInfo &lt; ActiveRecord::Base
2 2  
3 3 attr_accessible :validation_methodology, :restrictions, :organization
4 4  
5   - validates_presence_of :validation_methodology
6   -
7 5 belongs_to :organization
8 6  
  7 + validates_presence_of :organization
  8 + validates_presence_of :validation_methodology
  9 +
9 10 xss_terminate :only => [ :validation_methodology, :restrictions ], :on => 'validation'
10 11 end
... ...
config/routes.rb
... ... @@ -56,37 +56,37 @@ Noosfero::Application.routes.draw do
56 56 match 'search(/:action(/*category_path))', :controller => 'search'
57 57  
58 58 # events
59   - match 'profile/:profile/events_by_day', :controller => 'events', :action => 'events_by_day', :profile => /#{Noosfero.identifier_format_in_url}/
60   - match 'profile/:profile/events_by_month', :controller => 'events', :action => 'events_by_month', :profile => /#{Noosfero.identifier_format_in_url}/
61   - match 'profile/:profile/events/:year/:month/:day', :controller => 'events', :action => 'events', :year => /\d*/, :month => /\d*/, :day => /\d*/, :profile => /#{Noosfero.identifier_format_in_url}/
62   - match 'profile/:profile/events/:year/:month', :controller => 'events', :action => 'events', :year => /\d*/, :month => /\d*/, :profile => /#{Noosfero.identifier_format_in_url}/
63   - match 'profile/:profile/events', :controller => 'events', :action => 'events', :profile => /#{Noosfero.identifier_format_in_url}/
  59 + match 'profile/:profile/events_by_day', :controller => 'events', :action => 'events_by_day', :profile => /#{Noosfero.identifier_format_in_url}/i
  60 + match 'profile/:profile/events_by_month', :controller => 'events', :action => 'events_by_month', :profile => /#{Noosfero.identifier_format_in_url}/i
  61 + match 'profile/:profile/events/:year/:month/:day', :controller => 'events', :action => 'events', :year => /\d*/, :month => /\d*/, :day => /\d*/, :profile => /#{Noosfero.identifier_format_in_url}/i
  62 + match 'profile/:profile/events/:year/:month', :controller => 'events', :action => 'events', :year => /\d*/, :month => /\d*/, :profile => /#{Noosfero.identifier_format_in_url}/i
  63 + match 'profile/:profile/events', :controller => 'events', :action => 'events', :profile => /#{Noosfero.identifier_format_in_url}/i
64 64  
65 65 # catalog
66   - match 'catalog/:profile', :controller => 'catalog', :action => 'index', :profile => /#{Noosfero.identifier_format_in_url}/, :as => :catalog
  66 + match 'catalog/:profile', :controller => 'catalog', :action => 'index', :profile => /#{Noosfero.identifier_format_in_url}/i, :as => :catalog
67 67  
68 68 # invite
69   - match 'profile/:profile/invite/friends', :controller => 'invite', :action => 'invite_friends', :profile => /#{Noosfero.identifier_format_in_url}/
70   - match 'profile/:profile/invite/:action', :controller => 'invite', :profile => /#{Noosfero.identifier_format_in_url}/
  69 + match 'profile/:profile/invite/friends', :controller => 'invite', :action => 'invite_friends', :profile => /#{Noosfero.identifier_format_in_url}/i
  70 + match 'profile/:profile/invite/:action', :controller => 'invite', :profile => /#{Noosfero.identifier_format_in_url}/i
71 71  
72 72 # feeds per tag
73   - match 'profile/:profile/tags/:id/feed', :controller => 'profile', :action =>'tag_feed', :id => /.+/, :profile => /#{Noosfero.identifier_format_in_url}/, :as => :tag_feed
  73 + match 'profile/:profile/tags/:id/feed', :controller => 'profile', :action =>'tag_feed', :id => /.+/, :profile => /#{Noosfero.identifier_format_in_url}/i, :as => :tag_feed
74 74  
75 75 # profile tags
76   - match 'profile/:profile/tags/:id', :controller => 'profile', :action => 'content_tagged', :id => /.+/, :profile => /#{Noosfero.identifier_format_in_url}/
77   - match 'profile/:profile/tags(/:id)', :controller => 'profile', :action => 'tags', :profile => /#{Noosfero.identifier_format_in_url}/
  76 + match 'profile/:profile/tags/:id', :controller => 'profile', :action => 'content_tagged', :id => /.+/, :profile => /#{Noosfero.identifier_format_in_url}/i
  77 + match 'profile/:profile/tags(/:id)', :controller => 'profile', :action => 'tags', :profile => /#{Noosfero.identifier_format_in_url}/i
78 78  
79 79 # profile search
80   - match 'profile/:profile/search', :controller => 'profile_search', :action => 'index', :profile => /#{Noosfero.identifier_format_in_url}/
  80 + match 'profile/:profile/search', :controller => 'profile_search', :action => 'index', :profile => /#{Noosfero.identifier_format_in_url}/i
81 81  
82 82 # comments
83   - match 'profile/:profile/comment/:action/:id', :controller => 'comment', :profile => /#{Noosfero.identifier_format_in_url}/
  83 + match 'profile/:profile/comment/:action/:id', :controller => 'comment', :profile => /#{Noosfero.identifier_format_in_url}/i
84 84  
85 85 # public profile information
86   - match 'profile/:profile(/:action(/:id))', :controller => 'profile', :action => 'index', :id => /[^\/]*/, :profile => /#{Noosfero.identifier_format_in_url}/, :as => :profile
  86 + match 'profile/:profile(/:action(/:id))', :controller => 'profile', :action => 'index', :id => /[^\/]*/, :profile => /#{Noosfero.identifier_format_in_url}/i, :as => :profile
87 87  
88 88 # contact
89   - match 'contact/:profile/:action(/:id)', :controller => 'contact', :action => 'index', :id => /.*/, :profile => /#{Noosfero.identifier_format_in_url}/
  89 + match 'contact/:profile/:action(/:id)', :controller => 'contact', :action => 'index', :id => /.*/, :profile => /#{Noosfero.identifier_format_in_url}/i
90 90  
91 91 # map balloon
92 92 match 'map_balloon/:action/:id', :controller => 'map_balloon', :id => /.*/
... ... @@ -98,8 +98,8 @@ Noosfero::Application.routes.draw do
98 98 ## Controllers that are profile-specific (for profile admins )
99 99 ######################################################
100 100 # profile customization - "My profile"
101   - match 'myprofile/:profile', :controller => 'profile_editor', :action => 'index', :profile => /#{Noosfero.identifier_format_in_url}/
102   - match 'myprofile/:profile/:controller(/:action(/:id))', :controller => Noosfero.pattern_for_controllers_in_directory('my_profile'), :profile => /#{Noosfero.identifier_format_in_url}/, :as => :myprofile
  101 + match 'myprofile/:profile', :controller => 'profile_editor', :action => 'index', :profile => /#{Noosfero.identifier_format_in_url}/i
  102 + match 'myprofile/:profile/:controller(/:action(/:id))', :controller => Noosfero.pattern_for_controllers_in_directory('my_profile'), :profile => /#{Noosfero.identifier_format_in_url}/i, :as => :myprofile
103 103  
104 104  
105 105 ######################################################
... ... @@ -127,14 +127,14 @@ Noosfero::Application.routes.draw do
127 127 # cache stuff - hack
128 128 match 'public/:action/:id', :controller => 'public'
129 129  
130   - match ':profile/*page/versions', :controller => 'content_viewer', :action => 'article_versions', :profile => /#{Noosfero.identifier_format_in_url}/, :constraints => EnvironmentDomainConstraint.new
  130 + match ':profile/*page/versions', :controller => 'content_viewer', :action => 'article_versions', :profile => /#{Noosfero.identifier_format_in_url}/i, :constraints => EnvironmentDomainConstraint.new
131 131 match '*page/versions', :controller => 'content_viewer', :action => 'article_versions'
132 132  
133   - match ':profile/*page/versions_diff', :controller => 'content_viewer', :action => 'versions_diff', :profile => /#{Noosfero.identifier_format_in_url}/, :constraints => EnvironmentDomainConstraint.new
  133 + match ':profile/*page/versions_diff', :controller => 'content_viewer', :action => 'versions_diff', :profile => /#{Noosfero.identifier_format_in_url}/i, :constraints => EnvironmentDomainConstraint.new
134 134 match '*page/versions_diff', :controller => 'content_viewer', :action => 'versions_diff'
135 135  
136 136 # match requests for profiles that don't have a custom domain
137   - match ':profile(/*page)', :controller => 'content_viewer', :action => 'view_page', :profile => /#{Noosfero.identifier_format_in_url}/, :constraints => EnvironmentDomainConstraint.new
  137 + match ':profile(/*page)', :controller => 'content_viewer', :action => 'view_page', :profile => /#{Noosfero.identifier_format_in_url}/i, :constraints => EnvironmentDomainConstraint.new
138 138  
139 139 # match requests for content in domains hosted for profiles
140 140 match '/(*page)', :controller => 'content_viewer', :action => 'view_page'
... ...
lib/needs_profile.rb
... ... @@ -21,7 +21,11 @@ module NeedsProfile
21 21 protected
22 22  
23 23 def load_profile
24   - @profile ||= environment.profiles.find_by_identifier(params[:profile])
  24 + if params[:profile]
  25 + params[:profile].downcase!
  26 + @profile ||= environment.profiles.where(identifier: params[:profile]).first
  27 + end
  28 +
25 29 if @profile
26 30 profile_hostname = @profile.hostname
27 31 if profile_hostname && profile_hostname != request.host
... ...
lib/noosfero/plugin/routes.rb
... ... @@ -19,15 +19,15 @@ Dir.glob(Rails.root.join(plugins_root, &#39;*&#39;, &#39;controllers&#39;)) do |controllers_dir|
19 19 controllers.each do |controller|
20 20 controller_name = controller.gsub("#{plugin_name}_plugin_",'')
21 21 if %w[profile myprofile].include?(folder.to_s)
22   - match "#{prefixes_by_folder[folder]}/#{plugin_name}/#{controller_name}(/:action(/:id))", :controller => controller, :profile => /#{Noosfero.identifier_format}/
  22 + match "#{prefixes_by_folder[folder]}/#{plugin_name}/#{controller_name}(/:action(/:id))", controller: controller, profile: /#{Noosfero.identifier_format_in_url}/i
23 23 else
24   - match "#{prefixes_by_folder[folder]}/#{plugin_name}/#{controller_name}(/:action(/:id))", :controller => controller
  24 + match "#{prefixes_by_folder[folder]}/#{plugin_name}/#{controller_name}(/:action(/:id))", controller: controller
25 25 end
26 26 end
27 27 end
28 28  
29   - match 'plugin/' + plugin_name + '(/:action(/:id))', :controller => plugin_name + '_plugin'
30   - match 'profile/:profile/plugin/' + plugin_name + '(/:action(/:id))', :controller => plugin_name + '_plugin_profile', :profile => /#{Noosfero.identifier_format}/
31   - match 'myprofile/:profile/plugin/' + plugin_name + '(/:action(/:id))', :controller => plugin_name + '_plugin_myprofile', :profile => /#{Noosfero.identifier_format}/
32   - match 'admin/plugin/' + plugin_name + '(/:action(/:id))', :controller => plugin_name + '_plugin_admin'
  29 + match 'plugin/' + plugin_name + '(/:action(/:id))', controller: plugin_name + '_plugin'
  30 + match 'profile/:profile/plugin/' + plugin_name + '(/:action(/:id))', controller: plugin_name + '_plugin_profile', profile: /#{Noosfero.identifier_format_in_url}/i
  31 + match 'myprofile/:profile/plugin/' + plugin_name + '(/:action(/:id))', controller: plugin_name + '_plugin_myprofile', profile: /#{Noosfero.identifier_format_in_url}/i
  32 + match 'admin/plugin/' + plugin_name + '(/:action(/:id))', controller: plugin_name + '_plugin_admin'
33 33 end
... ...
test/functional/enterprise_validation_controller_test.rb
... ... @@ -12,126 +12,109 @@ class EnterpriseValidationControllerTest &lt; ActionController::TestCase
12 12 @controller = EnterpriseValidationController.new
13 13 @request = ActionController::TestRequest.new
14 14 @response = ActionController::TestResponse.new
15   -
  15 +
16 16 login_as 'ze'
17   - @org = Organization.create!(:identifier => 'myorg', :name => "My Org")
  17 + @user = Profile['ze']
  18 + @org = Organization.create!(identifier: 'myorg', name: "My Org")
18 19 give_permission('ze', 'validate_enterprise', @org)
19   - Profile.expects(:find_by_identifier).with('myorg').returns(@org).at_least_once
20 20 end
21 21  
22 22 should 'list pending validations on index' do
23   - empty = []
24   - @org.expects(:pending_validations).returns(empty)
25   - get :index, :profile => 'myorg'
26   - assert_equal empty, assigns(:pending_validations)
  23 + get :index, profile: 'myorg'
  24 + assert_equal [], assigns(:pending_validations)
27 25 assert_template 'index'
28 26 end
29 27  
30 28 should 'display details and prompt for needed data when approving or rejecting enterprise' do
31   - validating = CreateEnterprise.new
32   - @org.expects(:find_pending_validation).with('kakakaka').returns(validating)
33   -
34   - get :details, :profile => 'myorg', :id => 'kakakaka'
35   - assert_same validating, assigns(:pending)
  29 + code = 'kakakaka'
  30 + @org.validations.create! code: code, name: 'test', identifier: 'test', requestor: @user, target: @org
  31 + get :details, profile: 'myorg', id: code
  32 + assert_equal @org.find_pending_validation(code), assigns(:pending)
36 33 end
37 34  
38 35 should 'refuse to validate unexisting request' do
39   - @org.expects(:find_pending_validation).with('kakakaka').returns(nil)
40   - get :details , :profile => 'myorg', :id => 'kakakaka'
  36 + get :details, profile: 'myorg', id: 'kakakaka'
41 37 assert_response 404
42 38 end
43 39  
44 40 should 'be able to actually validate enterprise on request' do
45   - validation = CreateEnterprise.new
46   - @org.expects(:find_pending_validation).with('kakakaka').returns(validation)
47   - validation.expects(:approve)
48   - validation.expects(:code).returns('kakakaka')
49   - post :approve, :profile => 'myorg', :id => 'kakakaka'
50   - assert_redirected_to :action => 'view_processed', :id => 'kakakaka'
  41 + code = 'kakakaka'
  42 + @org.validations.create! code: code, name: 'test2', identifier: 'test2', requestor: @user, target: @org
  43 + post :approve, profile: 'myorg', id: code
  44 + assert_redirected_to action: 'view_processed', id: code
51 45 end
52 46  
53 47 should 'be able to reject an enterprise' do
54   - validation = CreateEnterprise.new
55   - @org.expects(:find_pending_validation).with('kakakaka').returns(validation)
56   - validation.expects(:reject)
57   - validation.expects(:code).returns('kakakaka')
58   - post :reject, :profile => 'myorg', :id => 'kakakaka', :reject_explanation => 'this is not a solidarity economy enterprise'
59   - assert_redirected_to :action => 'view_processed', :id => 'kakakaka'
  48 + code = 'kakakaka'
  49 + @org.validations.create! code: code, name: 'test2', identifier: 'test2', requestor: @user, target: @org
  50 + post :reject, profile: 'myorg', id: code, reject_explanation: 'this is not a solidarity economy enterprise'
  51 + assert_redirected_to action: 'view_processed', id: code
60 52 end
61 53  
62 54 should 'require the user to fill in the explanation for an rejection' do
63   - validation = CreateEnterprise.new
64   - validation.stubs(:environment).returns(Environment.default)
65   - @org.expects(:find_pending_validation).with('kakakaka').returns(validation)
66   -
67   - # FIXME: this is not working, but should. Anyway the assert_response and
68   - # assert_template below in some test some things we need. But the
69   - # expectation below must be put to work.
70   - #
71   - #validation.expects(:reject).raises(ActiveRecord::RecordInvalid)
  55 + code = 'kakakaka'
  56 + @org.validations.create! code: code, name: 'test2', identifier: 'test2', requestor: @user, target: @org
72 57  
73   - post :reject, :profile => 'myorg', :id => 'kakakaka'
  58 + post :reject, profile: 'myorg', id: code
74 59 assert_response :success
75 60 assert_template 'details'
76 61 end
77 62  
78 63 should 'list validations already processed' do
79   - processed_validations = [CreateEnterprise.new]
80   - @org.expects(:processed_validations).returns(processed_validations)
81   -
82   - get :list_processed, :profile => 'myorg'
  64 + v = @org.validations.create! code: 'kakakaka', name: 'test2', identifier: 'test2', requestor: @user, target: @org
  65 + v.perform
83 66  
84   - assert_equal processed_validations, assigns(:processed_validations)
  67 + get :list_processed, profile: 'myorg'
  68 +
  69 + assert_equal @org.processed_validations, assigns(:processed_validations)
85 70  
86 71 assert_response :success
87 72 assert_template 'list_processed'
88 73 end
89   -
  74 +
90 75 should 'be able to display a validation that was already processed' do
91   - validation = CreateEnterprise.new
92   - @org.expects(:find_processed_validation).with('kakakaka').returns(validation)
93   - get :view_processed, :profile => 'myorg', :id => 'kakakaka'
94   - assert_same validation, assigns(:processed)
  76 + code = 'kakakaka'
  77 + v = @org.validations.create! code: code, name: 'test2', identifier: 'test2', requestor: @user, target: @org
  78 + v.perform
  79 +
  80 + get :view_processed, profile: 'myorg', id: code
  81 + assert_same @org.processed_validations.first, assigns(:processed)
95 82 end
96 83  
97 84 should 'display a form for editing the validation info' do
98   - info = ValidationInfo.new(:validation_methodology => 'none')
99   - @org.expects(:validation_info).returns(info)
100   - get :edit_validation_info, :profile => 'myorg'
  85 + info = @org.validation_info = ValidationInfo.create! validation_methodology: 'none', organization: @org
  86 + get :edit_validation_info, profile: 'myorg'
101 87 assert_response :success
102 88 assert_equal info, assigns(:info)
103 89 end
104 90  
105 91 should 'save an alteration of the validation info' do
106   - info = ValidationInfo.new(:validation_methodology => 'none')
107   - @org.expects(:validation_info).returns(info)
108   - post :edit_validation_info, :profile => 'myorg', :info => {:validation_methodology => 'new methodology'}
109   -
  92 + info = @org.validation_info = ValidationInfo.create! validation_methodology: 'none', organization: @org
  93 + post :edit_validation_info, profile: 'myorg', info: {validation_methodology: 'new methodology'}
  94 +
110 95 assert_response :redirect
111   - assert_redirected_to :action => 'index'
112   - assert_equal info, assigns(:info)
  96 + assert_redirected_to action: 'index'
  97 + info.reload
  98 + assert_equal info.reload, assigns(:info)
113 99 end
114 100  
115 101 should 'not save an empaty validation mthodology' do
116   - info = ValidationInfo.new(:validation_methodology => 'none')
117   - @org.expects(:validation_info).returns(info)
118   - post :edit_validation_info, :profile => 'myorg', :info => {:validation_methodology => ''}
119   -
  102 + info = @org.validation_info = ValidationInfo.create! validation_methodology: 'none', organization: @org
  103 + post :edit_validation_info, profile: 'myorg', info: {validation_methodology: ''}
  104 +
120 105 assert_response :success
121 106 assert_equal info, assigns(:info)
122 107 end
123 108  
124 109 should 'filter html from methodology of the validation info' do
125   - info = ValidationInfo.new(:validation_methodology => 'none')
126   - @org.expects(:validation_info).returns(info)
127   - post :edit_validation_info, :profile => 'myorg', :info => {:validation_methodology => 'new <b>methodology</b>'}
  110 + @org.validation_info = ValidationInfo.create! validation_methodology: 'none', organization: @org
  111 + post :edit_validation_info, profile: 'myorg', info: {validation_methodology: 'new <b>methodology</b>'}
128 112 assert_sanitized assigns(:info).validation_methodology
129 113 end
130 114  
131 115 should 'filter html from restrictions of the validation info' do
132   - info = ValidationInfo.new(:validation_methodology => 'none')
133   - @org.expects(:validation_info).returns(info)
134   - post :edit_validation_info, :profile => 'myorg', :info => {:restrictions => 'new <b>methodology</b>'}
  116 + @org.validation_info = ValidationInfo.create! validation_methodology: 'none', organization: @org
  117 + post :edit_validation_info, profile: 'myorg', info: {restrictions: 'new <b>methodology</b>'}
135 118 assert_sanitized assigns(:info).restrictions
136 119 end
137 120  
... ...
test/integration/routing_test.rb
... ... @@ -27,6 +27,10 @@ class RoutingTest &lt; ActionController::IntegrationTest
27 27 assert_routing('/account/new_password/90dfhga7sadgd0as6saas', :controller => 'account', :action => 'new_password', :code => '90dfhga7sadgd0as6saas')
28 28 end
29 29  
  30 + should 'ignore case for profiles' do
  31 + assert_routing '/myprofile/ZE/cms', profile: 'ZE', controller: 'cms', action: 'index'
  32 + end
  33 +
30 34 def test_cms
31 35 assert_routing('/myprofile/ze/cms', :profile => 'ze', :controller => 'cms', :action => 'index')
32 36 end
... ...