mirror of
https://github.com/discourse/discourse.git
synced 2025-04-03 05:39:41 +08:00
use limit & offset for pagination of group members
This commit is contained in:
parent
d3510bff04
commit
adb570fe53
@ -18,8 +18,11 @@ class GroupsController < ApplicationController
|
|||||||
|
|
||||||
def members
|
def members
|
||||||
group = find_group(:group_id)
|
group = find_group(:group_id)
|
||||||
members = group.users.order('username_lower asc')
|
|
||||||
members = members.limit(200) if group.automatic
|
limit = (params[:limit] || 200).to_i
|
||||||
|
offset = (params[:offset] || 0).to_i
|
||||||
|
members = group.users.order('username_lower asc').limit(limit).offset(offset)
|
||||||
|
|
||||||
render_serialized(members.to_a, GroupUserSerializer)
|
render_serialized(members.to_a, GroupUserSerializer)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -67,5 +67,19 @@ describe GroupsController do
|
|||||||
xhr :get, :posts, group_id: group.name
|
xhr :get, :posts, group_id: group.name
|
||||||
response.should be_success
|
response.should be_success
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "ensures that membership can be paginated" do
|
||||||
|
5.times { group.add(Fabricate(:user)) }
|
||||||
|
xhr :get, :members, group_id: group.name, limit: 3
|
||||||
|
response.should be_success
|
||||||
|
members = JSON.parse(response.body)
|
||||||
|
members.count.should eq(3)
|
||||||
|
|
||||||
|
xhr :get, :members, group_id: group.name, limit: 250, offset: 250
|
||||||
|
xhr :get, :members, group_id: group.name, limit: 3, offset: 3
|
||||||
|
response.should be_success
|
||||||
|
members = JSON.parse(response.body)
|
||||||
|
members.count.should eq(2)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user