新注册用户可以同步到gitlab
This commit is contained in:
parent
3614c6ee9b
commit
006ed66d7a
|
@ -203,6 +203,7 @@ class User < Principal
|
|||
# added by fq
|
||||
after_create :act_as_activity
|
||||
# end
|
||||
before_create :sync_gitlab_user
|
||||
|
||||
scope :in_group, lambda {|group|
|
||||
group_id = group.is_a?(Group) ? group.id : group.to_i
|
||||
|
@ -994,6 +995,17 @@ class User < Principal
|
|||
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
|
||||
|
||||
|
|
|
@ -69,6 +69,14 @@ module RedmineApp
|
|||
|
||||
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'))
|
||||
instance_eval File.read(File.join(File.dirname(__FILE__), 'additional_environment.rb'))
|
||||
end
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
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']
|
||||
# Optional
|
||||
# config.user_agent = 'Custom User Agent' # user agent, default: 'Gitlab Ruby Gem [version]'
|
||||
|
|
|
@ -4,7 +4,9 @@ namespace :gitlab do
|
|||
module Helper
|
||||
def self.change_password(uid, en_pwd, salt)
|
||||
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
|
||||
|
||||
|
@ -17,7 +19,7 @@ namespace :gitlab do
|
|||
g = Gitlab.client
|
||||
u = g.get("/users?search=#{user.mail}").first
|
||||
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.save!
|
||||
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 = path.split('.').first
|
||||
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,
|
||||
path: path,
|
||||
description: project.description,
|
||||
|
|
Loading…
Reference in New Issue