diff --git a/app/models/user.rb b/app/models/user.rb index b4723cceb..5605ea038 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -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 diff --git a/config/application.rb b/config/application.rb index 83ba21b05..fc19faf49 100644 --- a/config/application.rb +++ b/config/application.rb @@ -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 diff --git a/config/initializers/gitlab_config.rb b/config/initializers/gitlab_config.rb index ddd1efec8..3e2159336 100644 --- a/config/initializers/gitlab_config.rb +++ b/config/initializers/gitlab_config.rb @@ -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]' diff --git a/lib/tasks/gitlab.rake b/lib/tasks/gitlab.rake index 2d53eaa0a..5795ae4f4 100644 --- a/lib/tasks/gitlab.rake +++ b/lib/tasks/gitlab.rake @@ -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,