gitlab同步修改用户

This commit is contained in:
huang 2016-12-24 11:57:10 +08:00
parent 87c134c007
commit 4336d28dda
1 changed files with 18 additions and 11 deletions

View File

@ -154,22 +154,14 @@ class MyController < ApplicationController
diskfile1 = diskfile + 'temp'
begin
if request.post?
# 修改邮箱的时候同步修改到gitlab
if @user.mail != params[:user][:mail]
g = Gitlab.client
begin
g.edit_user(@user.gid, :email => params[:user][:mail])
rescue Exception => e
puts e
end
end
changed_login = (@user.login.strip != params[:login].strip)
changed_mail = (@user.mail.strip != params[:user][:mail].strip)
@user.safe_attributes = params[:user]
@user.lastname = params[:lastname]
@user.firstname = ""
@user.pref.attributes = params[:pref]
@user.pref[:no_self_notified] = (params[:no_self_notified] == '1')
@user.login = params[:login]
@user.login = params[:login].strip
unless @user.user_extensions.nil?
# 如果用户是从业者将单位名称保存至学校id字段
if @user.user_extensions.identity == 3
@ -195,6 +187,21 @@ class MyController < ApplicationController
@se.description = params[:description]
if @user.save && @se.save
# 修改邮箱的时候同步修改到gitlab
if changed_mail || changed_login
g = Gitlab.client
s = Trustie::Gitlab::Sync.new
begin
gid = @user.gid
if gid.nil?
gid = s.sync_user(m.user).id
end
g.edit_user(gid, :email => params[:user][:mail], :username => @user.login)
rescue Exception => e
puts e
end
end
# 头像保存
FileUtils.mv diskfile1, diskfile, force: true if File.exist? diskfile1
@user.pref.save