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