Browse Source

fix: create team count limit

tags/v4.0.0^2
yystopf 4 years ago
parent
commit
47d1f727ce
3 changed files with 32 additions and 12 deletions
  1. +23
    -10
      app/controllers/organizations/teams_controller.rb
  2. +3
    -0
      app/views/organizations/teams/_simple_detail.json.jbuilder
  3. +6
    -2
      app/views/organizations/teams/index.json.jbuilder

+ 23
- 10
app/controllers/organizations/teams_controller.rb 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)


+ 3
- 0
app/views/organizations/teams/_simple_detail.json.jbuilder View File

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

+ 6
- 2
app/views/organizations/teams/index.json.jbuilder 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

Loading…
Cancel
Save