mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-11-23 23:58:31 -05:00
Merge pull request #3002 from jmay/group-membership-api
use limit & offset for pagination of group members
This commit is contained in:
commit
a8ff5fe97c
2 changed files with 20 additions and 2 deletions
|
@ -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,20 @@ 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)) }
|
||||||
|
usernames = group.users.map{ |m| m['username'] }.sort
|
||||||
|
|
||||||
|
xhr :get, :members, group_id: group.name, limit: 3
|
||||||
|
response.should be_success
|
||||||
|
members = JSON.parse(response.body)
|
||||||
|
members.map{ |m| m['username'] }.should eq(usernames[0..2])
|
||||||
|
|
||||||
|
xhr :get, :members, group_id: group.name, limit: 3, offset: 3
|
||||||
|
response.should be_success
|
||||||
|
members = JSON.parse(response.body)
|
||||||
|
members.map{ |m| m['username'] }.should eq(usernames[3..4])
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue