Commit 6a3caadded3cb3c8b3fd1ee2cd4772ed73274dac
Committed by
Gabriela Navarro
1 parent
e5d9ef3a
Exists in
master
and in
28 other branches
sort_members: sort community members alphabetically in manage members and view all page
(ActionItem2909) Signed-off-by: Alex Campelo <campelo.al1@gmail.com> Signed-off-by: Arthur Del Esposte <arthurmde@gmail.com> SIgned-off-by: Gabriela Navarro <navarro1703@gmail.com>
Showing
5 changed files
with
31 additions
and
3 deletions
Show diff stats
app/controllers/my_profile/profile_members_controller.rb
@@ -2,7 +2,7 @@ class ProfileMembersController < MyProfileController | @@ -2,7 +2,7 @@ class ProfileMembersController < MyProfileController | ||
2 | protect 'manage_memberships', :profile | 2 | protect 'manage_memberships', :profile |
3 | 3 | ||
4 | def index | 4 | def index |
5 | - @members = profile.members | 5 | + @members = profile.members_by_name |
6 | @member_role = environment.roles.find_by_name('member') | 6 | @member_role = environment.roles.find_by_name('member') |
7 | end | 7 | end |
8 | 8 |
app/controllers/public/profile_controller.rb
@@ -67,7 +67,7 @@ class ProfileController < PublicController | @@ -67,7 +67,7 @@ class ProfileController < PublicController | ||
67 | 67 | ||
68 | def members | 68 | def members |
69 | if is_cache_expired?(profile.members_cache_key(params)) | 69 | if is_cache_expired?(profile.members_cache_key(params)) |
70 | - @members = profile.members.includes(relations_to_include).paginate(:per_page => members_per_page, :page => params[:npage]) | 70 | + @members = profile.members_by_name.includes(relations_to_include).paginate(:per_page => members_per_page, :page => params[:npage]) |
71 | end | 71 | end |
72 | end | 72 | end |
73 | 73 |
app/models/profile.rb
@@ -87,6 +87,10 @@ class Profile < ActiveRecord::Base | @@ -87,6 +87,10 @@ class Profile < ActiveRecord::Base | ||
87 | scopes.size == 1 ? scopes.first : Person.or_scope(scopes) | 87 | scopes.size == 1 ? scopes.first : Person.or_scope(scopes) |
88 | end | 88 | end |
89 | 89 | ||
90 | + def members_by_name | ||
91 | + members.order(:name) | ||
92 | + end | ||
93 | + | ||
90 | def members_count | 94 | def members_count |
91 | members.count | 95 | members.count |
92 | end | 96 | end |
app/views/profile_members/_members_list.rhtml
1 | -<% collection = @collection == :profile_admins ? profile.admins : profile.members %> | 1 | +<% collection = @collection == :profile_admins ? profile.admins : profile.members_by_name %> |
2 | <% title = @title ? @title : _('Current members') %> | 2 | <% title = @title ? @title : _('Current members') %> |
3 | <% remove_action = @remove_action ? @remove_action : {:action => 'unassociate'} %> | 3 | <% remove_action = @remove_action ? @remove_action : {:action => 'unassociate'} %> |
4 | 4 |
test/unit/profile_test.rb
@@ -1692,6 +1692,30 @@ class ProfileTest < ActiveSupport::TestCase | @@ -1692,6 +1692,30 @@ class ProfileTest < ActiveSupport::TestCase | ||
1692 | assert_equal 1, community.members_count | 1692 | assert_equal 1, community.members_count |
1693 | end | 1693 | end |
1694 | 1694 | ||
1695 | + should 'order members by name alphabetically considering special characters' do | ||
1696 | + community = fast_create(Community) | ||
1697 | + | ||
1698 | + community.add_member(create_user('José').person) | ||
1699 | + community.add_member(create_user('João').person) | ||
1700 | + community.add_member(create_user('Mariana').person) | ||
1701 | + members = community.members_by_name | ||
1702 | + | ||
1703 | + assert_equal "João", members.first.name | ||
1704 | + assert_equal "Mariana", members.last.name | ||
1705 | + end | ||
1706 | + | ||
1707 | + should 'order members by name alphabetically considering upper and lower cases' do | ||
1708 | + community = fast_create(Community) | ||
1709 | + | ||
1710 | + community.add_member(create_user('mariana').person) | ||
1711 | + community.add_member(create_user('João').person) | ||
1712 | + community.add_member(create_user('guest').person) | ||
1713 | + members = community.members_by_name | ||
1714 | + | ||
1715 | + assert_equal "guest", members.first.name | ||
1716 | + assert_equal "mariana", members.last.name | ||
1717 | + end | ||
1718 | + | ||
1695 | should 'know if url is the profile homepage' do | 1719 | should 'know if url is the profile homepage' do |
1696 | profile = fast_create(Profile) | 1720 | profile = fast_create(Profile) |
1697 | 1721 |