Browse Source

fixed 组织成员数取组织内成员和组织所有仓库成员组合

pull/347/head
xxq250 2 years ago
parent
commit
d2663eb7b7
3 changed files with 26 additions and 13 deletions
  1. +18
    -5
      app/controllers/organizations/organization_users_controller.rb
  2. +4
    -4
      app/views/organizations/organization_users/_detail.json.jbuilder
  3. +4
    -4
      app/views/organizations/organization_users/index.json.jbuilder

+ 18
- 5
app/controllers/organizations/organization_users_controller.rb View File

@@ -4,17 +4,30 @@ class Organizations::OrganizationUsersController < Organizations::BaseController
before_action :check_user_can_edit_org, only: [:destroy]

def index
@organization_users = @organization.organization_users.includes(:user)
# @organization_users = @organization.organization_users.includes(:user)
# if params[:search].present?
# search = params[:search].to_s.downcase
# user_condition_users = User.like(search).to_sql
# team_condition_teams = User.joins(:teams).merge(@organization.teams.like(search)).to_sql
# users = User.from("( #{user_condition_users} UNION #{team_condition_teams }) AS users")
#
# @organization_users = @organization_users.where(user_id: users).distinct
# end
#
# @organization_users = kaminari_paginate(@organization_users)

organization_user_ids = @organization.organization_users.pluck(:user_id).uniq
project_member_user_ids = @organization.projects.joins(:members).pluck("members.user_id").uniq
users = User.where(id: organization_user_ids + project_member_user_ids)
if params[:search].present?
search = params[:search].to_s.downcase
user_condition_users = User.like(search).to_sql
team_condition_teams = User.joins(:teams).merge(@organization.teams.like(search)).to_sql
users = User.from("( #{user_condition_users} UNION #{team_condition_teams }) AS users")
user_ids = User.from("( #{user_condition_users} UNION #{team_condition_teams }) AS users").pluck(:id)

@organization_users = @organization_users.where(user_id: users).distinct
users = users.where(id: user_ids)
end

@organization_users = kaminari_paginate(@organization_users)
@users = kaminari_paginate(users)
end

def pm_check_user


+ 4
- 4
app/views/organizations/organization_users/_detail.json.jbuilder View File

@@ -1,7 +1,7 @@
json.id org_user.id
json.id user&.id
json.user do
json.partial! "organizations/user_detail", user: org_user.user
json.partial! "organizations/user_detail", user: user
end

json.team_names org_user.teams.pluck(:nickname)
json.created_at org_user.created_at.strftime("%Y-%m-%d")
json.team_names user.teams.where("teams.organization_id=?", organization.id).pluck(:nickname)
json.created_at user.created_on.strftime("%Y-%m-%d")

+ 4
- 4
app/views/organizations/organization_users/index.json.jbuilder View File

@@ -1,5 +1,5 @@
json.total_count @organization_users.total_count
json.organization_users @organization_users do |org_user|
next if org_user.user.blank?
json.partial! "detail", org_user: org_user, organization: @organization
json.total_count @users.total_count
json.organization_users @users do |user|
next if user.blank?
json.partial! "detail", user: user, organization: @organization
end

Loading…
Cancel
Save