Commit b207e83451642268b0fe51b402803a169bd92268
Exists in
master
and in
22 other branches
Merge branch 'rails235'
Showing
7 changed files
with
109 additions
and
40 deletions
Show diff stats
app/controllers/public/account_controller.rb
| ... | ... | @@ -17,6 +17,8 @@ class AccountController < ApplicationController |
| 17 | 17 | @user = User.find_by_activation_code(params[:activation_code]) if params[:activation_code] |
| 18 | 18 | if @user and @user.activate |
| 19 | 19 | @message = _("Your account has been activated, now you can log in!") |
| 20 | + check_redirection | |
| 21 | + session[:join] = params[:join] unless params[:join].blank? | |
| 20 | 22 | render :action => 'login', :userlogin => @user.login |
| 21 | 23 | else |
| 22 | 24 | session[:notice] = _("It looks like you're trying to activate an account. Perhaps have already activated this account?") |
| ... | ... | @@ -35,6 +37,7 @@ class AccountController < ApplicationController |
| 35 | 37 | self.current_user ||= User.authenticate(params[:user][:login], params[:user][:password], environment) if params[:user] |
| 36 | 38 | |
| 37 | 39 | if logged_in? |
| 40 | + check_join_in_community(self.current_user) | |
| 38 | 41 | if params[:remember_me] == "1" |
| 39 | 42 | self.current_user.remember_me |
| 40 | 43 | cookies[:auth_token] = { :value => self.current_user.remember_token , :expires => self.current_user.remember_token_expires_at } |
| ... | ... | @@ -91,6 +94,7 @@ class AccountController < ApplicationController |
| 91 | 94 | if session[:may_be_a_bot] |
| 92 | 95 | return false unless verify_recaptcha :model=>@user, :message=>_('Captcha (the human test)') |
| 93 | 96 | end |
| 97 | + @user.community_to_join = session[:join] | |
| 94 | 98 | @user.signup! |
| 95 | 99 | owner_role = Role.find_by_name('owner') |
| 96 | 100 | @user.person.affiliate(@user.person, [owner_role]) if owner_role |
| ... | ... | @@ -101,6 +105,7 @@ class AccountController < ApplicationController |
| 101 | 105 | end |
| 102 | 106 | if @user.activated? |
| 103 | 107 | self.current_user = @user |
| 108 | + check_join_in_community(@user) | |
| 104 | 109 | go_to_signup_initial_page |
| 105 | 110 | else |
| 106 | 111 | @register_pending = true |
| ... | ... | @@ -388,12 +393,6 @@ class AccountController < ApplicationController |
| 388 | 393 | end |
| 389 | 394 | |
| 390 | 395 | def go_to_initial_page |
| 391 | - if params[:redirection] | |
| 392 | - session[:return_to] = @user.return_to | |
| 393 | - @user.return_to = nil | |
| 394 | - @user.save | |
| 395 | - end | |
| 396 | - | |
| 397 | 396 | if params[:return_to] |
| 398 | 397 | redirect_to params[:return_to] |
| 399 | 398 | elsif environment.enabled?('allow_change_of_redirection_after_login') |
| ... | ... | @@ -444,4 +443,19 @@ class AccountController < ApplicationController |
| 444 | 443 | redirect_back_or_default(default) |
| 445 | 444 | end |
| 446 | 445 | end |
| 446 | + | |
| 447 | + def check_redirection | |
| 448 | + unless params[:redirection].blank? | |
| 449 | + session[:return_to] = @user.return_to | |
| 450 | + @user.update_attributes(:return_to => nil) | |
| 451 | + end | |
| 452 | + end | |
| 453 | + | |
| 454 | + def check_join_in_community(user) | |
| 455 | + profile_to_join = session[:join] | |
| 456 | + unless profile_to_join.blank? | |
| 457 | + environment.profiles.find_by_identifier(profile_to_join).add_member(user.person) | |
| 458 | + session.delete(:join) | |
| 459 | + end | |
| 460 | + end | |
| 447 | 461 | end | ... | ... |
app/controllers/public/profile_controller.rb
| ... | ... | @@ -3,7 +3,7 @@ class ProfileController < PublicController |
| 3 | 3 | needs_profile |
| 4 | 4 | before_filter :check_access_to_profile, :except => [:join, :join_not_logged, :index, :add] |
| 5 | 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 | 8 | helper TagsHelper |
| 9 | 9 | |
| ... | ... | @@ -97,21 +97,12 @@ class ProfileController < PublicController |
| 97 | 97 | end |
| 98 | 98 | |
| 99 | 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 | 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 | 106 | end |
| 116 | 107 | end |
| 117 | 108 | ... | ... |
app/models/user.rb
| ... | ... | @@ -63,6 +63,9 @@ class User < ActiveRecord::Base |
| 63 | 63 | self.person.preferred_domain && self.person.preferred_domain.name || self.environment.default_hostname(true) |
| 64 | 64 | end |
| 65 | 65 | |
| 66 | + # virtual attribute used to stash which community to join on signup or login | |
| 67 | + attr_accessor :community_to_join | |
| 68 | + | |
| 66 | 69 | class Mailer < ActionMailer::Base |
| 67 | 70 | def activation_email_notify(user) |
| 68 | 71 | user_email = "#{user.login}@#{user.email_domain}" |
| ... | ... | @@ -85,7 +88,8 @@ class User < ActiveRecord::Base |
| 85 | 88 | :activation_code => user.activation_code, |
| 86 | 89 | :environment => user.environment.name, |
| 87 | 90 | :url => user.environment.top_url, |
| 88 | - :redirection => (true if user.return_to) | |
| 91 | + :redirection => (true if user.return_to), | |
| 92 | + :join => (user.community_to_join if user.community_to_join) | |
| 89 | 93 | end |
| 90 | 94 | |
| 91 | 95 | def signup_welcome_email(user) | ... | ... |
app/views/user/mailer/activation_code.html.erb
| 1 | 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 | 5 | <%= _("Greetings,") %> |
| 6 | 6 | ... | ... |
features/login.feature
| ... | ... | @@ -207,3 +207,18 @@ Feature: login |
| 207 | 207 | | Password | 123456 | |
| 208 | 208 | When I press "Log in" |
| 209 | 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 | 250 | And I fill in "Password" with "secret" |
| 251 | 251 | And I press "Log in" |
| 252 | 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" | ... | ... |
test/functional/profile_controller_test.rb
| ... | ... | @@ -474,17 +474,23 @@ class ProfileControllerTest < ActionController::TestCase |
| 474 | 474 | assert_equal "/profile/#{community.identifier}", @request.session[:previous_location] |
| 475 | 475 | end |
| 476 | 476 | |
| 477 | - should 'redirect to location before login after join community' do | |
| 477 | + should 'redirect to login after user not logged asks to join a community' do | |
| 478 | 478 | community = Community.create!(:name => 'my test community') |
| 479 | 479 | |
| 480 | - @request.expects(:referer).returns("/profile/#{community.identifier}/to_go") | |
| 481 | - login_as(profile.identifier) | |
| 480 | + get :join_not_logged, :profile => community.identifier | |
| 482 | 481 | |
| 483 | - post :join_not_logged, :profile => community.identifier | |
| 482 | + assert_equal community.identifier, @request.session[:join] | |
| 483 | + assert_redirected_to :controller => :account, :action => :login | |
| 484 | + end | |
| 484 | 485 | |
| 485 | - assert_redirected_to "/profile/#{community.identifier}/to_go" | |
| 486 | + should 'redirect to join after user logged asks to join_not_logged a community' do | |
| 487 | + community = Community.create!(:name => 'my test community') | |
| 488 | + | |
| 489 | + login_as(profile.identifier) | |
| 490 | + get :join_not_logged, :profile => community.identifier | |
| 486 | 491 | |
| 487 | - assert_nil @request.session[:previous_location] | |
| 492 | + assert_equal community.identifier, @request.session[:join] | |
| 493 | + assert_redirected_to :controller => :profile, :action => :join | |
| 488 | 494 | end |
| 489 | 495 | |
| 490 | 496 | should 'show number of published events in index' do |
| ... | ... | @@ -1186,7 +1192,7 @@ class ProfileControllerTest < ActionController::TestCase |
| 1186 | 1192 | 20.times {comment = fast_create(Comment, :source_id => article, :title => 'a comment', :body => 'lalala', :created_at => Time.now)} |
| 1187 | 1193 | article.reload |
| 1188 | 1194 | get :index, :profile => profile.identifier |
| 1189 | - assert_tag 'ul', :attributes => {:class => 'profile-wall-activities-comments'}, :children => {:count => 0 } | |
| 1195 | + assert_tag 'ul', :attributes => {:class => 'profile-wall-activities-comments'}, :children => {:count => 0 } | |
| 1190 | 1196 | end |
| 1191 | 1197 | |
| 1192 | 1198 | should "view more comments paginated" do |
| ... | ... | @@ -1212,7 +1218,7 @@ class ProfileControllerTest < ActionController::TestCase |
| 1212 | 1218 | 20.times {fast_create(Scrap, :sender_id => profile.id, :receiver_id => profile.id, :scrap_id => scrap.id)} |
| 1213 | 1219 | profile.reload |
| 1214 | 1220 | get :index, :profile => profile.identifier |
| 1215 | - assert_tag 'ul', :attributes => {:class => 'profile-wall-activities-comments scrap-replies'}, :children => {:count => 0 } | |
| 1221 | + assert_tag 'ul', :attributes => {:class => 'profile-wall-activities-comments scrap-replies'}, :children => {:count => 0 } | |
| 1216 | 1222 | end |
| 1217 | 1223 | |
| 1218 | 1224 | should "view more replies paginated" do |
| ... | ... | @@ -1269,15 +1275,6 @@ class ProfileControllerTest < ActionController::TestCase |
| 1269 | 1275 | assert_tag :tag => 'div', :content => /#{instance_eval(&plugin2.profile_tabs[:content])}/, :attributes => {:id => /#{plugin2.profile_tabs[:id]}/} |
| 1270 | 1276 | end |
| 1271 | 1277 | |
| 1272 | - should 'redirect to profile page when try to request join_not_logged via GET method' do | |
| 1273 | - community = Community.create!(:name => 'my test community') | |
| 1274 | - login_as(profile.identifier) | |
| 1275 | - get :join_not_logged, :profile => community.identifier | |
| 1276 | - assert_nothing_raised do | |
| 1277 | - assert_redirected_to community.url | |
| 1278 | - end | |
| 1279 | - end | |
| 1280 | - | |
| 1281 | 1278 | should 'check different profile from the domain profile' do |
| 1282 | 1279 | default = Environment.default |
| 1283 | 1280 | default.domains.create!(:name => 'environment.com') | ... | ... |