From f2fe59ed0fc2ace704b2fa45cfd6bc6c4a10d808 Mon Sep 17 00:00:00 2001 From: huang Date: Thu, 17 Aug 2017 17:18:30 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=AE=9E=E8=AE=AD=E5=90=88?= =?UTF-8?q?=E4=BD=9C=E8=80=85=EF=BC=8C=E6=95=B0=E6=8D=AE=E5=90=8C=E6=AD=A5?= =?UTF-8?q?github?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/shixuns_controller.rb | 31 ++++++++++++++++++++++----- 1 file changed, 26 insertions(+), 5 deletions(-) diff --git a/app/controllers/shixuns_controller.rb b/app/controllers/shixuns_controller.rb index b7f035888..9adddf597 100644 --- a/app/controllers/shixuns_controller.rb +++ b/app/controllers/shixuns_controller.rb @@ -184,17 +184,38 @@ class ShixunsController < ApplicationController end end + # 事务处理,保证Trustie与Gitlab数据同步 def shixun_members_added unless params[:membership][:user_ids].blank? memberships = params[:membership][:user_ids] memberships.each do |member| - ShixunMember.create(:user_id => member, :shixun_id => @shixun.id, :role => 2) + ActiveRecord::Base.transaction do + begin + user = User.find(member) + s = Trustie::Gitlab::Sync.new + if user.gid.present? + gid = user.gid + else + guser = s.sync_user(user) + gid = guser.id + end + ShixunMember.create(:user_id => member, :shixun_id => @shixun.id, :role => 2) + u = s.g.add_team_member(@shixun.gpid, gid, 40) # 3代表角色master + if u.blank? + raise("同步Gitlab数据错误") + end + @collaborators = @shixun.collaborators + respond_to do |format| + format.js + end + rescue Exception => e + logger.error(e) + raise ActiveRecord::Rollback + end + end end @collaborators = @shixun.collaborators end - respond_to do |format| - format.js - end end def search @@ -619,7 +640,7 @@ class ShixunsController < ApplicationController # REDO: 新增类型copy的时候 # 复制项目 # gshixun --> gitlab project - CODES = %W(2 3 4 5 6 7 8 9 a b c f e f g h i j k l m n o p q r s t u v w x y z) + # CODES = %W(2 3 4 5 6 7 8 9 a b c f e f g h i j k l m n o p q r s t u v w x y z) def copy_myshixun shixun, gshixun myshixun = Myshixun.new # myshixun.attributes = shixun.attributes.dup.except("id","user_id","visits","gpid","status", "identifier","propaedeutics")