Commit cc6e47460287eca00bc58504a6b9759bc02f5782
Committed by
Antonio Terceiro
1 parent
e090a2b4
Exists in
staging
and in
42 other branches
ActionItem1125: only authenticated users can enable enterprises
* moved box "enterprise activation" to control panel * require login to activate enterprise
Showing
7 changed files
with
119 additions
and
127 deletions
Show diff stats
app/controllers/public/account_controller.rb
... | ... | @@ -4,6 +4,8 @@ class AccountController < ApplicationController |
4 | 4 | |
5 | 5 | require_ssl :except => [ :login_popup, :logout_popup, :wizard, :profile_details ] |
6 | 6 | |
7 | + before_filter :login_required, :only => [:activation_question, :accept_terms, :activate_enterprise] | |
8 | + | |
7 | 9 | # say something nice, you goof! something sweet. |
8 | 10 | def index |
9 | 11 | unless logged_in? |
... | ... | @@ -181,22 +183,6 @@ class AccountController < ApplicationController |
181 | 183 | def accept_terms |
182 | 184 | @enterprise = load_enterprise |
183 | 185 | @question = @enterprise.question |
184 | - | |
185 | - if @enterprise.enabled | |
186 | - render :action => 'already_activated' | |
187 | - return | |
188 | - end | |
189 | - | |
190 | - @question = @enterprise.question | |
191 | - if !@question || @enterprise.blocked? | |
192 | - render :action => 'blocked' | |
193 | - return | |
194 | - end | |
195 | - end | |
196 | - | |
197 | - def accept_terms | |
198 | - @enterprise = load_enterprise | |
199 | - @question = @enterprise.question | |
200 | 186 | if !@question || @enterprise.blocked? |
201 | 187 | render :action => 'blocked' |
202 | 188 | return |
... | ... | @@ -212,7 +198,6 @@ class AccountController < ApplicationController |
212 | 198 | @question = @enterprise.question |
213 | 199 | return unless check_answer |
214 | 200 | return unless check_acceptance_of_terms |
215 | - load_user | |
216 | 201 | |
217 | 202 | activation = load_enterprise_activation |
218 | 203 | if activation && user |
... | ... | @@ -253,18 +238,6 @@ class AccountController < ApplicationController |
253 | 238 | @cannot_redirect = true |
254 | 239 | end |
255 | 240 | |
256 | - def load_user | |
257 | - unless logged_in? | |
258 | - no_redirect | |
259 | - if params[:new_user] | |
260 | - signup | |
261 | - else | |
262 | - login | |
263 | - end | |
264 | - end | |
265 | - true | |
266 | - end | |
267 | - | |
268 | 241 | def check_answer |
269 | 242 | unless answer_correct |
270 | 243 | @enterprise.block | ... | ... |
app/views/account/activation_question.rhtml
... | ... | @@ -28,7 +28,7 @@ |
28 | 28 | |
29 | 29 | <p> <strong><%= _('Pay atention! You have only one chance!') %></strong> </p> |
30 | 30 | |
31 | - <p><%= _("This is a question to know if you is really part of this enterprise. Pay atention because you has only one chance to answer rigth and activate your enterprise. If you answer wrong you will not be able to activate the enterprise automaticaly and must get in touch with the admins of %s by email or phone.") % environment.name %> </p> | |
31 | + <p><%= _("This is a question to know if you really are part of this enterprise. Pay atention because you have only one chance to answer right and activate your enterprise. If you answer wrong you will not be able to activate the enterprise automaticaly and must get in touch with the admins of %s by email or phone.") % environment.name %> </p> | |
32 | 32 | |
33 | 33 | <%= 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, :id => 'enterprise-activation-answer', :help => help=_('We need to be sure that this is your enterprise'))) %> |
34 | 34 | ... | ... |
app/views/home/index.rhtml
... | ... | @@ -47,18 +47,6 @@ |
47 | 47 | <%= environment.description %> |
48 | 48 | <% end %> |
49 | 49 | |
50 | -<% if environment.enabled?('enterprise_activation') %> | |
51 | - | |
52 | - <div id='activation_enterprise'> | |
53 | - <% form_tag({:controller => 'account', :action => 'activation_question'}, {:method => 'get'}) do %> | |
54 | - <p><strong><%= __('Activate your enterprise') %></strong></p> | |
55 | - <%= labelled_form_field(__('Enterprise activation code') + ':', text_field_tag('enterprise_code')) %> | |
56 | - <%= submit_button(:ok, _('Activate')) %> | |
57 | - <% end %> | |
58 | - </div> | |
59 | - | |
60 | -<% end %> | |
61 | - | |
62 | 50 | <% if environment.enabled?('search_in_home') %> |
63 | 51 | <div id='home-search' style='text-align: center'> |
64 | 52 | <% form_tag :controller => 'search', :action => 'index' do %> | ... | ... |
app/views/profile_editor/index.rhtml
... | ... | @@ -60,8 +60,19 @@ |
60 | 60 | <% end %> |
61 | 61 | |
62 | 62 | <%= control_panel_button(_('Manage my groups'), 'groups', :controller => 'memberships') if profile.person? %> |
63 | - | |
64 | 63 | <% end %> |
65 | 64 | |
65 | + <% if environment.enabled?('enterprise_activation') %> | |
66 | + | |
67 | + <div id='activation_enterprise'> | |
68 | + <% form_tag({:controller => 'account', :action => 'activation_question'}, {:method => 'get'}) do %> | |
69 | + <p><strong><%= __('Activate your enterprise') %></strong></p> | |
70 | + <p><%= _("If you received a letter with information about your enterprise activation, add here the activation code that was sent.") %> </p> | |
71 | + <%= labelled_form_field(__('Enterprise activation code') + ':', text_field_tag('enterprise_code')) %> | |
72 | + <%= submit_button(:ok, _('Activate')) %> | |
73 | + <% end %> | |
74 | + </div> | |
75 | + | |
76 | + <% end %> | |
66 | 77 | |
67 | 78 | </div> | ... | ... |
test/functional/account_controller_test.rb
... | ... | @@ -332,7 +332,16 @@ class AccountControllerTest < Test::Unit::TestCase |
332 | 332 | # # |
333 | 333 | ################################ |
334 | 334 | |
335 | + should 'require login for validation question' do | |
336 | + get :activation_question, :enterprise_code => 'some_code' | |
337 | + | |
338 | + assert_redirected_to :controller => 'account', :action => 'login' | |
339 | + end | |
340 | + | |
335 | 341 | should 'report invalid enterprise code on signup' do |
342 | + person = create_user('mylogin').person | |
343 | + login_as(person.identifier) | |
344 | + | |
336 | 345 | EnterpriseActivation.expects(:find_by_code).with('some_invalid_code').returns(nil).at_least_once |
337 | 346 | |
338 | 347 | get :activation_question, :enterprise_code => 'some_invalid_code' |
... | ... | @@ -341,6 +350,9 @@ class AccountControllerTest < Test::Unit::TestCase |
341 | 350 | end |
342 | 351 | |
343 | 352 | should 'report enterprise already enabled' do |
353 | + person = create_user('mylogin').person | |
354 | + login_as(person.identifier) | |
355 | + | |
344 | 356 | ent = Enterprise.create!(:name => 'test enterprise', :identifier => 'test_ent', :cnpj => '0'*14, :enabled => true) |
345 | 357 | task = mock |
346 | 358 | task.expects(:enterprise).returns(ent).at_least_once |
... | ... | @@ -352,6 +364,9 @@ class AccountControllerTest < Test::Unit::TestCase |
352 | 364 | end |
353 | 365 | |
354 | 366 | should 'load enterprise from code on for validation question' do |
367 | + person = create_user('mylogin').person | |
368 | + login_as(person.identifier) | |
369 | + | |
355 | 370 | ent = Enterprise.create!(:name => 'test enterprise', :identifier => 'test_ent') |
356 | 371 | |
357 | 372 | task = mock |
... | ... | @@ -364,6 +379,9 @@ class AccountControllerTest < Test::Unit::TestCase |
364 | 379 | end |
365 | 380 | |
366 | 381 | should 'block enterprises that do not have foundation_year or cnpj' do |
382 | + person = create_user('mylogin').person | |
383 | + login_as(person.identifier) | |
384 | + | |
367 | 385 | ent = Enterprise.create!(:name => 'test enterprise', :identifier => 'test_ent', :enabled => false) |
368 | 386 | |
369 | 387 | task = mock |
... | ... | @@ -376,6 +394,9 @@ class AccountControllerTest < Test::Unit::TestCase |
376 | 394 | end |
377 | 395 | |
378 | 396 | should 'show form to those enterprises that have foundation year' do |
397 | + person = create_user('mylogin').person | |
398 | + login_as(person.identifier) | |
399 | + | |
379 | 400 | ent = Enterprise.create!(:name => 'test enterprise', :identifier => 'test_ent', :foundation_year => 1998, :enabled => false) |
380 | 401 | |
381 | 402 | task = mock |
... | ... | @@ -388,6 +409,9 @@ class AccountControllerTest < Test::Unit::TestCase |
388 | 409 | end |
389 | 410 | |
390 | 411 | should 'show form to those enterprises that have cnpj' do |
412 | + person = create_user('mylogin').person | |
413 | + login_as(person.identifier) | |
414 | + | |
391 | 415 | ent = Enterprise.create!(:name => 'test enterprise', :identifier => 'test_ent', :cnpj => '0'*14, :enabled => false) |
392 | 416 | |
393 | 417 | task = mock |
... | ... | @@ -400,6 +424,9 @@ class AccountControllerTest < Test::Unit::TestCase |
400 | 424 | end |
401 | 425 | |
402 | 426 | should 'block those who are blocked' do |
427 | + person = create_user('mylogin').person | |
428 | + login_as(person.identifier) | |
429 | + | |
403 | 430 | ent = Enterprise.create!(:name => 'test enterprise', :identifier => 'test_ent', :foundation_year => '1998', :enabled => false) |
404 | 431 | ent.block |
405 | 432 | |
... | ... | @@ -412,7 +439,37 @@ class AccountControllerTest < Test::Unit::TestCase |
412 | 439 | assert_template 'blocked' |
413 | 440 | end |
414 | 441 | |
442 | + should 'put hidden field with enterprise code for answering question' do | |
443 | + person = create_user('mylogin').person | |
444 | + login_as(person.identifier) | |
445 | + | |
446 | + ent = Enterprise.create!(:name => 'test enterprise', :identifier => 'test_ent', :foundation_year => 1998, :enabled => false) | |
447 | + | |
448 | + task = mock | |
449 | + task.expects(:enterprise).returns(ent).at_least_once | |
450 | + EnterpriseActivation.expects(:find_by_code).with('0123456789').returns(task).at_least_once | |
451 | + | |
452 | + get :activation_question, :enterprise_code => '0123456789' | |
453 | + | |
454 | + assert_tag :tag => 'input', :attributes => { :type => 'hidden', :name => 'enterprise_code', :value => '0123456789'} | |
455 | + end | |
456 | + | |
457 | + should 'require login for accept terms' do | |
458 | + ent = Enterprise.create!(:name => 'test enterprise', :identifier => 'test_ent', :foundation_year => 1998, :enabled => false) | |
459 | + | |
460 | + task = mock | |
461 | + task.expects(:enterprise).returns(ent).never | |
462 | + EnterpriseActivation.expects(:find_by_code).with('0123456789').returns(task).never | |
463 | + | |
464 | + post :accept_terms, :enterprise_code => '0123456789', :answer => '1998' | |
465 | + | |
466 | + assert_redirected_to :controller => 'account', :action => 'login' | |
467 | + end | |
468 | + | |
415 | 469 | should 'block those who failed to answer the question' do |
470 | + person = create_user('mylogin').person | |
471 | + login_as(person.identifier) | |
472 | + | |
416 | 473 | ent = Enterprise.create!(:name => 'test enterprise', :identifier => 'test_ent', :foundation_year => 1998, :enabled => false) |
417 | 474 | |
418 | 475 | task = mock |
... | ... | @@ -429,6 +486,9 @@ class AccountControllerTest < Test::Unit::TestCase |
429 | 486 | end |
430 | 487 | |
431 | 488 | should 'show terms of use for enterprise owners' do |
489 | + person = create_user('mylogin').person | |
490 | + login_as(person.identifier) | |
491 | + | |
432 | 492 | env = Environment.default |
433 | 493 | env.terms_of_enterprise_use = 'Some terms' |
434 | 494 | env.save! |
... | ... | @@ -443,32 +503,37 @@ class AccountControllerTest < Test::Unit::TestCase |
443 | 503 | assert_tag :tag => 'div', :content => 'Some terms' |
444 | 504 | end |
445 | 505 | |
446 | - should 'not activate if user does not accept terms' do | |
506 | + should 'block who is blocked but directly arrive in the second step' do | |
507 | + person = create_user('mylogin').person | |
508 | + login_as(person.identifier) | |
509 | + | |
447 | 510 | ent = Enterprise.create!(:name => 'test enterprise', :identifier => 'test_ent', :foundation_year => 1998, :enabled => false) |
448 | - p = create_user('test_user', :password => 'blih', :password_confirmation => 'blih', :email => 'test@noosfero.com').person | |
449 | - login_as(p.identifier) | |
511 | + ent.block | |
512 | + ent.save | |
450 | 513 | |
451 | - task = EnterpriseActivation.create!(:enterprise => ent) | |
514 | + task = mock | |
515 | + task.expects(:enterprise).returns(ent).at_least_once | |
452 | 516 | EnterpriseActivation.expects(:find_by_code).with('0123456789').returns(task).at_least_once |
453 | 517 | |
454 | - post :activate_enterprise, :enterprise_code => '0123456789', :answer => '1998', :terms_accepted => false | |
455 | - ent.reload | |
518 | + get :accept_terms, :enterprise_code => '0123456789', :answer => 1998 | |
456 | 519 | |
457 | - assert !ent.enabled | |
458 | - assert_not_includes ent.members, p | |
520 | + assert_template 'blocked' | |
459 | 521 | end |
460 | 522 | |
461 | - should 'ask for login or singup if not logged in' do | |
523 | + should 'require login to activate enterprise' do | |
524 | + env = Environment.default | |
525 | + env.terms_of_use = 'some terms' | |
526 | + env.save! | |
462 | 527 | ent = Enterprise.create!(:name => 'test enterprise', :identifier => 'test_ent', :foundation_year => 1998, :enabled => false) |
463 | 528 | task = EnterpriseActivation.create!(:enterprise => ent) |
464 | - EnterpriseActivation.expects(:find_by_code).with('0123456789').returns(task).at_least_once | |
529 | + EnterpriseActivation.expects(:find_by_code).with('0123456789').returns(task).never | |
465 | 530 | |
466 | 531 | post :activate_enterprise, :enterprise_code => '0123456789', :answer => '1998', :terms_accepted => true |
467 | 532 | |
468 | - assert_template 'activate_enterprise' | |
533 | + assert_redirected_to :controller => 'account', :action => 'login' | |
469 | 534 | end |
470 | 535 | |
471 | - should 'activate enterprise and make logged user admin' do | |
536 | + should 'not activate if user does not accept terms' do | |
472 | 537 | ent = Enterprise.create!(:name => 'test enterprise', :identifier => 'test_ent', :foundation_year => 1998, :enabled => false) |
473 | 538 | p = create_user('test_user', :password => 'blih', :password_confirmation => 'blih', :email => 'test@noosfero.com').person |
474 | 539 | login_as(p.identifier) |
... | ... | @@ -476,78 +541,32 @@ class AccountControllerTest < Test::Unit::TestCase |
476 | 541 | task = EnterpriseActivation.create!(:enterprise => ent) |
477 | 542 | EnterpriseActivation.expects(:find_by_code).with('0123456789').returns(task).at_least_once |
478 | 543 | |
479 | - post :activate_enterprise, :enterprise_code => '0123456789', :answer => '1998', :terms_accepted => true | |
480 | - ent.reload | |
481 | - | |
482 | - assert ent.enabled | |
483 | - assert_includes ent.members, p | |
484 | - end | |
485 | - | |
486 | - should 'not activate enterprise for inexistent user' do | |
487 | - ent = Enterprise.create!(:name => 'test enterprise', :identifier => 'test_ent', :foundation_year => 1998, :enabled => false) | |
488 | - task = EnterpriseActivation.create!(:enterprise => ent) | |
489 | - EnterpriseActivation.expects(:find_by_code).with('0123456789').returns(task).at_least_once | |
490 | - | |
491 | - post :activate_enterprise, :enterprise_code => '0123456789', :answer => '1998', :terms_accepted => true, :user => { :login => 'inexistent_user', :password => 'inexistent_password' } | |
544 | + post :activate_enterprise, :enterprise_code => '0123456789', :answer => '1998', :terms_accepted => false | |
492 | 545 | ent.reload |
493 | 546 | |
494 | 547 | assert !ent.enabled |
548 | + assert_not_includes ent.members, p | |
495 | 549 | end |
496 | 550 | |
497 | - should 'activate enterprise and make unlogged user admin' do | |
551 | + should 'activate enterprise and make logged user admin' do | |
498 | 552 | ent = Enterprise.create!(:name => 'test enterprise', :identifier => 'test_ent', :foundation_year => 1998, :enabled => false) |
499 | 553 | p = create_user('test_user', :password => 'blih', :password_confirmation => 'blih', :email => 'test@noosfero.com').person |
554 | + login_as(p.identifier) | |
500 | 555 | |
501 | 556 | task = EnterpriseActivation.create!(:enterprise => ent) |
502 | 557 | EnterpriseActivation.expects(:find_by_code).with('0123456789').returns(task).at_least_once |
503 | 558 | |
504 | - post :activate_enterprise, :enterprise_code => '0123456789', :answer => '1998', :terms_accepted => true, :user => { :login => 'test_user', :password => 'blih' } | |
559 | + post :activate_enterprise, :enterprise_code => '0123456789', :answer => '1998', :terms_accepted => true | |
505 | 560 | ent.reload |
506 | 561 | |
507 | 562 | assert ent.enabled |
508 | 563 | assert_includes ent.members, p |
509 | 564 | end |
510 | 565 | |
511 | - should 'activate enterprise, create user and make admin' do | |
512 | - ent = Enterprise.create!(:name => 'test enterprise', :identifier => 'test_ent', :foundation_year => 1998, :enabled => false) | |
513 | - | |
514 | - task = EnterpriseActivation.create!(:enterprise => ent) | |
515 | - EnterpriseActivation.expects(:find_by_code).with('0123456789').returns(task).at_least_once | |
516 | - | |
517 | - post :activate_enterprise, :enterprise_code => '0123456789', :answer => '1998', :terms_accepted => true, :new_user => true, :user => { :login => 'test_user', :password => 'blih', :password_confirmation => 'blih', :email => 'test@noosfero.com' }, :profile_data => person_data | |
518 | - ent.reload | |
519 | - | |
520 | - assert ent.enabled | |
521 | - assert_includes ent.members.map(&:identifier), 'test_user' | |
522 | - end | |
523 | - | |
524 | - should 'put hidden field with enterprise code for answering question' do | |
525 | - ent = Enterprise.create!(:name => 'test enterprise', :identifier => 'test_ent', :foundation_year => 1998, :enabled => false) | |
526 | - | |
527 | - task = mock | |
528 | - task.expects(:enterprise).returns(ent).at_least_once | |
529 | - EnterpriseActivation.expects(:find_by_code).with('0123456789').returns(task).at_least_once | |
530 | - | |
531 | - get :activation_question, :enterprise_code => '0123456789' | |
532 | - | |
533 | - assert_tag :tag => 'input', :attributes => { :type => 'hidden', :name => 'enterprise_code', :value => '0123456789'} | |
534 | - end | |
535 | - | |
536 | - should 'block who is blocked but directly arrive in the second step' do | |
537 | - ent = Enterprise.create!(:name => 'test enterprise', :identifier => 'test_ent', :foundation_year => 1998, :enabled => false) | |
538 | - ent.block | |
539 | - ent.save | |
540 | - | |
541 | - task = mock | |
542 | - task.expects(:enterprise).returns(ent).at_least_once | |
543 | - EnterpriseActivation.expects(:find_by_code).with('0123456789').returns(task).at_least_once | |
544 | - | |
545 | - get :accept_terms, :enterprise_code => '0123456789', :answer => 1998 | |
546 | - | |
547 | - assert_template 'blocked' | |
548 | - end | |
549 | - | |
550 | 566 | should 'load terms of use for users when creating new users as activate enterprise' do |
567 | + person = create_user('mylogin').person | |
568 | + login_as(person.identifier) | |
569 | + | |
551 | 570 | env = Environment.default |
552 | 571 | env.terms_of_use = 'some terms' |
553 | 572 | env.save! | ... | ... |
test/functional/home_controller_test.rb
... | ... | @@ -22,24 +22,6 @@ all_fixtures |
22 | 22 | assert_valid_xhtml |
23 | 23 | end |
24 | 24 | |
25 | - should 'not display form for enterprise activation if disabled in environment' do | |
26 | - env = Environment.default | |
27 | - env.disable('enterprise_activation') | |
28 | - env.save! | |
29 | - | |
30 | - get :index | |
31 | - assert_no_tag :tag => 'div', :attributes => { :id => 'activation_enterprise' }, :descendant => {:tag => 'form', :attributes => {:action => '/account/activation_question'}} | |
32 | - end | |
33 | - | |
34 | - should 'display form for enterprise activation if enabled on environment' do | |
35 | - env = Environment.default | |
36 | - env.enable('enterprise_activation') | |
37 | - env.save! | |
38 | - | |
39 | - get :index | |
40 | - assert_tag :tag => 'div', :attributes => { :id => 'activation_enterprise' }, :descendant => {:tag => 'form', :attributes => {:action => '/account/activation_question'}} | |
41 | - end | |
42 | - | |
43 | 25 | should 'not display news from portal if disabled in environment' do |
44 | 26 | env = Environment.default |
45 | 27 | env.disable('use_portal_community') | ... | ... |
test/functional/profile_editor_controller_test.rb
... | ... | @@ -694,4 +694,23 @@ class ProfileEditorControllerTest < Test::Unit::TestCase |
694 | 694 | assert_template 'edit' |
695 | 695 | end |
696 | 696 | |
697 | + should 'not display form for enterprise activation if disabled in environment' do | |
698 | + env = Environment.default | |
699 | + env.disable('enterprise_activation') | |
700 | + env.save! | |
701 | + | |
702 | + get :index, :profile => profile.identifier | |
703 | + assert_no_tag :tag => 'div', :attributes => { :id => 'activation_enterprise' }, :descendant => {:tag => 'form', :attributes => {:action => '/account/activation_question'}} | |
704 | + end | |
705 | + | |
706 | + should 'display form for enterprise activation if enabled on environment' do | |
707 | + env = Environment.default | |
708 | + env.enable('enterprise_activation') | |
709 | + env.save! | |
710 | + | |
711 | + get :index, :profile => profile.identifier | |
712 | + assert_tag :tag => 'div', :attributes => { :id => 'activation_enterprise' }, :descendant => {:tag => 'form', :attributes => {:action => '/account/activation_question'}} | |
713 | + end | |
714 | + | |
715 | + | |
697 | 716 | end | ... | ... |