diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 36e57de5a..f546a2ac3 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -53,6 +53,7 @@ class UsersController < ApplicationController include CustomFieldsHelper include AvatarHelper include WordsHelper + include GitlabHelper # added by liuping 关注 @@ -362,6 +363,10 @@ class UsersController < ApplicationController end def show + # 测试代码 + #login_gitlab("admin@local.host","19840410") + # 测试结束 + pre_count = 10 #limit case params[:type] when "1" diff --git a/app/helpers/gitlab_helper.rb b/app/helpers/gitlab_helper.rb new file mode 100644 index 000000000..486190c88 --- /dev/null +++ b/app/helpers/gitlab_helper.rb @@ -0,0 +1,115 @@ +# Gitlab5.3 API操作接口 +# Add by nwb + +module GitlabHelper + + # gitlab版本库数据本地保存的根目录 + ROOT_PATH="/home/git/repositories/" + PROJECT_PATH_CUT = 40 + # gitlab版本库所在服务器 + #REPO_IP_ADDRESS = Setting.repository_domain + REPO_IP_ADDRESS = "http://192.168.137.100" + GITLAB_API = "/api/v3" + + def self.gitlab_token=(token) + Thread.current[:gitlab_token] = token + end + + # gitlab的登录验证信息 + # add by nwb + def self.gitlab_token + Thread.current[:gitlab_token] ||= nil + end + + # 登录gitlab + # add by nwb + def login_gitlab(email,password) + url = REPO_IP_ADDRESS + GITLAB_API + "/session" + uri = URI.parse(url) + data = {email:email, password:password} + begin + res = Net::HTTP.post_form(uri, data) + if res.code == '201' + temp = ActiveSupport::JSON.decode(res.body) + gitlab_token= temp['private_token'] + return true + else + return false + end + rescue =>err + return false + end + end + + # 创建项目 + # add by nwb + def create_project(name) + + end + + # 为指定用户创建版本库 + # name:版本库名称 user:版本库创建后所属的用户 + def create_project_for_user(name,user) + + end + + # 创建用户 + # loginname:登录名称 username:用户姓名 + def create_user (loginname,username,password,email) + + end + + # 删除用户 + def delete_user(user_id) + + end + + # 给用户添加一个可操作的项目 + def add_project_to_user(project_name,user) + end + + def post(url, params) + uri = URI.parse(url) + http = Net::HTTP.new(uri.host, uri.port) + if uri.scheme == 'https' + http.verify_mode = OpenSSL::SSL::VERIFY_NONE + http.use_ssl = true + end + begin + request = Net::HTTP::Post.new(uri.request_uri) + request['Content-Type'] = 'application/json;charset=utf-8' + request['User-Agent'] = 'Mozilla/5.0 (Windows NT 5.1; rv:29.0) Gecko/20100101 Firefox/29.0' + request['X-ACL-TOKEN'] = 'xxx_token' + #request.set_form_data(params) + request.body = params.to_json + response = http.start { |http| http.request(request) } + puts response.body.inspect + return JSON.parse response.body + rescue =>err + return nil + end + end + + + def get(url, params) + uri = URI.parse(url) + uri.query = URI.encode_www_form(params) + http = Net::HTTP.new uri.host, uri.port + if uri.scheme == 'https' + http.verify_mode = OpenSSL::SSL::VERIFY_NONE + http.use_ssl = true + end + begin + request = Net::HTTP::Get.new uri.request_uri + request['Content-Type'] = 'application/json;charset=utf-8' + request['User-Agent'] = 'Mozilla/5.0 (Windows NT 5.1; rv:29.0) Gecko/20100101 Firefox/29.0' + request['X-ACL-TOKEN'] = 'xxx_token' + response = http.start { |http| http.request request } + puts response.body.inspect + return JSON.parse response.body + rescue =>err + return nil + end + end + +end \ No newline at end of file diff --git a/db/schema.rb b/db/schema.rb index f318ff96a..3d1499022 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended to check this file into your version control system. -ActiveRecord::Schema.define(:version => 20140714081030) do +ActiveRecord::Schema.define(:version => 20140715015540) do create_table "activities", :force => true do |t| t.integer "act_id", :null => false @@ -379,6 +379,7 @@ ActiveRecord::Schema.define(:version => 20140714081030) do t.text "description" t.datetime "created_on" t.integer "user_id", :default => 0 + t.integer "is_public", :default => 1 end add_index "documents", ["category_id"], :name => "index_documents_on_category_id" @@ -768,6 +769,7 @@ ActiveRecord::Schema.define(:version => 20140714081030) do t.boolean "hidden_repo", :default => false, :null => false t.integer "attachmenttype", :default => 1 t.integer "user_id" + t.integer "dts_test", :default => 0 end add_index "projects", ["lft"], :name => "index_projects_on_lft"