Commit 92a678148933c8af3f85821e7fbb429e07c497c4

Authored by MoisesMachado
1 parent 0c20ed40

ActionItem439: made infraestrucure to the activation of enterprises


git-svn-id: https://svn.colivre.coop.br/svn/noosfero/trunk@2010 3f533792-8f58-4932-b0fe-aaf55b0a4547
app/controllers/public/account_controller.rb
... ... @@ -38,7 +38,6 @@ class AccountController < PublicController
38 38 @user = User.new(params[:user])
39 39 @user.terms_of_use = environment.terms_of_use
40 40 @terms_of_use = environment.terms_of_use
41   -
42 41 if request.post?
43 42 @user.save!
44 43 @user.person.environment = environment
... ... @@ -49,11 +48,16 @@ class AccountController < PublicController
49 48 go_to_user_initial_page
50 49 flash[:notice] = _("Thanks for signing up!")
51 50 end
  51 + activate_enterprise if params[:enterprise_code]
52 52 rescue ActiveRecord::RecordInvalid
53   - render :action => 'signup'
  53 + if params[:enterprise_code]
  54 + render :action => 'activate_enteprise'
  55 + else
  56 + render :action => 'signup'
  57 + end
54 58 end
55 59 end
56   -
  60 +
57 61 # action to perform logout from the application
58 62 def logout
59 63 self.current_user.forget_me if logged_in?
... ... @@ -121,6 +125,27 @@ class AccountController < PublicController
121 125  
122 126 protected
123 127  
  128 + def activate_enterprise
  129 + @enterprise = Enterprise.return_by_code(params[:enterprise_code])
  130 + unless @enterprise
  131 + render :action => 'invalid_enterprise_code'
  132 + return
  133 + end
  134 +
  135 + if !@enterprise.foundation_year.blank?
  136 + @question = :foundation_year
  137 + elsif !@enterprise.cnpj.blank?
  138 + @question = :cnpj
  139 + end
  140 +
  141 + unless @question
  142 + render :action => 'blocked'
  143 + return
  144 + end
  145 +
  146 + render :action => 'activate_enterprise'; return
  147 + end
  148 +
124 149 def go_to_user_initial_page
125 150 redirect_back_or_default(:controller => "profile_editor", :profile => current_user.login, :action => 'index')
126 151 end
... ...
app/models/organization.rb
... ... @@ -40,7 +40,7 @@ class Organization < Profile
40 40 !self.validation_info.nil?
41 41 end
42 42  
43   - settings_items :contact_person, :contact_email, :acronym, :foundation_year, :legal_form, :economic_activity, :management_information, :validated
  43 + settings_items :contact_person, :contact_email, :acronym, :foundation_year, :legal_form, :economic_activity, :management_information, :validated, :cnpj
44 44  
45 45 validates_format_of :foundation_year, :with => Noosfero::Constants::INTEGER_FORMAT
46 46  
... ...
app/views/account/activate_enterprise.rhtml 0 → 100644
... ... @@ -0,0 +1,42 @@
  1 +<h1><%= _('Register and activate enterprise') %></h1>
  2 +
  3 +<%= error_messages_for :user %>
  4 +<% labelled_form_for :user, @user,
  5 + :html => { :help=>_('Fill all this fields to activate your enterprise and join in this environment.' +
  6 + '<p/>If you forgot your password, do not create a new account,' +
  7 + ' click on the "<b>I forgot my password!</b>" link. ;-)')
  8 + } do |f| -%>
  9 +
  10 +<%= f.text_field :login,
  11 + :help => help=_('"Username" is a simple nickname to recognize you on this environment.'),
  12 + :onchange => 'this.value = convToValidLogin( this.value )' %>
  13 +<small><%= help %></small>
  14 +
  15 +<%= f.text_field :email,
  16 + :help => help=_('We\'ll send you an e-mail to validate your registration.') %>
  17 +<small><%= help %></small>
  18 +
  19 +<%= f.password_field :password,
  20 + :help => help=_('Do not use a obviously password, but try some unforgettable word.') %>
  21 +<small><%= help %></small>
  22 +
  23 +<%= f.password_field :password_confirmation,
  24 + :help => help=_('We need to be sure that you wrote correctly your password.') %>
  25 +<small><%= help %></small>
  26 +
  27 +<%= ApplicationHelper::NoosferoFormBuilder::output_field(@question == :foundation_year ? _('What year your enterprise was founded?') : _('What is the CNPJ of your enterprise?'), text_field_tag(:answer, nil,:help => help=_('We need to be sure that this is your enterprise'))) %>
  28 +
  29 +<% if @terms_of_use %>
  30 + <p>
  31 + <%= @terms_of_use %>
  32 + </p>
  33 + <p>
  34 + <%= check_box 'user', 'terms_accepted' %>
  35 + <%= _('I accept the terms of use') %>
  36 + </p>
  37 +<% end %>
  38 +
  39 +<% button_bar do %>
  40 + <%= submit_button('save', _('Sign up'), :cancel => {:action => 'index'}, :class => 'icon-menu-login') %>
  41 +<% end %>
  42 +<% end -%>
... ...
app/views/account/invalid_enterprise_code.rhtml 0 → 100644
... ... @@ -0,0 +1,5 @@
  1 +<h1><%= _("Invalid enteprise code") %></h1>
  2 +
  3 +<p>
  4 +<%= _('The code you are using for validate your enterprise is not valid. Please check if you are typing it correctly.') %>
  5 +</p>
