Commit 14f976dcea756b5b79b6976dfa379949ee61e2fb
1 parent
274fe395
Exists in
master
and in
22 other branches
ActionItem14: merging work done offline at João Pessoa. Keeping individual log m…
…essages below to reach this commit from their respective action items. r716@cabula: terceiro | 2007-10-15 16:42:10 +0000 creting local branch for trunk r717@cabula: terceiro | 2007-10-15 20:03:03 +0000 ActionItem14: working on the user interface for enterprise registration r724@cabula: terceiro | 2007-10-16 21:44:04 +0000 ActionItem85: adding script for downloading plugins when using svk r725@cabula: terceiro | 2007-10-16 22:58:38 +0000 ActionItem14: implementing helper method r726@cabula: terceiro | 2007-10-16 23:34:59 +0000 ActionItem14: making test more complete r727@cabula: terceiro | 2007-10-17 12:36:20 +0000 ActionItem85: commenting out unexisting javascript r728@cabula: terceiro | 2007-10-17 15:58:58 +0000 ActionItem14: implementing enterprise registration controller. Still missing some TODO items. git-svn-id: https://svn.colivre.coop.br/svn/noosfero/trunk@716 3f533792-8f58-4932-b0fe-aaf55b0a4547
Showing
14 changed files
with
304 additions
and
6 deletions
Show diff stats
app/controllers/public/enterprise_registration_controller.rb
0 → 100644
... | ... | @@ -0,0 +1,52 @@ |
1 | +class EnterpriseRegistrationController < ApplicationController | |
2 | + | |
3 | + # Just go to the first step. | |
4 | + # | |
5 | + # FIXME: shouldn't this action present some sort of welcome message and point | |
6 | + # to the first step explicitly? | |
7 | + def index | |
8 | + @create_enterprise = CreateEnterprise.new(params[:create_enterprise]) | |
9 | + @create_enterprise.requestor = current_user.person | |
10 | + the_action = | |
11 | + if request.post? | |
12 | + if @create_enterprise.valid_before_selecting_target? | |
13 | + if @create_enterprise.valid? | |
14 | + :confirmation | |
15 | + else | |
16 | + :select_validator | |
17 | + end | |
18 | + end | |
19 | + end | |
20 | + | |
21 | + # default to basic_information | |
22 | + the_action ||= :basic_information | |
23 | + | |
24 | + send(the_action) | |
25 | + render :action => the_action | |
26 | + end | |
27 | + | |
28 | + protected | |
29 | + | |
30 | + # Fill in the form and select your Region. | |
31 | + # | |
32 | + # Posts back. | |
33 | + def basic_information | |
34 | + @regions = environment.regions.map {|item| [item.name, item.id]} | |
35 | + end | |
36 | + | |
37 | + # present information about validator organizations, and the user one to | |
38 | + # validate her brand new enterprise. | |
39 | + # | |
40 | + # Posts back. | |
41 | + def select_validator | |
42 | + @validators = @create_enterprise.region.validators | |
43 | + end | |
44 | + | |
45 | + # Actually records the enterprise registration request and presents a | |
46 | + # confirmation message saying to the user that the enterprise register | |
47 | + # request was done. | |
48 | + def confirmation | |
49 | + @create_enterprise.save! | |
50 | + end | |
51 | + | |
52 | +end | ... | ... |
app/models/create_enterprise.rb
... | ... | @@ -34,6 +34,14 @@ class CreateEnterprise < Task |
34 | 34 | end |
35 | 35 | end |
36 | 36 | |
37 | + def valid_before_selecting_target? | |
38 | + if valid? | |
39 | + true | |
40 | + else | |
41 | + self.errors.size == 1 and self.errors[:target_id] | |
42 | + end | |
43 | + end | |
44 | + | |
37 | 45 | # gets the associated region for the enterprise creation |
38 | 46 | def region(reload = false) |
39 | 47 | if self.region_id | ... | ... |
... | ... | @@ -0,0 +1,11 @@ |
1 | +<%= hidden_field 'create_enterprise', 'identifier' %> | |
2 | +<%= hidden_field 'create_enterprise', 'name' %> | |
3 | +<%= hidden_field 'create_enterprise', 'address' %> | |
4 | +<%= hidden_field 'create_enterprise', 'contact_phone' %> | |
5 | +<%= hidden_field 'create_enterprise', 'contact_person' %> | |
6 | +<%= hidden_field 'create_enterprise', 'acronym' %> | |
7 | +<%= hidden_field 'create_enterprise', 'foundation_year' %> | |
8 | +<%= hidden_field 'create_enterprise', 'legal_form' %> | |
9 | +<%= hidden_field 'create_enterprise', 'economic_activity' %> | |
10 | +<%= hidden_field 'create_enterprise', 'management_information' %> | |
11 | +<%= hidden_field 'create_enterprise', 'region_id' %> | ... | ... |
app/views/enterprise_registration/basic_information.rhtml
0 → 100644
... | ... | @@ -0,0 +1,36 @@ |
1 | +<%= error_messages_for 'create_enterprise' %> | |
2 | + | |
3 | +<h2><%= _('Register enterprise') %></h2> | |
4 | + | |
5 | +<h3> <%= _('How to proceed') %> </h3> | |
6 | +<p> <%= _('Fill the form and hit the Register button then the enterprise will be submitted for evaluation at the validation entitiy of your choice (within your state), when the enterprise is aproved you will be able to activate its profile') %> </p> | |
7 | + | |
8 | +<% labelled_form_for(:create_enterprise, @create_enterprise) do |f| %> | |
9 | + <%= f.text_field 'identifier', 'size' => 20 %> | |
10 | + | |
11 | + <%= f.text_field 'name', 'size' => 20 %> | |
12 | + | |
13 | + <%= f.text_field 'address', 'size' => 50 %> | |
14 | + | |
15 | + <%= f.text_field 'contact_phone', 'size' => 20 %> | |
16 | + | |
17 | + <%= f.text_field 'contact_person', 'size' => 20 %> | |
18 | + | |
19 | + <%= f.text_field 'acronym', 'size' => 20 %> | |
20 | + | |
21 | + <%= f.text_field 'foundation_year', 'size' => 20 %> | |
22 | + | |
23 | + <%= f.text_field 'legal_form', 'size' => 20 %> | |
24 | + | |
25 | + <%= f.text_field 'economic_activity', 'size' => 20 %> | |
26 | + | |
27 | + <%= labelled_form_field(_('Management information'), text_editor('create_enterprise', 'management_information')) %> | |
28 | + | |
29 | + <%= f.select('region_id', @regions) %> | |
30 | + | |
31 | + <div> | |
32 | + <%= submit_tag _('Register') %> | |
33 | + <%= link_to _('Cancel'), :action => 'index' %> | |
34 | + </div> | |
35 | + | |
36 | +<% end %> | ... | ... |
... | ... | @@ -0,0 +1,9 @@ |
1 | +<h2><%= _('Enterprise Registration completed') %></h2> | |
2 | + | |
3 | +<p> | |
4 | +<%= _("Your enterprise registration request was successfully registered. The validator organization you choose (%s) should get in touch with to start the validation process. As soon as the validators approve (or reject) your request, you will be notified by e-mail.") % @create_enterprise.target.name %> | |
5 | +</p> | |
6 | + | |
7 | +<p> | |
8 | +<%= link_to _('You can continue to browse this environment.'), :controller => 'home' %> | |
9 | +</p> | ... | ... |
app/views/enterprise_registration/select_validator.rhtml
0 → 100644
... | ... | @@ -0,0 +1,18 @@ |
1 | +<h2><%= _('Enterprise Registration: Select a validator organization') %></h2> | |
2 | + | |
3 | +<p> | |
4 | +<%= _('Select one organization to validate your enterprise registration request. Check the provided information about their validation methodoly and criteria.') %> | |
5 | +</p> | |
6 | + | |
7 | +<% form_tag do %> | |
8 | + <%= render :partial => 'hidden_fields' %> | |
9 | + | |
10 | + <% for validator in @validators %> | |
11 | + <div> | |
12 | + <%= radio_button_tag('create_enterprise[target_id]', validator.id) %> | |
13 | + <%= validator.name %> | |
14 | + </div> | |
15 | + <% end %> | |
16 | + | |
17 | + <%= submit_tag _('Confirm') %> | |
18 | +<% end %> | ... | ... |
app/views/layouts/application.rhtml
... | ... | @@ -3,7 +3,7 @@ |
3 | 3 | <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> |
4 | 4 | |
5 | 5 | <%= javascript_include_tag 'prototype' %> |
6 | - <%= javascript_include_tag 'sweetTitles' %> | |
6 | + <%# javascript_include_tag 'sweetTitles' %> | |
7 | 7 | <%= javascript_include_tag 'tiny_mce/tiny_mce.js' %> |
8 | 8 | <%= javascript_include_tag 'scriptaculous' %> |
9 | 9 | <%= javascript_include_tag 'dragdrop' %> | ... | ... |
config/routes.rb
... | ... | @@ -22,7 +22,9 @@ ActionController::Routing::Routes.draw do |map| |
22 | 22 | map.connect 'account/new_password/:code', :controller => 'account', :action => 'new_password' |
23 | 23 | |
24 | 24 | map.connect 'account/:action', :controller => 'account' |
25 | - | |
25 | + | |
26 | + # enterprise registration | |
27 | + map.connect 'enterprise_registration/:action', :controller => 'enterprise_registration' | |
26 | 28 | |
27 | 29 | ###################################################### |
28 | 30 | ## Controllers that are profile-specific (for profile admins ) | ... | ... |
public/stylesheets/common.css
... | ... | @@ -34,3 +34,29 @@ padding-left: 60px !important ; |
34 | 34 | color: #dfdfdf !important ; |
35 | 35 | } |
36 | 36 | |
37 | +div.fieldWithErrors { | |
38 | + display: inline; | |
39 | + background: yellow; | |
40 | +} | |
41 | + | |
42 | +div.fieldWithErrors input { | |
43 | + border: 1px solid red; | |
44 | + background: #fee; | |
45 | +} | |
46 | + | |
47 | +div#errorExplanation { | |
48 | + border: 2px solid #933; | |
49 | + background: #fee; | |
50 | + padding: 5px; | |
51 | +} | |
52 | + | |
53 | +div#errorExplanation h2 { | |
54 | + margin-top: -5px; | |
55 | + margin-left: -5px; | |
56 | + margin-right: -5px; | |
57 | + | |
58 | + padding: 3px; | |
59 | + background: #933; | |
60 | + color: white; | |
61 | + text-align: center; | |
62 | +} | ... | ... |
script/anhetegua
... | ... | @@ -9,16 +9,34 @@ def new_category(parent, name, color = nil) |
9 | 9 | category |
10 | 10 | end |
11 | 11 | |
12 | +def new_region(parent, name, color = nil) | |
13 | + region = Environment.default.regions.build(:name => name, :display_color => color, :parent_id => (parent ? parent.id: nil)) | |
14 | + region.save! | |
15 | + region | |
16 | +end | |
17 | + | |
12 | 18 | tematicas = new_category(nil, 'Temáticas', 1) |
13 | 19 | new_category(tematicas, 'Finanças Solidárias') |
14 | 20 | new_category(tematicas, 'Marco Legal') |
15 | 21 | new_category(tematicas, 'Software Livre') |
16 | 22 | |
17 | -territorios = new_category(nil, 'Territórios', 2) | |
18 | -new_category(territorios, 'Bahia') | |
19 | -new_category(territorios, 'Distrito Federal') | |
20 | -new_category(territorios, 'Rio Grande do Sul') | |
23 | +territorios = new_region(nil, 'Territórios', 2) | |
24 | +ba = new_region(territorios, 'Bahia') | |
25 | +df = new_region(territorios, 'Distrito Federal') | |
26 | +rs = new_region(territorios, 'Rio Grande do Sul') | |
21 | 27 | |
22 | 28 | cadeias = new_category(nil, 'Cadeias', 3) |
23 | 29 | new_category(cadeias, 'Algodão') |
24 | 30 | new_category(cadeias, 'Tecnologia de Informação') |
31 | + | |
32 | + | |
33 | +# validators | |
34 | +ba.validators << Organization.create!(:name => "Colivre", :identifier => 'colivre') | |
35 | +ba.validators << Organization.create!(:name => "Forum Baiano de Economia Solidaraia", :identifier => 'ecosolbahia') | |
36 | + | |
37 | +df.validators << Organization.create!(:name => 'Caritas', :identifier => 'caritas') | |
38 | +df.validators << Organization.create!(:name => 'Forum Brasileiro de Economia Solidaria', :identifier => 'fbes') | |
39 | + | |
40 | +rs.validators << Organization.create!(:name => 'Associacao Software Livre.Org', :identifier => 'asl') | |
41 | +rs.validators << Organization.create!(:name => 'Forum Gaucho de Economia Solidaria', :identifier => 'ecosolrs') | |
42 | + | ... | ... |
test/functional/enterprise_registration_controller_test.rb
0 → 100644
... | ... | @@ -0,0 +1,82 @@ |
1 | +require File.dirname(__FILE__) + '/../test_helper' | |
2 | +require 'enterprise_registration_controller' | |
3 | + | |
4 | +# Re-raise errors caught by the controller. | |
5 | +class EnterpriseRegistrationController; def rescue_action(e) raise e end; end | |
6 | + | |
7 | +class EnterpriseRegistrationControllerTest < Test::Unit::TestCase | |
8 | + | |
9 | + fixtures :users | |
10 | + | |
11 | + def setup | |
12 | + @controller = EnterpriseRegistrationController.new | |
13 | + @request = ActionController::TestRequest.new | |
14 | + @response = ActionController::TestResponse.new | |
15 | + login_as 'ze' | |
16 | + end | |
17 | + | |
18 | + should 'go to the first step on index' do | |
19 | + get :index | |
20 | + assert_response :success | |
21 | + assert_template 'basic_information' | |
22 | + end | |
23 | + | |
24 | + should 'prompt for basic information' do | |
25 | + get :index | |
26 | + %w[ name identifier address contact_phone contact_person | |
27 | + acronym foundation_year legal_form economic_activity ].each do |item| | |
28 | + assert_tag :tag => 'input', :attributes => { :name => "create_enterprise[#{item}]" } | |
29 | + end | |
30 | + assert_tag :tag => 'textarea', :attributes => { :name => "create_enterprise[management_information]"} | |
31 | + assert_tag :tag => 'select', :attributes => { :name => "create_enterprise[region_id]"} | |
32 | + end | |
33 | + | |
34 | + should 'get back to entering basic information if data is invalid' do | |
35 | + post :index, :create_enterprise => {} | |
36 | + assert_response :success | |
37 | + assert_template 'basic_information' | |
38 | + end | |
39 | + | |
40 | + should 'prompt for selecting validator' do | |
41 | + data = { 'name' => 'My new enterprise', 'identifier' => 'mynew' } | |
42 | + | |
43 | + create_enterprise = CreateEnterprise.new | |
44 | + CreateEnterprise.expects(:new).with(data).returns(create_enterprise) | |
45 | + | |
46 | + validator1 = mock() | |
47 | + validator1.expects(:id).returns(1) | |
48 | + validator1.expects(:name).returns("validator1") | |
49 | + validator2 = mock() | |
50 | + validator2.expects(:id).returns(2) | |
51 | + validator2.expects(:name).returns("validator2") | |
52 | + region = mock() | |
53 | + region.expects(:validators).returns([validator1, validator2]).at_least_once | |
54 | + create_enterprise.expects(:region).returns(region) | |
55 | + | |
56 | + # all data but validator selected | |
57 | + create_enterprise.expects(:valid_before_selecting_target?).returns(true) | |
58 | + create_enterprise.expects(:valid?).returns(false) | |
59 | + | |
60 | + post :index, :create_enterprise => data | |
61 | + assert_template 'select_validator' | |
62 | + end | |
63 | + | |
64 | + should 'provide confirmation at the end of the process' do | |
65 | + data = { 'name' => 'My new enterprise', 'identifier' => 'mynew' } | |
66 | + | |
67 | + create_enterprise = CreateEnterprise.new | |
68 | + CreateEnterprise.expects(:new).with(data).returns(create_enterprise) | |
69 | + | |
70 | + # all including validator selected | |
71 | + validator = mock() | |
72 | + validator.stubs(:name).returns("lalala") | |
73 | + create_enterprise.expects(:valid_before_selecting_target?).returns(true) | |
74 | + create_enterprise.expects(:valid?).returns(true) # validator already selected | |
75 | + create_enterprise.expects(:save!) | |
76 | + create_enterprise.expects(:target).returns(validator) | |
77 | + | |
78 | + post :index, :create_enterprise => data | |
79 | + assert_template 'confirmation' | |
80 | + end | |
81 | + | |
82 | +end | ... | ... |
test/integration/routing_test.rb
... | ... | @@ -21,6 +21,10 @@ class RoutingTest < ActionController::IntegrationTest |
21 | 21 | assert_routing('/account', :controller => 'account', :action => 'index') |
22 | 22 | end |
23 | 23 | |
24 | + def test_enterprise_registration_controller | |
25 | + assert_routing('/enterprise_registration', :controller => 'enterprise_registration', :action => 'index') | |
26 | + end | |
27 | + | |
24 | 28 | def test_new_password |
25 | 29 | assert_routing('/account/new_password/90dfhga7sadgd0as6saas', :controller => 'account', :action => 'new_password', :code => '90dfhga7sadgd0as6saas') |
26 | 30 | end | ... | ... |
test/unit/create_enterprise_test.rb
... | ... | @@ -115,4 +115,29 @@ class CreateEnterpriseTest < Test::Unit::TestCase |
115 | 115 | end |
116 | 116 | end |
117 | 117 | |
118 | + should 'validate that eveything is ok but the validator (target)' do | |
119 | + Environment.destroy_all | |
120 | + environment = Environment.create!(:name => "My environment", :contact_email => 'test@localhost.localdomain', :is_default => true) | |
121 | + region = Region.create!(:name => 'My region', :environment_id => environment.id) | |
122 | + validator = Organization.create!(:name => "My organization", :identifier => 'myorg', :environment_id => environment.id) | |
123 | + region.validators << validator | |
124 | + person = User.create!(:login => 'testuser', :password => 'test', :password_confirmation => 'test', :email => 'testuser@localhost.localdomain').person | |
125 | + task = CreateEnterprise.new({ | |
126 | + :name => 'My new enterprise', | |
127 | + :identifier => 'mynewenterprise', | |
128 | + :address => 'satan street, 666', | |
129 | + :contact_phone => '1298372198', | |
130 | + :contact_person => 'random joe', | |
131 | + :legal_form => 'cooperative', | |
132 | + :economic_activity => 'free software', | |
133 | + :region_id => region.id, | |
134 | + :requestor_id => person.id, | |
135 | + }) | |
136 | + | |
137 | + assert !task.valid? && task.valid_before_selecting_target? | |
138 | + | |
139 | + task.target = validator | |
140 | + assert task.valid? | |
141 | + end | |
142 | + | |
118 | 143 | end | ... | ... |
... | ... | @@ -0,0 +1,7 @@ |
1 | +#!/bin/sh | |
2 | + | |
3 | +# this script can be used when using svk, since svk does not support automatic | |
4 | +# checkout of svn's svn:externals. Then if you use svk, change to | |
5 | +# vendor/plugins directory and run this script with `sh update-externals.sh` | |
6 | + | |
7 | +svk propget svn:externals . | awk '{ if ($1) print "if [ -e " $1 " ]; then svn update " $1 "; else svn co " $2 " " $1 "; fi"}' | sh | ... | ... |