同步用户bug解决

This commit is contained in:
guange 2015-11-01 21:49:07 +08:00
parent 0fb48a41cb
commit be25a57eaf
4 changed files with 22 additions and 4 deletions

View File

@ -209,7 +209,7 @@ class User < Principal
validates_inclusion_of :mail_notification, :in => MAIL_NOTIFICATION_OPTIONS.collect(&:first), :allow_blank => true validates_inclusion_of :mail_notification, :in => MAIL_NOTIFICATION_OPTIONS.collect(&:first), :allow_blank => true
validate :validate_password_length validate :validate_password_length
# validates_email_realness_of :mail # validates_email_realness_of :mail
before_create :set_mail_notification, :sync_gitlab_user before_create :set_mail_notification
before_save :update_hashed_password before_save :update_hashed_password
before_destroy :remove_references_before_destroy before_destroy :remove_references_before_destroy
# added by fq # added by fq
@ -218,6 +218,8 @@ class User < Principal
# 更新邮箱用户或用户名的同事,同步更新邀请信息 # 更新邮箱用户或用户名的同事,同步更新邀请信息
after_update :update_invite_list after_update :update_invite_list
include Trustie::Gitlab::ManageUser
scope :in_group, lambda {|group| scope :in_group, lambda {|group|
group_id = group.is_a?(Group) ? group.id : group.to_i group_id = group.is_a?(Group) ? group.id : group.to_i
where("#{User.table_name}.id IN (SELECT gu.user_id FROM #{table_name_prefix}groups_users#{table_name_suffix} gu WHERE gu.group_id = ?)", group_id) where("#{User.table_name}.id IN (SELECT gu.user_id FROM #{table_name_prefix}groups_users#{table_name_suffix} gu WHERE gu.group_id = ?)", group_id)

View File

@ -60,6 +60,11 @@ class Gitlab::Client
put("/users/#{user_id}", :body => options) put("/users/#{user_id}", :body => options)
end end
def delete_user(user_id)
delete("/users/#{user_id}")
end
# Creates a new user session. # Creates a new user session.
# #
# @example # @example

View File

@ -4,15 +4,26 @@ module Trustie
module Gitlab module Gitlab
module Helper module Helper
def change_password(uid, en_pwd, salt) def change_password(uid, en_pwd, salt)
return unless uid
options = {:encrypted_password=>en_pwd, :password_salt=>salt} options = {:encrypted_password=>en_pwd, :password_salt=>salt}
self.g.put("/users/ext/#{uid}", :body => options) self.g.put("/users/ext/#{uid}", :body => options)
# g.edit_user(uid, :encrypted_password=>en_pwd, :password_salt=>salt) # g.edit_user(uid, :encrypted_password=>en_pwd, :password_salt=>salt)
end end
def find_user(user)
us = self.g.get("/users?search=#{user.mail}")
if Array === us
us.each do |u|
return u if u.email == user.mail
end
end
return nil
end
def add_user(user) def add_user(user)
u = nil u = nil
begin begin
u = self.g.get("/users?search=#{user.mail}").first u = find_user(user)
unless u unless u
u = self.g.create_user(user.mail, u = self.g.create_user(user.mail,
user.hashed_password, user.hashed_password,
@ -29,7 +40,8 @@ module Trustie
end end
def del_user(user) def del_user(user)
## gitlab unimplement return unless user.gid
self.g.delete_user(user.gid)
end end
end end

View File

@ -27,7 +27,6 @@ module Trustie
change_password(self.gid, self.hashed_password, self.salt) change_password(self.gid, self.hashed_password, self.salt)
end end
private
def g def g
@g ||= ::Gitlab.client @g ||= ::Gitlab.client
end end