parent
1f5d792783
commit
3d8571b59e
|
@ -367,6 +367,8 @@ class UsersController < ApplicationController
|
|||
#login_gitlab("admin@local.host","19840410")
|
||||
#create_project("testproject1")
|
||||
#create_project_for_user("testproject1","2")
|
||||
#create_user("test","just test","123456","test@sina.com")
|
||||
#delete_user("3")
|
||||
# 测试结束
|
||||
|
||||
pre_count = 10 #limit
|
||||
|
|
|
@ -94,14 +94,47 @@ module GitlabHelper
|
|||
end
|
||||
|
||||
# 创建用户
|
||||
# loginname:登录名称 username:用户姓名
|
||||
def create_user (loginname,username,password,email)
|
||||
|
||||
# loginname:登录名称(版本库路径包含) name:用户姓名
|
||||
# add by nwb
|
||||
def create_user (loginname,name,password,email)
|
||||
url = REPO_IP_ADDRESS + GITLAB_API + "/users"
|
||||
uri = URI.parse(url)
|
||||
data = {email:email,password:password,username:loginname, name:name, private_token:GitlabHelper.gitlab_token}
|
||||
begin
|
||||
res = Net::HTTP.post_form(uri, data)
|
||||
if res.code == '201'
|
||||
temp = ActiveSupport::JSON.decode(res.body)
|
||||
#新创建的gitlab用户编号(需保存)
|
||||
user_id = temp['id']
|
||||
return true
|
||||
else
|
||||
return false
|
||||
end
|
||||
rescue =>err
|
||||
return false
|
||||
end
|
||||
end
|
||||
|
||||
# 删除用户
|
||||
def delete_user(user_id)
|
||||
|
||||
url = REPO_IP_ADDRESS + GITLAB_API + "/users/" + user_id
|
||||
uri = URI.parse(url)
|
||||
data = {id:user_id,private_token:GitlabHelper.gitlab_token}
|
||||
http = Net::HTTP.new uri.host, uri.port
|
||||
begin
|
||||
req = Net::HTTP::Delete.new(uri.request_uri)
|
||||
req.form_data = data
|
||||
res= http.start { |http| http.request req }
|
||||
if res.code == '200'
|
||||
temp = ActiveSupport::JSON.decode(res.body)
|
||||
# 删除成功,对应更新trustie用户的gitlab用户编号
|
||||
return true
|
||||
else
|
||||
return false
|
||||
end
|
||||
rescue =>err
|
||||
return false
|
||||
end
|
||||
end
|
||||
|
||||
# 给用户添加一个可操作的项目
|
||||
|
|
Loading…
Reference in New Issue