Merge remote-tracking branch 'origin/szzh' into szzh
This commit is contained in:
commit
8d7a203411
|
@ -1,22 +0,0 @@
|
|||
#coding=utf-8
|
||||
|
||||
namespace :rep_fault do
|
||||
desc "set ossean's type value"
|
||||
task :rep_update => :environment do
|
||||
rep = Repository.find(400)
|
||||
rep.type = "Repository::Git"
|
||||
rep.save
|
||||
end
|
||||
|
||||
desc "forge and ossean's members"
|
||||
task :sync_members => :environment do
|
||||
projects = []
|
||||
projects << Project.where("id =? ",2)
|
||||
projects << Project.where("id =? ",299)
|
||||
puts projects
|
||||
s = Trustie::Gitlab::Sync.new
|
||||
projects.each do |project|
|
||||
s.only_members(project.first)
|
||||
end
|
||||
end
|
||||
end
|
|
@ -0,0 +1,39 @@
|
|||
#coding=utf-8
|
||||
|
||||
namespace :gitlab do
|
||||
desc "sync gitlab's users which lost in last sync"
|
||||
task :add_gid => :environment do
|
||||
users = User.find_by_sql("select * from users where gid is null")
|
||||
s = Trustie::Gitlab::Sync.new
|
||||
g = Gitlab.client
|
||||
users.each do |user|
|
||||
us = g.get("/users?search=#{user.mail}")
|
||||
puts user.mail
|
||||
if us.blank?
|
||||
puts "55555555555555555"
|
||||
s.sync_user(user)
|
||||
else
|
||||
# 解决查询的时候出现多值的情况,比如:123@163.com和g123@163.com
|
||||
puts "66666666666666666666"
|
||||
puts user.id
|
||||
if Array === us
|
||||
us.each do |u|
|
||||
if u.email == user.mail
|
||||
user.gid = u.id
|
||||
user.save
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
task :sync_members => :environment do
|
||||
projects = Project.all
|
||||
s = Trustie::Gitlab::Sync.new
|
||||
projects.each do |project|
|
||||
puts project.id
|
||||
s.only_members(project.first)
|
||||
end
|
||||
end
|
||||
end
|
|
@ -3,46 +3,46 @@
|
|||
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 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
|
||||
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
|
||||
return nil
|
||||
end
|
||||
return nil
|
||||
end
|
||||
|
||||
def add_user(user)
|
||||
u = nil
|
||||
begin
|
||||
u = find_user(user)
|
||||
unless u
|
||||
u = self.g.create_user(user.mail,
|
||||
user.hashed_password,
|
||||
name: user.show_name,
|
||||
username: user.login,
|
||||
confirm: "true")
|
||||
user.gid = u.id
|
||||
end
|
||||
change_password(u.id, user.hashed_password, user.salt)
|
||||
rescue => e
|
||||
puts e
|
||||
end
|
||||
return u
|
||||
def add_user(user)
|
||||
u = nil
|
||||
begin
|
||||
u = find_user(user)
|
||||
unless u
|
||||
u = self.g.create_user(user.mail,
|
||||
user.hashed_password,
|
||||
name: user.show_name,
|
||||
username: user.login,
|
||||
confirm: "true")
|
||||
user.gid = u.id
|
||||
end
|
||||
change_password(u.id, user.hashed_password, user.salt)
|
||||
rescue => e
|
||||
puts e
|
||||
end
|
||||
return u
|
||||
end
|
||||
|
||||
def del_user(user)
|
||||
return unless user.gid
|
||||
self.g.delete_user(user.gid)
|
||||
end
|
||||
def del_user(user)
|
||||
return unless user.gid
|
||||
self.g.delete_user(user.gid)
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue