新注册用户可以同步到gitlab

This commit is contained in:
guange 2015-07-15 15:51:49 +08:00
parent 3614c6ee9b
commit 006ed66d7a
4 changed files with 28 additions and 3 deletions

View File

@ -203,6 +203,7 @@ class User < Principal
# added by fq # added by fq
after_create :act_as_activity after_create :act_as_activity
# end # end
before_create :sync_gitlab_user
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
@ -994,6 +995,17 @@ class User < Principal
end end
private
def sync_gitlab_user
user = self
g = Gitlab.client
u = g.get("/users?search=#{user.mail}").first
unless u
u = g.create_user(user.mail, user.password, name: user.show_name, username: user.login, confirm: "true")
self.gid = u.id
puts "create user #{user.login}"
end
end
end end

View File

@ -69,6 +69,14 @@ module RedmineApp
config.action_view.sanitized_allowed_tags = 'div', 'p', 'span', 'img', 'embed' config.action_view.sanitized_allowed_tags = 'div', 'p', 'span', 'img', 'embed'
config.before_initialize do
puts "before initialize"
end
config.after_initialize do
puts "after initialize"
end
if File.exists?(File.join(File.dirname(__FILE__), 'additional_environment.rb')) if File.exists?(File.join(File.dirname(__FILE__), 'additional_environment.rb'))
instance_eval File.read(File.join(File.dirname(__FILE__), 'additional_environment.rb')) instance_eval File.read(File.join(File.dirname(__FILE__), 'additional_environment.rb'))
end end

View File

@ -1,5 +1,5 @@
Gitlab.configure do |config| Gitlab.configure do |config|
config.endpoint = 'http://192.168.41.130:3000/api/v3' # API endpoint URL, default: ENV['GITLAB_API_ENDPOINT'] config.endpoint = 'http://192.168.41.130:3000/trustie/api/v3' # API endpoint URL, default: ENV['GITLAB_API_ENDPOINT']
config.private_token = 'cK15gUDwvt8EEkzwQ_63' # user's private token, default: ENV['GITLAB_API_PRIVATE_TOKEN'] config.private_token = 'cK15gUDwvt8EEkzwQ_63' # user's private token, default: ENV['GITLAB_API_PRIVATE_TOKEN']
# Optional # Optional
# config.user_agent = 'Custom User Agent' # user agent, default: 'Gitlab Ruby Gem [version]' # config.user_agent = 'Custom User Agent' # user agent, default: 'Gitlab Ruby Gem [version]'

View File

@ -4,7 +4,9 @@ namespace :gitlab do
module Helper module Helper
def self.change_password(uid, en_pwd, salt) def self.change_password(uid, en_pwd, salt)
g = Gitlab.client g = Gitlab.client
g.edit_user(uid, :encrypted_password=>en_pwd, :password_salt=>salt) options = {:encrypted_password=>en_pwd, :password_salt=>salt}
g.put("/users/ext/#{uid}", :body => options)
# g.edit_user(uid, :encrypted_password=>en_pwd, :password_salt=>salt)
end end
end end
@ -17,7 +19,7 @@ namespace :gitlab do
g = Gitlab.client g = Gitlab.client
u = g.get("/users?search=#{user.mail}").first u = g.get("/users?search=#{user.mail}").first
unless u unless u
u = g.create_user(user.mail, user.hashed_password, name: user.show_name, username: user.login) u = g.create_user(user.mail, user.hashed_password, name: user.show_name, username: user.login, confirm: "true")
user.gid = u.id user.gid = u.id
user.save! user.save!
puts "create user #{user.login}" puts "create user #{user.login}"
@ -44,6 +46,9 @@ namespace :gitlab do
path = project.repositories.where(:is_default => true).first.root_url.split('/').last path = project.repositories.where(:is_default => true).first.root_url.split('/').last
path = path.split('.').first path = path.split('.').first
raise "unknow path" unless path raise "unknow path" unless path
# import url http://xianbo_trustie2:1234@repository.trustie.net/xianbo/trustie2.git
# can use password
gproject = g.create_project(project.identifier, gproject = g.create_project(project.identifier,
path: path, path: path,
description: project.description, description: project.description,