diff --git a/app/controllers/organizations/teams_controller.rb b/app/controllers/organizations/teams_controller.rb index c599ac420..285f9960b 100644 --- a/app/controllers/organizations/teams_controller.rb +++ b/app/controllers/organizations/teams_controller.rb @@ -4,15 +4,24 @@ class Organizations::TeamsController < Organizations::BaseController before_action :check_user_can_edit_org, only: [:create, :update, :destroy] def index - #if @organization.is_owner?(current_user) || current_user.admin? - @teams = @organization.teams - #else - # @teams = @organization.teams.joins(:team_users).where(team_users: {user_id: current_user.id}) - #end - @is_admin = can_edit_org? - @teams = @teams.includes(:team_units, :team_users) - @teams = kaminari_paginate(@teams) + if params[:is_full].present? + if can_edit_org? + @teams = @organization.teams + else + @teams = [] + end + else + #if @organization.is_owner?(current_user) || current_user.admin? + @teams = @organization.teams + #else + # @teams = @organization.teams.joins(:team_users).where(team_users: {user_id: current_user.id}) + #end + @is_admin = can_edit_org? + @teams = @teams.includes(:team_units, :team_users) + + @teams = kaminari_paginate(@teams) + end end def search @@ -34,8 +43,12 @@ class Organizations::TeamsController < Organizations::BaseController def create ActiveRecord::Base.transaction do - Organizations::CreateTeamForm.new(team_params).validate! - @team = Organizations::Teams::CreateService.call(current_user, @organization, team_params) + if @organization.teams.count >= 50 + return render_forbidden("组织的团队数量已超过限制!") + else + Organizations::CreateTeamForm.new(team_params).validate! + @team = Organizations::Teams::CreateService.call(current_user, @organization, team_params) + end end rescue Exception => e uid_logger_error(e.message) diff --git a/app/views/organizations/teams/_simple_detail.json.jbuilder b/app/views/organizations/teams/_simple_detail.json.jbuilder new file mode 100644 index 000000000..5e9a6246d --- /dev/null +++ b/app/views/organizations/teams/_simple_detail.json.jbuilder @@ -0,0 +1,3 @@ +json.id team.id +json.name team.name +json.nickname team.nickname.blank? ? team.name : team.nickname \ No newline at end of file diff --git a/app/views/organizations/teams/index.json.jbuilder b/app/views/organizations/teams/index.json.jbuilder index ad3479ec4..189047fc4 100644 --- a/app/views/organizations/teams/index.json.jbuilder +++ b/app/views/organizations/teams/index.json.jbuilder @@ -1,4 +1,8 @@ -json.total_count @teams.total_count +json.total_count params[:is_full].present? ? @teams.count : @teams.total_count json.teams @teams do |team| - json.partial! "detail", team: team, organization: @organization + if params[:is_full].present? + json.partial! "simple_detail", team: team, organization: @organization + else + json.partial! "detail", team: team, organization: @organization + end end