Commit a99b94faa74cba50b78d363fd9a3af5c5de18824

Authored by Daniela Feitosa
2 parents d5f224bb 3923d48a

Merge branch 'AI3096-join_community' into rails235

app/controllers/public/account_controller.rb
@@ -17,6 +17,7 @@ class AccountController < ApplicationController @@ -17,6 +17,7 @@ class AccountController < ApplicationController
17 @user = User.find_by_activation_code(params[:activation_code]) if params[:activation_code] 17 @user = User.find_by_activation_code(params[:activation_code]) if params[:activation_code]
18 if @user and @user.activate 18 if @user and @user.activate
19 @message = _("Your account has been activated, now you can log in!") 19 @message = _("Your account has been activated, now you can log in!")
  20 + session[:join] = params[:join] unless params[:join].blank?
20 render :action => 'login', :userlogin => @user.login 21 render :action => 'login', :userlogin => @user.login
21 else 22 else
22 session[:notice] = _("It looks like you're trying to activate an account. Perhaps have already activated this account?") 23 session[:notice] = _("It looks like you're trying to activate an account. Perhaps have already activated this account?")
@@ -35,6 +36,7 @@ class AccountController < ApplicationController @@ -35,6 +36,7 @@ class AccountController < ApplicationController
35 self.current_user ||= User.authenticate(params[:user][:login], params[:user][:password], environment) if params[:user] 36 self.current_user ||= User.authenticate(params[:user][:login], params[:user][:password], environment) if params[:user]
36 37
37 if logged_in? 38 if logged_in?
  39 + join_community(self.current_user)
38 if params[:remember_me] == "1" 40 if params[:remember_me] == "1"
39 self.current_user.remember_me 41 self.current_user.remember_me
40 cookies[:auth_token] = { :value => self.current_user.remember_token , :expires => self.current_user.remember_token_expires_at } 42 cookies[:auth_token] = { :value => self.current_user.remember_token , :expires => self.current_user.remember_token_expires_at }
@@ -91,6 +93,7 @@ class AccountController < ApplicationController @@ -91,6 +93,7 @@ class AccountController < ApplicationController
91 if session[:may_be_a_bot] 93 if session[:may_be_a_bot]
92 return false unless verify_recaptcha :model=>@user, :message=>_('Captcha (the human test)') 94 return false unless verify_recaptcha :model=>@user, :message=>_('Captcha (the human test)')
93 end 95 end
  96 + @user.community_to_join = session[:join]
94 @user.signup! 97 @user.signup!
95 owner_role = Role.find_by_name('owner') 98 owner_role = Role.find_by_name('owner')
96 @user.person.affiliate(@user.person, [owner_role]) if owner_role 99 @user.person.affiliate(@user.person, [owner_role]) if owner_role
@@ -101,6 +104,7 @@ class AccountController < ApplicationController @@ -101,6 +104,7 @@ class AccountController < ApplicationController
101 end 104 end
102 if @user.activated? 105 if @user.activated?
103 self.current_user = @user 106 self.current_user = @user
  107 + join_community(@user)
104 go_to_signup_initial_page 108 go_to_signup_initial_page
105 else 109 else
106 @register_pending = true 110 @register_pending = true
@@ -448,4 +452,12 @@ class AccountController < ApplicationController @@ -448,4 +452,12 @@ class AccountController < ApplicationController
448 redirect_back_or_default(default) 452 redirect_back_or_default(default)
449 end 453 end
450 end 454 end
  455 +
  456 + def join_community(user)
  457 + profile_to_join = session[:join]
  458 + unless profile_to_join.blank?
  459 + environment.profiles.find_by_identifier(profile_to_join).add_member(user.person)
  460 + session.delete(:join)
  461 + end
  462 + end
451 end 463 end
app/controllers/public/profile_controller.rb
@@ -3,7 +3,7 @@ class ProfileController < PublicController @@ -3,7 +3,7 @@ class ProfileController < PublicController
3 needs_profile 3 needs_profile
4 before_filter :check_access_to_profile, :except => [:join, :join_not_logged, :index, :add] 4 before_filter :check_access_to_profile, :except => [:join, :join_not_logged, :index, :add]
5 before_filter :store_location, :only => [:join, :join_not_logged, :report_abuse, :send_mail] 5 before_filter :store_location, :only => [:join, :join_not_logged, :report_abuse, :send_mail]
6 - before_filter :login_required, :only => [:add, :join, :join_not_logged, :leave, :unblock, :leave_scrap, :remove_scrap, :remove_activity, :view_more_activities, :view_more_network_activities, :report_abuse, :register_report, :leave_comment_on_activity, :send_mail] 6 + before_filter :login_required, :only => [:add, :join, :leave, :unblock, :leave_scrap, :remove_scrap, :remove_activity, :view_more_activities, :view_more_network_activities, :report_abuse, :register_report, :leave_comment_on_activity, :send_mail]
7 7
8 helper TagsHelper 8 helper TagsHelper
9 9
@@ -97,21 +97,12 @@ class ProfileController < PublicController @@ -97,21 +97,12 @@ class ProfileController < PublicController
97 end 97 end
98 98
99 def join_not_logged 99 def join_not_logged
100 - if request.post?  
101 - profile.add_member(user)  
102 - session[:notice] = _('%s administrator still needs to accept you as member.') % profile.name if profile.closed?  
103 - redirect_to_previous_location 100 + session[:join] = profile.identifier
  101 +
  102 + if user
  103 + redirect_to :controller => 'profile', :action => 'join'
104 else 104 else
105 - if user.memberships.include?(profile)  
106 - session[:notice] = _('You are already a member of %s.') % profile.name  
107 - redirect_to profile.url  
108 - return  
109 - end  
110 - if request.xhr?  
111 - render :layout => false  
112 - else  
113 - redirect_to profile.url  
114 - end 105 + redirect_to :controller => '/account', :action => 'login'
115 end 106 end
116 end 107 end
117 108
app/models/user.rb
@@ -50,6 +50,9 @@ class User < ActiveRecord::Base @@ -50,6 +50,9 @@ class User < ActiveRecord::Base
50 self.person.preferred_domain && self.person.preferred_domain.name || self.environment.default_hostname(true) 50 self.person.preferred_domain && self.person.preferred_domain.name || self.environment.default_hostname(true)
51 end 51 end
52 52
  53 + # virtual attribute used to stash which community to join on signup or login
  54 + attr_accessor :community_to_join
  55 +
53 class Mailer < ActionMailer::Base 56 class Mailer < ActionMailer::Base
54 def activation_email_notify(user) 57 def activation_email_notify(user)
55 user_email = "#{user.login}@#{user.email_domain}" 58 user_email = "#{user.login}@#{user.email_domain}"
@@ -72,7 +75,8 @@ class User &lt; ActiveRecord::Base @@ -72,7 +75,8 @@ class User &lt; ActiveRecord::Base
72 :activation_code => user.activation_code, 75 :activation_code => user.activation_code,
73 :environment => user.environment.name, 76 :environment => user.environment.name,
74 :url => user.environment.top_url, 77 :url => user.environment.top_url,
75 - :redirection => (true if user.return_to) 78 + :redirection => (true if user.return_to),
  79 + :join => (user.community_to_join if user.community_to_join)
76 end 80 end
77 81
78 def signup_welcome_email(user) 82 def signup_welcome_email(user)
app/views/user/mailer/activation_code.rhtml
1 <%= _('Hi, %{recipient}!') % { :recipient => @recipient } %> 1 <%= _('Hi, %{recipient}!') % { :recipient => @recipient } %>
2 2
3 -<%= word_wrap(_('Welcome to %{environment}! To activate your account, follow the link: %{activation_url}') % { :environment => @environment, :activation_url => @url + url_for(:controller => :account, :action => :activate, :activation_code => @activation_code, :redirection => @redirection) }) %> 3 +<%= word_wrap(_('Welcome to %{environment}! To activate your account, follow the link: %{activation_url}') % { :environment => @environment, :activation_url => @url + url_for(:controller => :account, :action => :activate, :activation_code => @activation_code, :redirection => @redirection, :join => @join) }) %>
4 4
5 <%= _("Greetings,") %> 5 <%= _("Greetings,") %>
6 6
features/login.feature
@@ -207,3 +207,18 @@ Feature: login @@ -207,3 +207,18 @@ Feature: login
207 | Password | 123456 | 207 | Password | 123456 |
208 When I press "Log in" 208 When I press "Log in"
209 Then I should be on joaosilva's control panel 209 Then I should be on joaosilva's control panel
  210 +
  211 + Scenario: join community on login
  212 + Given the following users
  213 + | login | name |
  214 + | mariasilva | Maria Silva |
  215 + And the following communities
  216 + | name | identifier | owner |
  217 + | Free Software | freesoftware | mariasilva |
  218 + And I am on /freesoftware
  219 + When I follow "Join"
  220 + And I fill in the following:
  221 + | Username / Email | joaosilva |
  222 + | Password | 123456 |
  223 + And I press "Log in"
  224 + Then "Joao Silva" should be a member of "Free Software"
features/signup.feature
@@ -250,3 +250,51 @@ Feature: signup @@ -250,3 +250,51 @@ Feature: signup
250 And I fill in "Password" with "secret" 250 And I fill in "Password" with "secret"
251 And I press "Log in" 251 And I press "Log in"
252 Then I should be on the homepage 252 Then I should be on the homepage
  253 +
  254 + @selenium
  255 + Scenario: join community on signup
  256 + Given the following users
  257 + | login | name |
  258 + | mariasilva | Maria Silva |
  259 + And the following communities
  260 + | name | identifier | owner |
  261 + | Free Software | freesoftware | mariasilva |
  262 + And feature "skip_new_user_email_confirmation" is disabled on environment
  263 + And I am on /freesoftware
  264 + When I follow "Join"
  265 + And I follow "New user"
  266 + And I fill in the following within ".no-boxes":
  267 + | e-Mail | josesilva@example.com |
  268 + | Username | josesilva |
  269 + | Password | secret |
  270 + | Password confirmation | secret |
  271 + | Full name | José da Silva |
  272 + And wait for the captcha signup time
  273 + And I press "Create my account"
  274 + And I go to josesilva's confirmation URL
  275 + And I fill in "Username" with "josesilva"
  276 + And I fill in "Password" with "secret"
  277 + And I press "Log in"
  278 + Then "José da Silva" should be a member of "Free Software"
  279 +
  280 + @selenium
  281 + Scenario: join community on direct signup
  282 + Given the following users
  283 + | login | name |
  284 + | mariasilva | Maria Silva |
  285 + And the following communities
  286 + | name | identifier | owner |
  287 + | Free Software | freesoftware | mariasilva |
  288 + And feature "skip_new_user_email_confirmation" is enabled on environment
  289 + And I am on /freesoftware
  290 + When I follow "Join"
  291 + And I follow "New user"
  292 + And I fill in the following within ".no-boxes":
  293 + | e-Mail | josesilva@example.com |
  294 + | Username | josesilva |
  295 + | Password | secret |
  296 + | Password confirmation | secret |
  297 + | Full name | José da Silva |
  298 + And wait for the captcha signup time
  299 + And I press "Create my account"
  300 + Then "José da Silva" should be a member of "Free Software"