From 92a678148933c8af3f85821e7fbb429e07c497c4 Mon Sep 17 00:00:00 2001 From: MoisesMachado Date: Thu, 12 Jun 2008 18:15:11 +0000 Subject: [PATCH] ActionItem439: made infraestrucure to the activation of enterprises --- app/controllers/public/account_controller.rb | 31 ++++++++++++++++++++++++++++--- app/models/organization.rb | 2 +- app/views/account/activate_enterprise.rhtml | 42 ++++++++++++++++++++++++++++++++++++++++++ app/views/account/invalid_enterprise_code.rhtml | 5 +++++ script/extract_sies_data.rb | 35 +++++++++++++++++++---------------- script/fbes_populate_helper.rb | 2 +- test/functional/account_controller_test.rb | 25 +++++++++++++++++++++++++ test/unit/enterprise_test.rb | 13 +++++++++++++ 8 files changed, 134 insertions(+), 21 deletions(-) create mode 100644 app/views/account/activate_enterprise.rhtml create mode 100644 app/views/account/invalid_enterprise_code.rhtml diff --git a/app/controllers/public/account_controller.rb b/app/controllers/public/account_controller.rb index b733ccf..901b164 100644 --- a/app/controllers/public/account_controller.rb +++ b/app/controllers/public/account_controller.rb @@ -38,7 +38,6 @@ class AccountController < PublicController @user = User.new(params[:user]) @user.terms_of_use = environment.terms_of_use @terms_of_use = environment.terms_of_use - if request.post? @user.save! @user.person.environment = environment @@ -49,11 +48,16 @@ class AccountController < PublicController go_to_user_initial_page flash[:notice] = _("Thanks for signing up!") end + activate_enterprise if params[:enterprise_code] rescue ActiveRecord::RecordInvalid - render :action => 'signup' + if params[:enterprise_code] + render :action => 'activate_enteprise' + else + render :action => 'signup' + end end end - + # action to perform logout from the application def logout self.current_user.forget_me if logged_in? @@ -121,6 +125,27 @@ class AccountController < PublicController protected + def activate_enterprise + @enterprise = Enterprise.return_by_code(params[:enterprise_code]) + unless @enterprise + render :action => 'invalid_enterprise_code' + return + end + + if !@enterprise.foundation_year.blank? + @question = :foundation_year + elsif !@enterprise.cnpj.blank? + @question = :cnpj + end + + unless @question + render :action => 'blocked' + return + end + + render :action => 'activate_enterprise'; return + end + def go_to_user_initial_page redirect_back_or_default(:controller => "profile_editor", :profile => current_user.login, :action => 'index') end diff --git a/app/models/organization.rb b/app/models/organization.rb index 087f5fc..0f5c471 100644 --- a/app/models/organization.rb +++ b/app/models/organization.rb @@ -40,7 +40,7 @@ class Organization < Profile !self.validation_info.nil? end - settings_items :contact_person, :contact_email, :acronym, :foundation_year, :legal_form, :economic_activity, :management_information, :validated + settings_items :contact_person, :contact_email, :acronym, :foundation_year, :legal_form, :economic_activity, :management_information, :validated, :cnpj validates_format_of :foundation_year, :with => Noosfero::Constants::INTEGER_FORMAT diff --git a/app/views/account/activate_enterprise.rhtml b/app/views/account/activate_enterprise.rhtml new file mode 100644 index 0000000..c16d5b4 --- /dev/null +++ b/app/views/account/activate_enterprise.rhtml @@ -0,0 +1,42 @@ +

<%= _('Register and activate enterprise') %>

+ +<%= error_messages_for :user %> +<% labelled_form_for :user, @user, + :html => { :help=>_('Fill all this fields to activate your enterprise and join in this environment.' + + '

If you forgot your password, do not create a new account,' + + ' click on the "I forgot my password!" link. ;-)') + } do |f| -%> + +<%= f.text_field :login, + :help => help=_('"Username" is a simple nickname to recognize you on this environment.'), + :onchange => 'this.value = convToValidLogin( this.value )' %> +<%= help %> + +<%= f.text_field :email, + :help => help=_('We\'ll send you an e-mail to validate your registration.') %> +<%= help %> + +<%= f.password_field :password, + :help => help=_('Do not use a obviously password, but try some unforgettable word.') %> +<%= help %> + +<%= f.password_field :password_confirmation, + :help => help=_('We need to be sure that you wrote correctly your password.') %> +<%= help %> + +<%= 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'))) %> + +<% if @terms_of_use %> +

+ <%= @terms_of_use %> +

+

+ <%= check_box 'user', 'terms_accepted' %> + <%= _('I accept the terms of use') %> +

+<% end %> + +<% button_bar do %> + <%= submit_button('save', _('Sign up'), :cancel => {:action => 'index'}, :class => 'icon-menu-login') %> +<% end %> +<% end -%> diff --git a/app/views/account/invalid_enterprise_code.rhtml b/app/views/account/invalid_enterprise_code.rhtml new file mode 100644 index 0000000..34c81bf --- /dev/null +++ b/app/views/account/invalid_enterprise_code.rhtml @@ -0,0 +1,5 @@ +

