Commit 5cf4f96063d0c3a87363f02b6e6d654362933816
Committed by
Antonio Terceiro
1 parent
1cb8eaf0
Exists in
master
and in
23 other branches
Dont ask confirmation if already a member
(ActionItem1280)
Showing
5 changed files
with
32 additions
and
3 deletions
Show diff stats
app/controllers/public/content_viewer_controller.rb
| ... | ... | @@ -52,6 +52,7 @@ class ContentViewerController < ApplicationController |
| 52 | 52 | |
| 53 | 53 | # At this point the page will be showed |
| 54 | 54 | @page.hit |
| 55 | + store_location | |
| 55 | 56 | |
| 56 | 57 | unless @page.mime_type == 'text/html' || (@page.image? && params[:view]) |
| 57 | 58 | headers['Content-Type'] = @page.mime_type | ... | ... |
app/controllers/public/profile_controller.rb
| ... | ... | @@ -55,7 +55,6 @@ class ProfileController < PublicController |
| 55 | 55 | end |
| 56 | 56 | |
| 57 | 57 | def join |
| 58 | - store_location(request.referer) | |
| 59 | 58 | @wizard = params[:wizard] |
| 60 | 59 | if request.post? && params[:confirmation] |
| 61 | 60 | profile.add_member(current_user.person) |
| ... | ... | @@ -66,6 +65,12 @@ class ProfileController < PublicController |
| 66 | 65 | redirect_to_before_join |
| 67 | 66 | end |
| 68 | 67 | else |
| 68 | + store_location(request.referer) | |
| 69 | + if current_user.person.memberships.include?(profile) | |
| 70 | + flash[:notice] = _('You are already a member of "%s"') % profile.name | |
| 71 | + redirect_back_or_default profile.url | |
| 72 | + return | |
| 73 | + end | |
| 69 | 74 | if request.xhr? |
| 70 | 75 | render :layout => false |
| 71 | 76 | end | ... | ... |
features/join_community.feature
| ... | ... | @@ -59,3 +59,22 @@ Feature: join a community |
| 59 | 59 | When I press "Yes, I want to join" |
| 60 | 60 | Then I should be on Sample Community's homepage |
| 61 | 61 | And "Jose Oliveira" should be a member of "Sample Community" |
| 62 | + | |
| 63 | + Scenario: ask confirmation before join community | |
| 64 | + Given I am on the homepage | |
| 65 | + And the following communities | |
| 66 | + | name | | |
| 67 | + | Community to join | | |
| 68 | + And I am logged in as "joaosilva" | |
| 69 | + When I am on /profile/community-to-join/join | |
| 70 | + Then I should see "Are you sure you want to join Community to join" | |
| 71 | + | |
| 72 | + Scenario: dont ask confirmation before join community if already member | |
| 73 | + Given I am on the homepage | |
| 74 | + And the following communities | |
| 75 | + | name | | |
| 76 | + | Community to join | | |
| 77 | + And joaosilva is member of community-to-join | |
| 78 | + And I am logged in as "joaosilva" | |
| 79 | + When I am on /profile/community-to-join/join | |
| 80 | + Then I should not see "Are you sure you want to join Community to join" | ... | ... |
features/step_definitions/noosfero_steps.rb
| ... | ... | @@ -131,3 +131,7 @@ Then /^"([^\"]*)" should have the following data$/ do |id, table| |
| 131 | 131 | data = expected.keys.inject({}) { |hash, key| hash[key] = profile.send(key).to_s; hash } |
| 132 | 132 | data.should == expected |
| 133 | 133 | end |
| 134 | + | |
| 135 | +Given /^(.+) is member of (.+)$/ do |person, group| | |
| 136 | + Organization[group].add_member(Person[person]) | |
| 137 | +end | ... | ... |
test/functional/profile_controller_test.rb
| ... | ... | @@ -611,7 +611,7 @@ class ProfileControllerTest < Test::Unit::TestCase |
| 611 | 611 | should 'redirect to stored location after join community' do |
| 612 | 612 | community = Community.create!(:name => 'my test community') |
| 613 | 613 | |
| 614 | - @request.expects(:referer).returns("/profile/#{community.identifier}/to_go") | |
| 614 | + @request.session[:return_to] = "/profile/#{community.identifier}/to_go" | |
| 615 | 615 | login_as(profile.identifier) |
| 616 | 616 | |
| 617 | 617 | post :join, :profile => community.identifier, :confirmation => '1' |
| ... | ... | @@ -632,7 +632,7 @@ class ProfileControllerTest < Test::Unit::TestCase |
| 632 | 632 | should 'redirect to location before login after join community' do |
| 633 | 633 | community = Community.create!(:name => 'my test community') |
| 634 | 634 | |
| 635 | - @request.expects(:referer).returns("/profile/#{community.identifier}/to_go") | |
| 635 | + @request.session[:return_to] = "/profile/#{community.identifier}/to_go" | |
| 636 | 636 | login_as(profile.identifier) |
| 637 | 637 | |
| 638 | 638 | post :join, :profile => community.identifier, :confirmation => '1' | ... | ... |