Commit 92a678148933c8af3f85821e7fbb429e07c497c4
1 parent
0c20ed40
Exists in
master
and in
29 other branches
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
Showing
8 changed files
with
134 additions
and
21 deletions
Show diff stats
app/controllers/public/account_controller.rb
| @@ -38,7 +38,6 @@ class AccountController < PublicController | @@ -38,7 +38,6 @@ class AccountController < PublicController | ||
| 38 | @user = User.new(params[:user]) | 38 | @user = User.new(params[:user]) |
| 39 | @user.terms_of_use = environment.terms_of_use | 39 | @user.terms_of_use = environment.terms_of_use |
| 40 | @terms_of_use = environment.terms_of_use | 40 | @terms_of_use = environment.terms_of_use |
| 41 | - | ||
| 42 | if request.post? | 41 | if request.post? |
| 43 | @user.save! | 42 | @user.save! |
| 44 | @user.person.environment = environment | 43 | @user.person.environment = environment |
| @@ -49,11 +48,16 @@ class AccountController < PublicController | @@ -49,11 +48,16 @@ class AccountController < PublicController | ||
| 49 | go_to_user_initial_page | 48 | go_to_user_initial_page |
| 50 | flash[:notice] = _("Thanks for signing up!") | 49 | flash[:notice] = _("Thanks for signing up!") |
| 51 | end | 50 | end |
| 51 | + activate_enterprise if params[:enterprise_code] | ||
| 52 | rescue ActiveRecord::RecordInvalid | 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 | end | 58 | end |
| 55 | end | 59 | end |
| 56 | - | 60 | + |
| 57 | # action to perform logout from the application | 61 | # action to perform logout from the application |
| 58 | def logout | 62 | def logout |
| 59 | self.current_user.forget_me if logged_in? | 63 | self.current_user.forget_me if logged_in? |
| @@ -121,6 +125,27 @@ class AccountController < PublicController | @@ -121,6 +125,27 @@ class AccountController < PublicController | ||
| 121 | 125 | ||
| 122 | protected | 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 | def go_to_user_initial_page | 149 | def go_to_user_initial_page |
| 125 | redirect_back_or_default(:controller => "profile_editor", :profile => current_user.login, :action => 'index') | 150 | redirect_back_or_default(:controller => "profile_editor", :profile => current_user.login, :action => 'index') |
| 126 | end | 151 | end |
app/models/organization.rb
| @@ -40,7 +40,7 @@ class Organization < Profile | @@ -40,7 +40,7 @@ class Organization < Profile | ||
| 40 | !self.validation_info.nil? | 40 | !self.validation_info.nil? |
| 41 | end | 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 | validates_format_of :foundation_year, :with => Noosfero::Constants::INTEGER_FORMAT | 45 | validates_format_of :foundation_year, :with => Noosfero::Constants::INTEGER_FORMAT |
| 46 | 46 |
| @@ -0,0 +1,42 @@ | @@ -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 -%> |
script/extract_sies_data.rb
| @@ -98,22 +98,25 @@ categories[#{cat.id}] = cat#{@seq}.id | @@ -98,22 +98,25 @@ categories[#{cat.id}] = cat#{@seq}.id | ||
| 98 | endereco << " CEP: " << ent.cep | 98 | endereco << " CEP: " << ent.cep |
| 99 | end | 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 | end | 120 | end |
| 118 | 121 | ||
| 119 | def dump_city(city) | 122 | def dump_city(city) |
script/fbes_populate_helper.rb
| @@ -52,7 +52,7 @@ require File.dirname(__FILE__) + '/../config/environment' | @@ -52,7 +52,7 @@ require File.dirname(__FILE__) + '/../config/environment' | ||
| 52 | count += 1 | 52 | count += 1 |
| 53 | end | 53 | end |
| 54 | data[:identifier] = ident | 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 | products.each do |p| | 56 | products.each do |p| |
| 57 | ent.products.create!(p) unless ent.products.find(:first, :conditions => p) | 57 | ent.products.create!(p) unless ent.products.find(:first, :conditions => p) |
| 58 | end | 58 | end |
test/functional/account_controller_test.rb
| @@ -275,6 +275,31 @@ class AccountControllerTest < Test::Unit::TestCase | @@ -275,6 +275,31 @@ class AccountControllerTest < Test::Unit::TestCase | ||
| 275 | assert_redirected_to :controller => 'profile_editor' | 275 | assert_redirected_to :controller => 'profile_editor' |
| 276 | end | 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 | protected | 303 | protected |
| 279 | def create_user(options = {}) | 304 | def create_user(options = {}) |
| 280 | post :signup, :user => { :login => 'quire', :email => 'quire@example.com', | 305 | post :signup, :user => { :login => 'quire', :email => 'quire@example.com', |
test/unit/enterprise_test.rb
| @@ -133,5 +133,18 @@ class EnterpriseTest < Test::Unit::TestCase | @@ -133,5 +133,18 @@ class EnterpriseTest < Test::Unit::TestCase | ||
| 133 | assert_nil Enterprise.return_by_code(ent.code.next) | 133 | assert_nil Enterprise.return_by_code(ent.code.next) |
| 134 | end | 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 | end | 150 | end |