Commit 81d272c3bbe984e2b5c2e9b66a67b445342f666a
Exists in
theme-brasil-digital-from-staging
and in
9 other branches
Merge branch 'rails3' of gitlab.com:participa/noosfero into rails3
Showing
12 changed files
with
124 additions
and
64 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/content_viewer/_article_toolbar.html.erb
| ... | ... | @@ -10,7 +10,7 @@ |
| 10 | 10 | |
| 11 | 11 | <% if @page != profile.home_page && !@page.has_posts? && @page.allow_delete?(user) && !remove_content_button(:delete)%> |
| 12 | 12 | <% content = content_tag( 'span', _('Delete') ) %> |
| 13 | - <% url = profile.admin_url.merge({ :controller => 'cms', :action => 'destroy', :id => @page}) %> | |
| 13 | + <% url = profile.admin_url.merge({ :controller => 'cms', :action => 'destroy', :id => @page.id}) %> | |
| 14 | 14 | <% options = {:method => :post, :confirm => delete_article_message(@page)} %> |
| 15 | 15 | <%= expirable_button @page, :delete, content, url, options %> |
| 16 | 16 | <% end %> |
| ... | ... | @@ -19,9 +19,9 @@ |
| 19 | 19 | <% content = content_tag( 'span', _('Spread this') ) %> |
| 20 | 20 | <% url = nil %> |
| 21 | 21 | <% if profile.kind_of?(Person) %> |
| 22 | - <% url = profile.admin_url.merge({ :controller => 'cms', :action => 'publish', :id => @page }) %> | |
| 22 | + <% url = profile.admin_url.merge({ :controller => 'cms', :action => 'publish', :id => @page.id }) %> | |
| 23 | 23 | <% elsif profile.kind_of?(Community) && environment.portal_community %> |
| 24 | - <% url = profile.admin_url.merge({ :controller => 'cms', :action => 'publish_on_portal_community', :id => @page }) %> | |
| 24 | + <% url = profile.admin_url.merge({ :controller => 'cms', :action => 'publish_on_portal_community', :id => @page.id }) %> | |
| 25 | 25 | <% end %> |
| 26 | 26 | <%= expirable_button @page, :spread, content, url if url %> |
| 27 | 27 | <% end %> | ... | ... |
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/edit_profile.feature
| ... | ... | @@ -12,7 +12,7 @@ Feature: edit profile |
| 12 | 12 | | birth_date | |
| 13 | 13 | When I go to joao's control panel |
| 14 | 14 | And I follow "Edit Profile" |
| 15 | - And I select "1980-11-15" from "profile_data_birth_date" | |
| 15 | + And I fill in "Birth date" with "1980-11-15" | |
| 16 | 16 | And I press "Save" |
| 17 | 17 | Then I should not see "Birth date is invalid" |
| 18 | 18 | And I should not see "Birth date is mandatory" |
| ... | ... | @@ -23,7 +23,7 @@ Feature: edit profile |
| 23 | 23 | | birth_date | |
| 24 | 24 | When I go to joao's control panel |
| 25 | 25 | And I follow "Edit Profile" |
| 26 | - And I select "1980-11-15" from "profile_data_birth_date" | |
| 26 | + And I fill in "Birth date" with "1980-11-15" | |
| 27 | 27 | And I press "Save" |
| 28 | 28 | Then I should not see "Birth date is invalid" |
| 29 | 29 | And I should not see "Birth date is mandatory" | ... | ... |
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/profile_domain.feature
| ... | ... | @@ -9,11 +9,11 @@ Feature: domain for profile |
| 9 | 9 | | joaosilva | Joao Silva | |
| 10 | 10 | And the following communities |
| 11 | 11 | | identifier | name | domain | |
| 12 | - | sample-community | Sample Community | localhost | | |
| 12 | + | sample-community | Sample Community | 127.0.0.1 | | |
| 13 | 13 | And the following blocks |
| 14 | 14 | | owner | type | |
| 15 | 15 | | joaosilva | ProfileInfoBlock | |
| 16 | - And the environment domain is "127.0.0.1" | |
| 16 | + And the environment domain is "localhost" | |
| 17 | 17 | And "Joao Silva" is environment admin |
| 18 | 18 | And "Joao Silva" is admin of "Sample Community" |
| 19 | 19 | |
| ... | ... | @@ -29,8 +29,7 @@ Feature: domain for profile |
| 29 | 29 | @selenium |
| 30 | 30 | Scenario: access user control panel |
| 31 | 31 | Given I am logged in as "joaosilva" |
| 32 | - When I go to the homepage | |
| 33 | - And I follow "joaosilva" | |
| 32 | + When I follow "joaosilva" | |
| 34 | 33 | And I go to sample-community's homepage |
| 35 | 34 | And I follow "Login" |
| 36 | 35 | And I fill in "joaosilva" for "Username" |
| ... | ... | @@ -39,18 +38,13 @@ Feature: domain for profile |
| 39 | 38 | And I follow "Control panel" within "div#user" |
| 40 | 39 | Then I should see "Joao Silva" within "span.control-panel-title" |
| 41 | 40 | |
| 42 | - # Looking for page title is problematic on selenium since it considers the | |
| 43 | - # title to be invibible. Checkout some information about this: | |
| 44 | - # * https://github.com/jnicklas/capybara/issues/863 | |
| 45 | - # * https://github.com/jnicklas/capybara/pull/953 | |
| 46 | 41 | @selenium |
| 47 | 42 | Scenario: access user page |
| 48 | 43 | Given I am logged in as "joaosilva" |
| 49 | - When I go to the homepage | |
| 50 | - And I follow "joaosilva" | |
| 44 | + When I follow "joaosilva" | |
| 51 | 45 | Then I should be on joaosilva's profile |
| 52 | 46 | And I should see "Joao Silva" within any "h1" |
| 53 | - #And the page title should be "Joao Silva" | |
| 47 | + And the page title should be "Joao Silva" | |
| 54 | 48 | |
| 55 | 49 | Scenario: access community by domain |
| 56 | 50 | Given I go to the search communities page |
| ... | ... | @@ -64,7 +58,7 @@ Feature: domain for profile |
| 64 | 58 | Given I am on sample-community's homepage |
| 65 | 59 | When I go to /something-that-does-not-exist |
| 66 | 60 | And I follow "Go to the home page" |
| 67 | - Then the page title should be "Sample Community - Colivre.net" | |
| 61 | + Then the page title should be "Sample Community" | |
| 68 | 62 | |
| 69 | 63 | Scenario: Go to environment homepage after clicking on home button on not found page |
| 70 | 64 | Given I am on the homepage |
| ... | ... | @@ -72,8 +66,3 @@ Feature: domain for profile |
| 72 | 66 | And I follow "Go to the home page" |
| 73 | 67 | Then I should be on the homepage |
| 74 | 68 | And the page title should be "Colivre.net" |
| 75 | - | |
| 76 | - @selenium | |
| 77 | - Scenario: Compose link to administration with environment domain | |
| 78 | - Given I am logged in as "joaosilva" | |
| 79 | - Then I should see "Administration" linking to "http://127.0.0.1.*/admin" | ... | ... |
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" | ... | ... |
features/step_definitions/web_steps.rb
| ... | ... | @@ -118,9 +118,9 @@ end |
| 118 | 118 | |
| 119 | 119 | Then /^(?:|I )should see "([^"]*)" within any "([^"]*)"?$/ do |text, selector| |
| 120 | 120 | if page.respond_to? :should |
| 121 | - page.should have_css(selector, :content => text) | |
| 121 | + page.should have_css(selector, :text => text) | |
| 122 | 122 | else |
| 123 | - assert page.has_css?(selector, :content => text) | |
| 123 | + assert page.has_css?(selector, :text => text) | |
| 124 | 124 | end |
| 125 | 125 | end |
| 126 | 126 | ... | ... |
plugins/video/lib/video_block.rb
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') | ... | ... |