From be25a57eaf16aa5c1addf9172d15bb0c165a9b90 Mon Sep 17 00:00:00 2001 From: guange <8863824@gmail.com> Date: Sun, 1 Nov 2015 21:49:07 +0800 Subject: [PATCH] =?UTF-8?q?=E5=90=8C=E6=AD=A5=E7=94=A8=E6=88=B7bug?= =?UTF-8?q?=E8=A7=A3=E5=86=B3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/user.rb | 4 +++- lib/gitlab-cli/lib/gitlab/client/users.rb | 5 +++++ lib/trustie/gitlab/helper.rb | 16 ++++++++++++++-- lib/trustie/gitlab/manage_user.rb | 1 - 4 files changed, 22 insertions(+), 4 deletions(-) diff --git a/app/models/user.rb b/app/models/user.rb index e68fc7d8e..edc29c015 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -209,7 +209,7 @@ class User < Principal validates_inclusion_of :mail_notification, :in => MAIL_NOTIFICATION_OPTIONS.collect(&:first), :allow_blank => true validate :validate_password_length # validates_email_realness_of :mail - before_create :set_mail_notification, :sync_gitlab_user + before_create :set_mail_notification before_save :update_hashed_password before_destroy :remove_references_before_destroy # added by fq @@ -218,6 +218,8 @@ class User < Principal # 更新邮箱用户或用户名的同事,同步更新邀请信息 after_update :update_invite_list + include Trustie::Gitlab::ManageUser + scope :in_group, lambda {|group| 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) diff --git a/lib/gitlab-cli/lib/gitlab/client/users.rb b/lib/gitlab-cli/lib/gitlab/client/users.rb index 3fc83cd1b..37bfc0d74 100644 --- a/lib/gitlab-cli/lib/gitlab/client/users.rb +++ b/lib/gitlab-cli/lib/gitlab/client/users.rb @@ -60,6 +60,11 @@ class Gitlab::Client put("/users/#{user_id}", :body => options) end + + def delete_user(user_id) + delete("/users/#{user_id}") + end + # Creates a new user session. # # @example diff --git a/lib/trustie/gitlab/helper.rb b/lib/trustie/gitlab/helper.rb index 5ea4c13e1..57c333875 100644 --- a/lib/trustie/gitlab/helper.rb +++ b/lib/trustie/gitlab/helper.rb @@ -4,15 +4,26 @@ module Trustie module Gitlab module Helper def change_password(uid, en_pwd, salt) + return unless uid options = {:encrypted_password=>en_pwd, :password_salt=>salt} self.g.put("/users/ext/#{uid}", :body => options) # g.edit_user(uid, :encrypted_password=>en_pwd, :password_salt=>salt) 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) u = nil begin - u = self.g.get("/users?search=#{user.mail}").first + u = find_user(user) unless u u = self.g.create_user(user.mail, user.hashed_password, @@ -29,7 +40,8 @@ module Trustie end def del_user(user) - ## gitlab unimplement + return unless user.gid + self.g.delete_user(user.gid) end end diff --git a/lib/trustie/gitlab/manage_user.rb b/lib/trustie/gitlab/manage_user.rb index 76528739c..15bd7ef78 100644 --- a/lib/trustie/gitlab/manage_user.rb +++ b/lib/trustie/gitlab/manage_user.rb @@ -27,7 +27,6 @@ module Trustie change_password(self.gid, self.hashed_password, self.salt) end - private def g @g ||= ::Gitlab.client end