Commit 02903b02b2290e7a7af8fb0fd253fc4dbe1465ad
Exists in
staging
and in
4 other branches
Merge branch 'fix_task_list' into 'master'
Limit task list in profile editor See merge request !998
Showing
3 changed files
with
24 additions
and
8 deletions
Show diff stats
app/controllers/my_profile/profile_editor_controller.rb
... | ... | @@ -12,7 +12,7 @@ class ProfileEditorController < MyProfileController |
12 | 12 | include CategoriesHelper |
13 | 13 | |
14 | 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 | 16 | @show_appearance_option = user.is_admin?(environment) || environment.enabled?('enable_appearance') |
17 | 17 | @show_header_footer_option = user.is_admin?(environment) || (!profile.enterprise? && !environment.enabled?('disable_header_and_footer')) |
18 | 18 | end | ... | ... |
app/views/profile_editor/_pending_tasks.html.erb
... | ... | @@ -2,9 +2,9 @@ |
2 | 2 | |
3 | 3 | <% unless @pending_tasks.empty? %> |
4 | 4 | <div class='pending-tasks'> |
5 | - <h2><%= _('You have pending requests') %></h2> | |
5 | + <h2><%= _('You have %s pending requests' % @pending_tasks.count) %></h2> | |
6 | 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 | 8 | </ul> |
9 | 9 | <%= button(:todo, _('Process requests'), :controller => 'tasks', :action => 'index') %> |
10 | 10 | </div> | ... | ... |
test/functional/profile_editor_controller_test.rb
... | ... | @@ -391,8 +391,6 @@ class ProfileEditorControllerTest < ActionController::TestCase |
391 | 391 | user2 = create_user('usertwo').person |
392 | 392 | AddFriend.create!(:person => user1, :friend => user2) |
393 | 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 | 394 | login_as('usertwo') |
397 | 395 | get :index, :profile => 'usertwo' |
398 | 396 | assert_tag :tag => 'div', :attributes => { :class => 'pending-tasks' } |
... | ... | @@ -400,16 +398,34 @@ class ProfileEditorControllerTest < ActionController::TestCase |
400 | 398 | |
401 | 399 | should 'not show task if user has no permission' do |
402 | 400 | user1 = profile |
401 | + community = fast_create(Community) | |
403 | 402 | user2 = create_user('usertwo').person |
404 | - task = AddFriend.create!(:person => user1, :friend => user2) | |
403 | + task = AddMember.create!(person: user1, organization: community) | |
405 | 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 | 406 | login_as('usertwo') |
409 | 407 | get :index, :profile => 'usertwo' |
410 | 408 | assert_no_tag :tag => 'div', :attributes => { :class => 'pending-tasks' } |
411 | 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 | 429 | should 'show favorite enterprises button for person' do |
414 | 430 | get :index, :profile => profile.identifier |
415 | 431 | assert_tag :tag => 'a', :content => 'Favorite Enterprises' | ... | ... |