From f8268accc00f25a402b76cd7a1af7e715760e68a Mon Sep 17 00:00:00 2001 From: yystopf Date: Thu, 4 Aug 2022 17:28:14 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=EF=BC=9A=20=E7=BB=84?= =?UTF-8?q?=E7=BB=87=E4=B8=8B=E9=A1=B9=E7=9B=AE=E5=8D=8F=E4=BD=9C=E8=80=85?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=BD=93=E5=89=8D=E7=94=A8=E6=88=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/members_controller.rb | 5 ++++ app/views/members/index.json.jbuilder | 34 ++++++++++++++++++++++----- 2 files changed, 33 insertions(+), 6 deletions(-) diff --git a/app/controllers/members_controller.rb b/app/controllers/members_controller.rb index 92ad4ccbb..b4d8e1f9a 100644 --- a/app/controllers/members_controller.rb +++ b/app/controllers/members_controller.rb @@ -26,6 +26,9 @@ class MembersController < ApplicationController @total_count = scope.size @members = paginate(scope) + if @project.owner.is_a?(Organization) && (params[:page].to_i == 1 || params[:page].blank?) + @current_user_header_team = Team.joins(:team_users, :team_projects).where(team_projects: {project_id: @project.id}, team_users: {user_id: current_user.id}).order(authorize: :desc).take + end end def remove @@ -65,6 +68,8 @@ class MembersController < ApplicationController end def check_member_not_exists! + @current_user_header_team = Team.joins(:team_users, :team_projects).where(team_projects: {project_id: @project.id}, team_users: {user_id: current_user.id}).order(authorize: :desc).take + return render_error("用户为组织成员,请到组织下操作!") if @current_user_header_team.present? return render_error("user_id为#{params[:user_id]}的用户还不是项目成员") unless member_exists? end diff --git a/app/views/members/index.json.jbuilder b/app/views/members/index.json.jbuilder index 457c50271..ba08d0214 100644 --- a/app/views/members/index.json.jbuilder +++ b/app/views/members/index.json.jbuilder @@ -1,9 +1,31 @@ json.total_count @total_count -json.members @members do |member| - if member.user.present? - json.partial! 'member', user: member.user - json.is_owner @project.owner?(member.user) - json.role member.roles.last.name - json.role_name t("roles.#{member.roles.last.name}") +json.members do + if @current_user_header_team.present? + json.child! do + json.partial! 'member', user: current_user + json.is_owner @project.owner?(current_user) + case @current_user_header_team.authorize + when 'read' + json.role 'Reporter' + json.role_name t("roles.Reporter") + when 'write' + json.role 'Developer' + json.role_name t("roles.Developer") + when 'admin' + json.role 'Manager' + json.role_name t("roles.Manager") + when 'owner' + json.role 'Manager' + json.role_name t("roles.Manager") + end + end + end + @members.each do |member| + json.child! do + json.partial! 'member', user: member.user + json.is_owner @project.owner?(member.user) + json.role member.roles.last.name + json.role_name t("roles.#{member.roles.last.name}") + end end end