mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-11-24 16:18:42 -05:00
35edfb5b91
this in the new year.
44 lines
1.1 KiB
Ruby
44 lines
1.1 KiB
Ruby
class GroupsController < ApplicationController
|
|
|
|
def show
|
|
render_serialized(find_group(:id), BasicGroupSerializer)
|
|
end
|
|
|
|
def counts
|
|
group = find_group(:group_id)
|
|
render json: {counts: { posts: group.posts_for(guardian).count,
|
|
members: group.users.count } }
|
|
end
|
|
|
|
def posts
|
|
group = find_group(:group_id)
|
|
posts = group.posts_for(guardian, params[:before_post_id]).limit(20)
|
|
render_serialized posts.to_a, GroupPostSerializer
|
|
end
|
|
|
|
def members
|
|
group = find_group(:group_id)
|
|
|
|
members = group.users.order('username_lower asc')
|
|
|
|
# TODO: We should fix the root cause of the bug where if there
|
|
# are more than 200 groups it will truncate
|
|
if group.automatic?
|
|
limit = (params[:limit] || 200).to_i
|
|
offset = (params[:offset] || 0).to_i
|
|
members = members.limit(limit).offset(offset)
|
|
end
|
|
|
|
render_serialized(members.to_a, GroupUserSerializer)
|
|
end
|
|
|
|
private
|
|
|
|
def find_group(param_name)
|
|
name = params.require(param_name)
|
|
group = Group.find_by("lower(name) = ?", name.downcase)
|
|
guardian.ensure_can_see!(group)
|
|
group
|
|
end
|
|
|
|
end
|