Commit 02903b02b2290e7a7af8fb0fd253fc4dbe1465ad

Authored by Leandro Santos
2 parents f16ec7f4 0595bfe6
Exists in fix_sign_up_form

Merge branch 'fix_task_list' into 'master'

Limit task list in profile editor



See merge request !998
app/controllers/my_profile/profile_editor_controller.rb
@@ -12,7 +12,7 @@ class ProfileEditorController < MyProfileController @@ -12,7 +12,7 @@ class ProfileEditorController < MyProfileController
12 include CategoriesHelper 12 include CategoriesHelper
13 13
14 def index 14 def index
15 - @pending_tasks = Task.to(profile).pending.without_spam.select{|i| user.has_permission?(i.permission, profile)} 15 + @pending_tasks = Task.to(profile).pending.without_spam
16 @show_appearance_option = user.is_admin?(environment) || environment.enabled?('enable_appearance') 16 @show_appearance_option = user.is_admin?(environment) || environment.enabled?('enable_appearance')
17 @show_header_footer_option = user.is_admin?(environment) || (!profile.enterprise? && !environment.enabled?('disable_header_and_footer')) 17 @show_header_footer_option = user.is_admin?(environment) || (!profile.enterprise? && !environment.enabled?('disable_header_and_footer'))
18 end 18 end
app/views/profile_editor/_pending_tasks.html.erb
@@ -2,9 +2,9 @@ @@ -2,9 +2,9 @@
2 2
3 <% unless @pending_tasks.empty? %> 3 <% unless @pending_tasks.empty? %>
4 <div class='pending-tasks'> 4 <div class='pending-tasks'>
5 - <h2><%= _('You have pending requests') %></h2> 5 + <h2><%= _('You have %s pending requests' % @pending_tasks.count) %></h2>
6 <ul> 6 <ul>
7 - <%= safe_join(@pending_tasks.map {|task| content_tag('li', task_information(task).html_safe)}) %> 7 + <%= safe_join(@pending_tasks.limit(5).map {|task| content_tag('li', task_information(task).html_safe)}) %>
8 </ul> 8 </ul>
9 <%= button(:todo, _('Process requests'), :controller => 'tasks', :action => 'index') %> 9 <%= button(:todo, _('Process requests'), :controller => 'tasks', :action => 'index') %>
10 </div> 10 </div>
test/functional/profile_editor_controller_test.rb
@@ -391,8 +391,6 @@ class ProfileEditorControllerTest &lt; ActionController::TestCase @@ -391,8 +391,6 @@ class ProfileEditorControllerTest &lt; ActionController::TestCase
391 user2 = create_user('usertwo').person 391 user2 = create_user('usertwo').person
392 AddFriend.create!(:person => user1, :friend => user2) 392 AddFriend.create!(:person => user1, :friend => user2)
393 @controller.stubs(:user).returns(user2) 393 @controller.stubs(:user).returns(user2)
394 - user2.stubs(:has_permission?).with('edit_profile', anything).returns(true)  
395 - user2.expects(:has_permission?).with(:manage_friends, anything).returns(true)  
396 login_as('usertwo') 394 login_as('usertwo')
397 get :index, :profile => 'usertwo' 395 get :index, :profile => 'usertwo'
398 assert_tag :tag => 'div', :attributes => { :class => 'pending-tasks' } 396 assert_tag :tag => 'div', :attributes => { :class => 'pending-tasks' }
@@ -400,16 +398,34 @@ class ProfileEditorControllerTest &lt; ActionController::TestCase @@ -400,16 +398,34 @@ class ProfileEditorControllerTest &lt; ActionController::TestCase
400 398
401 should 'not show task if user has no permission' do 399 should 'not show task if user has no permission' do
402 user1 = profile 400 user1 = profile
  401 + community = fast_create(Community)
403 user2 = create_user('usertwo').person 402 user2 = create_user('usertwo').person
404 - task = AddFriend.create!(:person => user1, :friend => user2) 403 + task = AddMember.create!(person: user1, organization: community)
405 @controller.stubs(:user).returns(user2) 404 @controller.stubs(:user).returns(user2)
406 - user2.stubs(:has_permission?).with('edit_profile', anything).returns(true)  
407 - user2.expects(:has_permission?).with(:manage_friends, anything).returns(false) 405 + give_permission(user2, 'invite_members', community)
408 login_as('usertwo') 406 login_as('usertwo')
409 get :index, :profile => 'usertwo' 407 get :index, :profile => 'usertwo'
410 assert_no_tag :tag => 'div', :attributes => { :class => 'pending-tasks' } 408 assert_no_tag :tag => 'div', :attributes => { :class => 'pending-tasks' }
411 end 409 end
412 410
  411 + should 'limit task list' do
  412 + user2 = create_user('usertwo').person
  413 + 6.times { AddFriend.create!(:person => create_user.person, :friend => user2) }
  414 + login_as('usertwo')
  415 + get :index, :profile => 'usertwo'
  416 + assert_select '.pending-tasks > ul > li', 5
  417 + end
  418 +
  419 + should 'display task count in task list' do
  420 + user2 = create_user('usertwo').person
  421 + 6.times { AddFriend.create!(:person => create_user.person, :friend => user2) }
  422 + login_as('usertwo')
  423 + get :index, :profile => 'usertwo'
  424 + assert_select '.pending-tasks h2' do |elements|
  425 + assert_match /6/, elements.first.content
  426 + end
  427 + end
  428 +
413 should 'show favorite enterprises button for person' do 429 should 'show favorite enterprises button for person' do
414 get :index, :profile => profile.identifier 430 get :index, :profile => profile.identifier
415 assert_tag :tag => 'a', :content => 'Favorite Enterprises' 431 assert_tag :tag => 'a', :content => 'Favorite Enterprises'