ref: master
plugins/teams/controllers/myprofile/teams_plugin/members_controller.rb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
class TeamsPlugin::MembersController < MyProfileController before_filter :load_context def search @team = @context.teams.find params[:team_id] @query = params[:query] @members_ids = @team.members.map(&:profile_id) @people = environment.people.is_public.limit(10).order('name ASC'). where('name ILIKE ? OR name ILIKE ? OR identifier LIKE ?', "#{@query}%", "% #{@query}%", "#{@query}%"). where.not(id: @members_ids) render json: @people.map{ |p| TeamsPlugin::MemberSerializer.new(p).attributes } end def add @team = @context.teams.find params[:team_id] @member = @team.members.create! profile_id: params[:id] render json: TeamsPlugin::MemberSerializer.new(@member).attributes end def destroy @team = @context.teams.find params[:team_id] @member = @team.members.find params[:id] @member.destroy render nothing: true end protected def load_context @context = params[:context][:type].constantize.find params[:context][:id] end end |