... ...
script/extract_sies_data.rb
... ... @@ -98,22 +98,25 @@ categories[#{cat.id}] = cat#{@seq}.id
98 98 endereco << " CEP: " << ent.cep
99 99 end
100 100  
101   - puts "new_ent({ :name => #{ent.nome.inspect},
102   - :identifier => #{ent.nome.to_slug.inspect},
103   - :contact_phone => #{ent.tel.inspect},
104   - :address => #{endereco.inspect},
105   - :lat => #{ent.lat.inspect},
106   - :lng => #{ent.long.inspect},
107   - :geocode_precision => #{ent.geomodificou.inspect},
108   - :data => {
109   - :id_sies => #{ent.id_sies.inspect},
110   - :foundation_year => #{ent.extra_data.ANO.inspect},
111   - :cnpj => #{ent.extra_data.CNPJ.inspect}
112   - },
113   - :contact_email => #{email.inspect},
114   - :categories => [cities[#{ent.id_cidade}]]},
115   - [#{ent.products.map{|p| "{ :name => #{p.category.nome.inspect} , :product_category_id => categories[#{p.category.id}] }"}.join(', ')}],
116   - [#{ent.input_products.map{|p| "{ :product_category_id => categories[#{p.category.id}]}" }.join(', ')}])"
  101 + puts <<-EOF
  102 +new_ent({ :name => #{ent.nome.inspect},
  103 + :identifier => #{ent.nome.to_slug.inspect},
  104 + :contact_phone => #{ent.tel.inspect},
  105 + :address => #{endereco.inspect},
  106 + :lat => #{ent.lat.inspect},
  107 + :lng => #{ent.long.inspect},
  108 + :geocode_precision => #{ent.geomodificou.inspect},
  109 + :data => {
  110 + :id_sies => #{ent.id_sies.inspect}
  111 + },
  112 + :contact_email => #{email.inspect},
  113 + :foundation_year => #{ent.extra_data.ANO.inspect},
  114 + :cnpj => #{ent.extra_data.CNPJ.inspect},
  115 + :categories => [cities[#{ent.id_cidade}]]
  116 + },
  117 + [#{ent.products.map{|p| "{ :name => #{p.category.nome.inspect} , :product_category_id => categories[#{p.category.id}] }"}.join(', ')}],
  118 + [#{ent.input_products.map{|p| "{ :product_category_id => categories[#{p.category.id}]}" }.join(', ')}])
  119 +EOF
117 120 end
118 121  
119 122 def dump_city(city)
... ...
script/fbes_populate_helper.rb
... ... @@ -52,7 +52,7 @@ require File.dirname(__FILE__) + &#39;/../config/environment&#39;
52 52 count += 1
53 53 end
54 54 data[:identifier] = ident
55   - ent = Enterprise.create!({:environment => Environment.default}.merge(data), :enabled => false)
  55 + ent = Enterprise.create!({:environment => Environment.default, :enabled => false}.merge(data))
56 56 products.each do |p|
57 57 ent.products.create!(p) unless ent.products.find(:first, :conditions => p)
58 58 end
... ...
test/functional/account_controller_test.rb
... ... @@ -275,6 +275,31 @@ class AccountControllerTest &lt; Test::Unit::TestCase
275 275 assert_redirected_to :controller => 'profile_editor'
276 276 end
277 277  
  278 + should 'report invalid enterprise code on signup' do
  279 + get :signup, :enterprise_code => 'some_invalid_code'
  280 +
  281 + assert_template 'invalid_enterprise_code'
  282 + end
  283 +
  284 + should 'load enterprise from code on signup' do
  285 + ent = Enterprise.create!(:name => 'test enterprise', :identifier => 'test_ent')
  286 + get :signup, :enterprise_code => ent.code
  287 +
  288 + assert_equal ent, assigns(:enterprise)
  289 + end
  290 +
  291 + should 'block enterprises that do not have foundation_year or cnpj'
  292 +
  293 + should 'show form to those enterprises that have foundation year'
  294 +
  295 + should 'show form to those enterprises that have cnpj'
  296 +
  297 + should 'block those who failed to answer the question'
  298 +
  299 + should 'activate enterprise for those who answer the question right'
  300 +
  301 + should 'make new user admin of new enterprise'
  302 +
278 303 protected
279 304 def create_user(options = {})
280 305 post :signup, :user => { :login => 'quire', :email => 'quire@example.com',
... ...
test/unit/enterprise_test.rb
... ... @@ -133,5 +133,18 @@ class EnterpriseTest &lt; Test::Unit::TestCase
133 133 assert_nil Enterprise.return_by_code(ent.code.next)
134 134 end
135 135  
  136 + should 'have foudation_year' do
  137 + ent = Enterprise.create!(:name => 'test enteprise', :identifier => 'test_ent')
  138 +
  139 + assert_respond_to ent, 'foundation_year'
  140 + assert_respond_to ent, 'foundation_year='
  141 + end
  142 +
  143 + should 'have cnpj' do
  144 + ent = Enterprise.create!(:name => 'test enteprise', :identifier => 'test_ent')
  145 +
  146 + assert_respond_to ent, 'cnpj'
  147 + assert_respond_to ent, 'cnpj='
  148 + end
136 149  
137 150 end
... ...