Commit 3a4c55178821e4fa1514a0b0c20c298f9bacfe64
Exists in
master
and in
29 other branches
Merge branch 'stable'
Showing
15 changed files
with
89 additions
and
8 deletions
Show diff stats
app/controllers/public/account_controller.rb
@@ -5,6 +5,7 @@ class AccountController < ApplicationController | @@ -5,6 +5,7 @@ class AccountController < ApplicationController | ||
5 | require_ssl :except => [ :login_popup, :logout_popup, :wizard, :profile_details ] | 5 | require_ssl :except => [ :login_popup, :logout_popup, :wizard, :profile_details ] |
6 | 6 | ||
7 | before_filter :login_required, :only => [:activation_question, :accept_terms, :activate_enterprise] | 7 | before_filter :login_required, :only => [:activation_question, :accept_terms, :activate_enterprise] |
8 | + before_filter :redirect_if_logged_in, :only => [:login, :signup] | ||
8 | 9 | ||
9 | # say something nice, you goof! something sweet. | 10 | # say something nice, you goof! something sweet. |
10 | def index | 11 | def index |
@@ -291,4 +292,10 @@ class AccountController < ApplicationController | @@ -291,4 +292,10 @@ class AccountController < ApplicationController | ||
291 | end | 292 | end |
292 | end | 293 | end |
293 | 294 | ||
295 | + def redirect_if_logged_in | ||
296 | + if logged_in? | ||
297 | + go_to_initial_page | ||
298 | + end | ||
299 | + end | ||
300 | + | ||
294 | end | 301 | end |
app/controllers/public/content_viewer_controller.rb
@@ -82,7 +82,8 @@ class ContentViewerController < ApplicationController | @@ -82,7 +82,8 @@ class ContentViewerController < ApplicationController | ||
82 | end | 82 | end |
83 | 83 | ||
84 | if @page.folder? && @page.view_as == 'image_gallery' | 84 | if @page.folder? && @page.view_as == 'image_gallery' |
85 | - @images = @page.images.paginate(:per_page => 12, :page => params[:npage]) | 85 | + @images = @page.images |
86 | + @images = @images.paginate(:per_page => per_page, :page => params[:npage]) unless params[:slideshow] | ||
86 | end | 87 | end |
87 | 88 | ||
88 | @comments = @page.comments(true) | 89 | @comments = @page.comments(true) |
@@ -114,4 +115,7 @@ class ContentViewerController < ApplicationController | @@ -114,4 +115,7 @@ class ContentViewerController < ApplicationController | ||
114 | redirect_to :action => 'view_page', :profile => params[:profile], :page => @page.explode_path, :view => params[:view] | 115 | redirect_to :action => 'view_page', :profile => params[:profile], :page => @page.explode_path, :view => params[:view] |
115 | end | 116 | end |
116 | 117 | ||
118 | + def per_page | ||
119 | + 12 | ||
120 | + end | ||
117 | end | 121 | end |
app/models/add_friend.rb
@@ -6,6 +6,8 @@ class AddFriend < Task | @@ -6,6 +6,8 @@ class AddFriend < Task | ||
6 | 6 | ||
7 | validates_uniqueness_of :target_id, :scope => [ :requestor_id ] | 7 | validates_uniqueness_of :target_id, :scope => [ :requestor_id ] |
8 | 8 | ||
9 | + validates_length_of :group_for_person, :group_for_friend, :maximum => 150, :allow_nil => true | ||
10 | + | ||
9 | alias :person :requestor | 11 | alias :person :requestor |
10 | alias :person= :requestor= | 12 | alias :person= :requestor= |
11 | 13 |
app/models/task_mailer.rb
@@ -22,15 +22,15 @@ class TaskMailer < ActionMailer::Base | @@ -22,15 +22,15 @@ class TaskMailer < ActionMailer::Base | ||
22 | :target => task.target.name, | 22 | :target => task.target.name, |
23 | :message => msg, | 23 | :message => msg, |
24 | :environment => task.requestor.environment.name, | 24 | :environment => task.requestor.environment.name, |
25 | - :url => url_for(:host => task.requestor.environment.default_hostname, :controller => 'home'), | 25 | + :url => generate_environment_url(task, :controller => 'home'), |
26 | :tasks_url => url_for_tasks_list | 26 | :tasks_url => url_for_tasks_list |
27 | end | 27 | end |
28 | 28 | ||
29 | def invitation_notification(task) | 29 | def invitation_notification(task) |
30 | msg = task.message | 30 | msg = task.message |
31 | msg = msg.gsub(/<user>/, task.requestor.name) | 31 | msg = msg.gsub(/<user>/, task.requestor.name) |
32 | - msg = msg.gsub(/<friend>/, task.friend_name) | ||
33 | - msg = msg.gsub(/<url>/, url_for(:host => task.requestor.environment.default_hostname, :controller => 'account', :action => 'signup', :invitation_code => task.code)) | 32 | + msg = msg.gsub(/<friend>/, task.friend_name.blank? ? task.friend_email : task.friend_name) |
33 | + msg = msg.gsub(/<url>/, generate_environment_url(task, :controller => 'account', :action => 'signup', :invitation_code => task.code)) | ||
34 | 34 | ||
35 | recipients task.friend_email | 35 | recipients task.friend_email |
36 | 36 | ||
@@ -66,4 +66,8 @@ class TaskMailer < ActionMailer::Base | @@ -66,4 +66,8 @@ class TaskMailer < ActionMailer::Base | ||
66 | "#{task.requestor.environment.name} <#{task.requestor.environment.contact_email}>" | 66 | "#{task.requestor.environment.name} <#{task.requestor.environment.contact_email}>" |
67 | end | 67 | end |
68 | 68 | ||
69 | + def generate_environment_url(task, url = {}) | ||
70 | + url_for(Noosfero.url_options.merge(:host => task.requestor.environment.default_hostname).merge(url)) | ||
71 | + end | ||
72 | + | ||
69 | end | 73 | end |
app/views/friends/add.rhtml
@@ -15,7 +15,7 @@ | @@ -15,7 +15,7 @@ | ||
15 | 15 | ||
16 | <div> | 16 | <div> |
17 | <%= __('Classify your new friend %s: ') % @friend.name %> | 17 | <%= __('Classify your new friend %s: ') % @friend.name %> |
18 | - <%= text_field_with_local_autocomplete('group', profile.suggested_friend_groups) %> | 18 | + <%= text_field_with_local_autocomplete('group', profile.suggested_friend_groups, :maxlength => 150) %> |
19 | <p> | 19 | <p> |
20 | <%= _('Suggestions: %s') % profile.suggested_friend_groups.join(', ') %> | 20 | <%= _('Suggestions: %s') % profile.suggested_friend_groups.join(', ') %> |
21 | </p> | 21 | </p> |
app/views/tasks/_add_friend.rhtml
@@ -27,7 +27,7 @@ | @@ -27,7 +27,7 @@ | ||
27 | <%= _('Classify your new friend:') %> | 27 | <%= _('Classify your new friend:') %> |
28 | <%= text_field_with_local_autocomplete("task[group_for_friend]", | 28 | <%= text_field_with_local_autocomplete("task[group_for_friend]", |
29 | profile.suggested_friend_groups, | 29 | profile.suggested_friend_groups, |
30 | - :id => "field-group-for-friend-#{task.id}") %> | 30 | + {:id => "field-group-for-friend-#{task.id}", :maxlength => 150}) %> |
31 | <p class="friend-classify-suggestions"> | 31 | <p class="friend-classify-suggestions"> |
32 | <%= _('Suggestions: %s') % profile.suggested_friend_groups.join(', ') %> | 32 | <%= _('Suggestions: %s') % profile.suggested_friend_groups.join(', ') %> |
33 | </p> | 33 | </p> |
features/login.feature
@@ -39,3 +39,8 @@ Feature: login | @@ -39,3 +39,8 @@ Feature: login | ||
39 | | Password | 123456 | | 39 | | Password | 123456 | |
40 | When I press "Log in" | 40 | When I press "Log in" |
41 | Then I should be on Joao Silva's control panel | 41 | Then I should be on Joao Silva's control panel |
42 | + | ||
43 | + Scenario: be redirected if user goes to login page and is logged | ||
44 | + Given I am logged in as "joaosilva" | ||
45 | + And I go to login page | ||
46 | + Then I should be on Joao Silva's control panel |
features/publish_article.feature
@@ -40,6 +40,7 @@ Feature: publish article | @@ -40,6 +40,7 @@ Feature: publish article | ||
40 | And I follow "Spread" | 40 | And I follow "Spread" |
41 | And I check "Sample Community" | 41 | And I check "Sample Community" |
42 | And I press "Publish" | 42 | And I press "Publish" |
43 | + And I am not logged in | ||
43 | And I am logged in as "mariasilva" | 44 | And I am logged in as "mariasilva" |
44 | And "Maria Silva" is a member of "Sample Community" | 45 | And "Maria Silva" is a member of "Sample Community" |
45 | And I am on Maria Silva's control panel | 46 | And I am on Maria Silva's control panel |
features/signup.feature
@@ -15,3 +15,10 @@ Feature: signup | @@ -15,3 +15,10 @@ Feature: signup | ||
15 | And I press "Sign up" | 15 | And I press "Sign up" |
16 | Then I should see "Thanks for signing up!" | 16 | Then I should see "Thanks for signing up!" |
17 | 17 | ||
18 | + Scenario: be redirected if user goes to signup page and is logged | ||
19 | + Given the following users | ||
20 | + | login | name | | ||
21 | + | joaosilva | Joao Silva | | ||
22 | + Given I am logged in as "joaosilva" | ||
23 | + And I go to signup page | ||
24 | + Then I should be on Joao Silva's control panel |
features/support/paths.rb
@@ -29,6 +29,9 @@ module NavigationHelpers | @@ -29,6 +29,9 @@ module NavigationHelpers | ||
29 | when /^login page$/ | 29 | when /^login page$/ |
30 | '/account/login' | 30 | '/account/login' |
31 | 31 | ||
32 | + when /^signup page$/ | ||
33 | + '/account/signup' | ||
34 | + | ||
32 | when /^(.*)'s control panel$/ | 35 | when /^(.*)'s control panel$/ |
33 | '/myprofile/%s' % Profile.find_by_name($1).identifier | 36 | '/myprofile/%s' % Profile.find_by_name($1).identifier |
34 | 37 |
test/functional/account_controller_test.rb
@@ -36,6 +36,7 @@ class AccountControllerTest < Test::Unit::TestCase | @@ -36,6 +36,7 @@ class AccountControllerTest < Test::Unit::TestCase | ||
36 | should 'redirect to where user was on login' do | 36 | should 'redirect to where user was on login' do |
37 | @request.env["HTTP_REFERER"] = '/bli' | 37 | @request.env["HTTP_REFERER"] = '/bli' |
38 | u = new_user | 38 | u = new_user |
39 | + @controller.stubs(:logged_in?).returns(false) | ||
39 | post :login, :user => {:login => 'quire', :password => 'quire'} | 40 | post :login, :user => {:login => 'quire', :password => 'quire'} |
40 | 41 | ||
41 | assert_redirected_to '/bli' | 42 | assert_redirected_to '/bli' |
@@ -283,6 +284,7 @@ class AccountControllerTest < Test::Unit::TestCase | @@ -283,6 +284,7 @@ class AccountControllerTest < Test::Unit::TestCase | ||
283 | assert_difference User, :count do | 284 | assert_difference User, :count do |
284 | new_user(:login => 'user1', :email => 'user@example.com') | 285 | new_user(:login => 'user1', :email => 'user@example.com') |
285 | assert assigns(:user).valid? | 286 | assert assigns(:user).valid? |
287 | + @controller.stubs(:logged_in?).returns(false) | ||
286 | new_user(:login => 'user2', :email => 'user@example.com') | 288 | new_user(:login => 'user2', :email => 'user@example.com') |
287 | assert assigns(:user).errors.on(:email) | 289 | assert assigns(:user).errors.on(:email) |
288 | end | 290 | end |
test/functional/content_viewer_controller_test.rb
@@ -804,6 +804,21 @@ class ContentViewerControllerTest < Test::Unit::TestCase | @@ -804,6 +804,21 @@ class ContentViewerControllerTest < Test::Unit::TestCase | ||
804 | assert_template 'slideshow' | 804 | assert_template 'slideshow' |
805 | end | 805 | end |
806 | 806 | ||
807 | + should 'display all images from profile in the slideshow' do | ||
808 | + @controller.stubs(:per_page).returns(1) | ||
809 | + folder = Folder.create!(:name => 'gallery', :profile => profile, :view_as => 'image_gallery') | ||
810 | + | ||
811 | + fixture_filename = '/files/other-pic.jpg' | ||
812 | + filename = RAILS_ROOT + '/test/fixtures' + fixture_filename | ||
813 | + system('echo "image for test" | convert -background yellow -page 32x32 text:- %s' % filename) | ||
814 | + image1 = UploadedFile.create!(:profile => profile, :parent => folder, :uploaded_data => fixture_file_upload(fixture_filename, 'image/jpg')) | ||
815 | + | ||
816 | + image2 = UploadedFile.create!(:profile => profile, :parent => folder, :uploaded_data => fixture_file_upload('/files/rails.png', 'image/png')) | ||
817 | + get :view_page, :profile => profile.identifier, :page => folder.explode_path, :slideshow => true | ||
818 | + | ||
819 | + assert_equal 2, assigns(:images).size | ||
820 | + end | ||
821 | + | ||
807 | should 'display source from article' do | 822 | should 'display source from article' do |
808 | profile.articles << TextileArticle.new(:name => "Article one", :profile => profile, :source => 'http://www.original-source.invalid') | 823 | profile.articles << TextileArticle.new(:name => "Article one", :profile => profile, :source => 'http://www.original-source.invalid') |
809 | get :view_page, :profile => profile.identifier, :page => ['article-one'] | 824 | get :view_page, :profile => profile.identifier, :page => ['article-one'] |
test/integration/enterprise_registration_test.rb
@@ -44,10 +44,12 @@ class EnterpriseRegistrationTest < ActionController::IntegrationTest | @@ -44,10 +44,12 @@ class EnterpriseRegistrationTest < ActionController::IntegrationTest | ||
44 | 44 | ||
45 | code = CreateEnterprise.find(:first, :order => 'id desc').code | 45 | code = CreateEnterprise.find(:first, :order => 'id desc').code |
46 | 46 | ||
47 | + post '/account/logout' | ||
48 | + | ||
47 | # steps done by the validator | 49 | # steps done by the validator |
48 | validator = create_user_with_permission('validator', 'validate_enterprise', org) | 50 | validator = create_user_with_permission('validator', 'validate_enterprise', org) |
49 | login 'validator', 'validator' | 51 | login 'validator', 'validator' |
50 | - | 52 | + |
51 | get "/myprofile/myorg/enterprise_validation" | 53 | get "/myprofile/myorg/enterprise_validation" |
52 | assert_response :success | 54 | assert_response :success |
53 | assert_tag :tag => 'a', :attributes => { :href => "/myprofile/myorg/enterprise_validation/details/#{code}" } | 55 | assert_tag :tag => 'a', :attributes => { :href => "/myprofile/myorg/enterprise_validation/details/#{code}" } |
test/unit/add_friend_test.rb
@@ -100,4 +100,33 @@ class AddFriendTest < ActiveSupport::TestCase | @@ -100,4 +100,33 @@ class AddFriendTest < ActiveSupport::TestCase | ||
100 | end | 100 | end |
101 | end | 101 | end |
102 | 102 | ||
103 | + should 'limit "group for person" number of characters' do | ||
104 | + #Max value is 150 | ||
105 | + big_word = 'a' * 155 | ||
106 | + task = AddFriend.new | ||
107 | + | ||
108 | + task.group_for_person = big_word | ||
109 | + task.valid? | ||
110 | + assert task.errors[:group_for_person] | ||
111 | + | ||
112 | + task.group_for_person = 'short name' | ||
113 | + task.valid? | ||
114 | + assert !task.errors[:group_for_person] | ||
115 | + end | ||
116 | + | ||
117 | + should 'limit "group for friend" number of characters' do | ||
118 | + #Max value is 150 | ||
119 | + big_word = 'a' * 155 | ||
120 | + task = AddFriend.new | ||
121 | + | ||
122 | + task.group_for_friend = big_word | ||
123 | + task.valid? | ||
124 | + assert task.errors[:group_for_friend] | ||
125 | + | ||
126 | + task.group_for_friend = 'short name' | ||
127 | + task.valid? | ||
128 | + assert !task.errors[:group_for_friend] | ||
129 | + end | ||
130 | + | ||
131 | + | ||
103 | end | 132 | end |
test/unit/task_mailer_test.rb
@@ -113,7 +113,7 @@ class TaskMailerTest < Test::Unit::TestCase | @@ -113,7 +113,7 @@ class TaskMailerTest < Test::Unit::TestCase | ||
113 | 113 | ||
114 | task.expects(:message).returns('Hello <friend>, <user> invite you, please follow this link: <url>') | 114 | task.expects(:message).returns('Hello <friend>, <user> invite you, please follow this link: <url>') |
115 | task.expects(:friend_email).returns('friend@exemple.com') | 115 | task.expects(:friend_email).returns('friend@exemple.com') |
116 | - task.expects(:friend_name).returns('friend name') | 116 | + task.expects(:friend_name).returns('friend name').at_least_once |
117 | 117 | ||
118 | requestor = mock() | 118 | requestor = mock() |
119 | requestor.expects(:name).returns('my name') | 119 | requestor.expects(:name).returns('my name') |