fix: create team count limit

This commit is contained in:
yystopf 2022-01-06 17:38:44 +08:00
parent a7665df0ea
commit 47d1f727ce
3 changed files with 32 additions and 12 deletions

View File

@ -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)

View File

@ -0,0 +1,3 @@
json.id team.id
json.name team.name
json.nickname team.nickname.blank? ? team.name : team.nickname

View File

@ -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