Commit a83021650981877cd2a983a4e2e05bbab9fa93c6
1 parent
e6710a34
Exists in
master
and in
22 other branches
social_network: Join community on login/signup
Join community if user log in or sign up after following a "Join" link within a community. (ActionItem3096)
Showing
2 changed files
with
13 additions
and
23 deletions
Show diff stats
app/controllers/public/account_controller.rb
... | ... | @@ -18,6 +18,7 @@ class AccountController < ApplicationController |
18 | 18 | if @user and @user.activate |
19 | 19 | @message = _("Your account has been activated, now you can log in!") |
20 | 20 | check_redirection |
21 | + session[:join] = params[:join] unless params[:join].blank? | |
21 | 22 | render :action => 'login', :userlogin => @user.login |
22 | 23 | else |
23 | 24 | session[:notice] = _("It looks like you're trying to activate an account. Perhaps have already activated this account?") |
... | ... | @@ -36,7 +37,7 @@ class AccountController < ApplicationController |
36 | 37 | self.current_user ||= User.authenticate(params[:user][:login], params[:user][:password], environment) if params[:user] |
37 | 38 | |
38 | 39 | if logged_in? |
39 | - check_join_in_community(self.current_user) | |
40 | + join_community(self.current_user) | |
40 | 41 | if params[:remember_me] == "1" |
41 | 42 | self.current_user.remember_me |
42 | 43 | cookies[:auth_token] = { :value => self.current_user.remember_token , :expires => self.current_user.remember_token_expires_at } |
... | ... | @@ -104,7 +105,7 @@ class AccountController < ApplicationController |
104 | 105 | end |
105 | 106 | if @user.activated? |
106 | 107 | self.current_user = @user |
107 | - check_join_in_community(@user) | |
108 | + join_community(@user) | |
108 | 109 | go_to_signup_initial_page |
109 | 110 | else |
110 | 111 | @register_pending = true |
... | ... | @@ -453,4 +454,12 @@ class AccountController < ApplicationController |
453 | 454 | @user.update_attributes(:return_to => nil) |
454 | 455 | end |
455 | 456 | end |
457 | + | |
458 | + def join_community(user) | |
459 | + profile_to_join = session[:join] | |
460 | + unless profile_to_join.blank? | |
461 | + environment.profiles.find_by_identifier(profile_to_join).add_member(user.person) | |
462 | + session.delete(:join) | |
463 | + end | |
464 | + end | |
456 | 465 | end | ... | ... |
test/functional/profile_controller_test.rb
... | ... | @@ -477,25 +477,6 @@ class ProfileControllerTest < ActionController::TestCase |
477 | 477 | assert_equal "/profile/#{community.identifier}", @request.session[:previous_location] |
478 | 478 | end |
479 | 479 | |
480 | - should 'redirect to login after user not logged asks to join a community' do | |
481 | - community = Community.create!(:name => 'my test community') | |
482 | - | |
483 | - get :join_not_logged, :profile => community.identifier | |
484 | - | |
485 | - assert_equal community.identifier, @request.session[:join] | |
486 | - assert_redirected_to :controller => :account, :action => :login | |
487 | - end | |
488 | - | |
489 | - should 'redirect to join after user logged asks to join_not_logged a community' do | |
490 | - community = Community.create!(:name => 'my test community') | |
491 | - | |
492 | - login_as(profile.identifier) | |
493 | - get :join_not_logged, :profile => community.identifier | |
494 | - | |
495 | - assert_equal community.identifier, @request.session[:join] | |
496 | - assert_redirected_to :controller => :profile, :action => :join | |
497 | - end | |
498 | - | |
499 | 480 | should 'show number of published events in index' do |
500 | 481 | profile.articles << Event.new(:name => 'Published event', :start_date => Date.today) |
501 | 482 | profile.articles << Event.new(:name => 'Unpublished event', :start_date => Date.today, :published => false) |
... | ... | @@ -1195,7 +1176,7 @@ class ProfileControllerTest < ActionController::TestCase |
1195 | 1176 | 20.times {comment = fast_create(Comment, :source_id => article, :title => 'a comment', :body => 'lalala', :created_at => Time.now)} |
1196 | 1177 | article.reload |
1197 | 1178 | get :index, :profile => profile.identifier |
1198 | - assert_tag 'ul', :attributes => {:class => 'profile-wall-activities-comments'}, :children => {:count => 0 } | |
1179 | + assert_tag 'ul', :attributes => {:class => 'profile-wall-activities-comments'}, :children => {:count => 0 } | |
1199 | 1180 | end |
1200 | 1181 | |
1201 | 1182 | should "view more comments paginated" do |
... | ... | @@ -1221,7 +1202,7 @@ class ProfileControllerTest < ActionController::TestCase |
1221 | 1202 | 20.times {fast_create(Scrap, :sender_id => profile.id, :receiver_id => profile.id, :scrap_id => scrap.id)} |
1222 | 1203 | profile.reload |
1223 | 1204 | get :index, :profile => profile.identifier |
1224 | - assert_tag 'ul', :attributes => {:class => 'profile-wall-activities-comments scrap-replies'}, :children => {:count => 0 } | |
1205 | + assert_tag 'ul', :attributes => {:class => 'profile-wall-activities-comments scrap-replies'}, :children => {:count => 0 } | |
1225 | 1206 | end |
1226 | 1207 | |
1227 | 1208 | should "view more replies paginated" do | ... | ... |