<%= _("Invalid enteprise code") %>

+ +

+<%= _('The code you are using for validate your enterprise is not valid. Please check if you are typing it correctly.') %> +

diff --git a/script/extract_sies_data.rb b/script/extract_sies_data.rb index 17fb61f..dba3481 100644 --- a/script/extract_sies_data.rb +++ b/script/extract_sies_data.rb @@ -98,22 +98,25 @@ categories[#{cat.id}] = cat#{@seq}.id endereco << " CEP: " << ent.cep end - puts "new_ent({ :name => #{ent.nome.inspect}, - :identifier => #{ent.nome.to_slug.inspect}, - :contact_phone => #{ent.tel.inspect}, - :address => #{endereco.inspect}, - :lat => #{ent.lat.inspect}, - :lng => #{ent.long.inspect}, - :geocode_precision => #{ent.geomodificou.inspect}, - :data => { - :id_sies => #{ent.id_sies.inspect}, - :foundation_year => #{ent.extra_data.ANO.inspect}, - :cnpj => #{ent.extra_data.CNPJ.inspect} - }, - :contact_email => #{email.inspect}, - :categories => [cities[#{ent.id_cidade}]]}, - [#{ent.products.map{|p| "{ :name => #{p.category.nome.inspect} , :product_category_id => categories[#{p.category.id}] }"}.join(', ')}], - [#{ent.input_products.map{|p| "{ :product_category_id => categories[#{p.category.id}]}" }.join(', ')}])" + puts <<-EOF +new_ent({ :name => #{ent.nome.inspect}, + :identifier => #{ent.nome.to_slug.inspect}, + :contact_phone => #{ent.tel.inspect}, + :address => #{endereco.inspect}, + :lat => #{ent.lat.inspect}, + :lng => #{ent.long.inspect}, + :geocode_precision => #{ent.geomodificou.inspect}, + :data => { + :id_sies => #{ent.id_sies.inspect} + }, + :contact_email => #{email.inspect}, + :foundation_year => #{ent.extra_data.ANO.inspect}, + :cnpj => #{ent.extra_data.CNPJ.inspect}, + :categories => [cities[#{ent.id_cidade}]] + }, + [#{ent.products.map{|p| "{ :name => #{p.category.nome.inspect} , :product_category_id => categories[#{p.category.id}] }"}.join(', ')}], + [#{ent.input_products.map{|p| "{ :product_category_id => categories[#{p.category.id}]}" }.join(', ')}]) +EOF end def dump_city(city) diff --git a/script/fbes_populate_helper.rb b/script/fbes_populate_helper.rb index 138fd04..3b117ad 100644 --- a/script/fbes_populate_helper.rb +++ b/script/fbes_populate_helper.rb @@ -52,7 +52,7 @@ require File.dirname(__FILE__) + '/../config/environment' count += 1 end data[:identifier] = ident - ent = Enterprise.create!({:environment => Environment.default}.merge(data), :enabled => false) + ent = Enterprise.create!({:environment => Environment.default, :enabled => false}.merge(data)) products.each do |p| ent.products.create!(p) unless ent.products.find(:first, :conditions => p) end diff --git a/test/functional/account_controller_test.rb b/test/functional/account_controller_test.rb index a8dab57..53dc779 100644 --- a/test/functional/account_controller_test.rb +++ b/test/functional/account_controller_test.rb @@ -275,6 +275,31 @@ class AccountControllerTest < Test::Unit::TestCase assert_redirected_to :controller => 'profile_editor' end + should 'report invalid enterprise code on signup' do + get :signup, :enterprise_code => 'some_invalid_code' + + assert_template 'invalid_enterprise_code' + end + + should 'load enterprise from code on signup' do + ent = Enterprise.create!(:name => 'test enterprise', :identifier => 'test_ent') + get :signup, :enterprise_code => ent.code + + assert_equal ent, assigns(:enterprise) + end + + should 'block enterprises that do not have foundation_year or cnpj' + + should 'show form to those enterprises that have foundation year' + + should 'show form to those enterprises that have cnpj' + + should 'block those who failed to answer the question' + + should 'activate enterprise for those who answer the question right' + + should 'make new user admin of new enterprise' + protected def create_user(options = {}) post :signup, :user => { :login => 'quire', :email => 'quire@example.com', diff --git a/test/unit/enterprise_test.rb b/test/unit/enterprise_test.rb index 38b191f..2054ebc 100644 --- a/test/unit/enterprise_test.rb +++ b/test/unit/enterprise_test.rb @@ -133,5 +133,18 @@ class EnterpriseTest < Test::Unit::TestCase assert_nil Enterprise.return_by_code(ent.code.next) end + should 'have foudation_year' do + ent = Enterprise.create!(:name => 'test enteprise', :identifier => 'test_ent') + + assert_respond_to ent, 'foundation_year' + assert_respond_to ent, 'foundation_year=' + end + + should 'have cnpj' do + ent = Enterprise.create!(:name => 'test enteprise', :identifier => 'test_ent') + + assert_respond_to ent, 'cnpj' + assert_respond_to ent, 'cnpj=' + end end -- libgit2 0.21.2