新建版本库逻辑更改

GitlabVersion
nwb 11 years ago
parent c5f6f5884f
commit b550e98603

@ -97,32 +97,55 @@ class RepositoriesController < ApplicationController
if params[:repository_scm].to_s == 'Git' if params[:repository_scm].to_s == 'Git'
# add by nwb # add by nwb
# 增加对gitlab版本库的支持 # 增加对gitlab版本库的支持
# 判断gitlab用户是否存在不存在则创建
# 数据检测
if params[:repository][:identifier] == ""
flash[:error] = l(:project_module_repository) + l(:blank)
render :action => 'newrepo', :layout => 'base_projects'
return
elsif params[:repository][:gitlab_user] == ""
flash[:error] = l(:label_user) + l(:blank)
render :action => 'newrepo', :layout => 'base_projects'
return
elsif params[:repository][:gitlab_email] == ""
flash[:error] = l(:field_mail) + l(:blank)
render :action => 'newrepo', :layout => 'base_projects'
return
elsif params[:repository][:upassword] == ""
flash[:error] = l(:label_password) + l(:blank)
render :action => 'newrepo', :layout => 'base_projects'
return
end
attrs = pickup_extra_info
@repository = Repository.factory('Git')
@repository.safe_attributes = params[:repository]
if attrs[:attrs_extra].keys.any?
@repository.merge_extra_info(attrs[:attrs_extra])
end
@repository.project = @project
# 判断gitlab用户是否存在不存在则创建
user = User.current user = User.current
gitlab_user = GitlabUser.find_by_user_id(user.id) gitlab_user = GitlabUser.find_by_user_id(user.id)
if gitlab_user.nil? if gitlab_user.nil?
if create_user(user.login,user.show_name,user.password,user.mail,user.id) if !create_user(params[:repository][:gitlab_user],user.show_name,params[:repository][:upassword],params[:repository][:gitlab_email],user.id)
else
# 创建gitlab用户失败 # 创建gitlab用户失败
# 返回可自定义用户创建gitlab的界面 flash[:error] = l(:error_create_gitlab_user)
render :action => 'newrepo', :layout =>'base_projects'
return
end end
end end
# 创建gitlab版本库 # 创建gitlab版本库
repos = params[:repository][:identifier] repos = params[:repository][:identifier]
if create_project_for_user(repos,@project.id,gitlab_user.gitlab_user_id) if !create_project_for_user(repos,@project.id,gitlab_user.gitlab_user_id)
# 创建成功
else
# 创建gitlab项目失败 # 创建gitlab项目失败
flash[:error] = l(:error_create_gitlab_project)
render :action => 'newrepo', :layout =>'base_projects'
return
end end
# 连接创建成功后的gitlab版本库 # 连接创建成功后的gitlab版本库
attrs = pickup_extra_info
@repository = Repository.factory('Git')
@repository.safe_attributes = params[:repository]
if attrs[:attrs_extra].keys.any?
@repository.merge_extra_info(attrs[:attrs_extra])
end
@repository.project = @project
if request.post? && @repository.save if request.post? && @repository.save
redirect_to settings_project_path(@project, :tab => 'repositories') redirect_to settings_project_path(@project, :tab => 'repositories')
else else

@ -14,6 +14,10 @@ module GitlabHelper
#REPO_IP_ADDRESS = "http://" + Setting.repository_domain #REPO_IP_ADDRESS = "http://" + Setting.repository_domain
REPO_IP_ADDRESS = "http://192.168.137.100" REPO_IP_ADDRESS = "http://192.168.137.100"
GITLAB_API = "/api/v3" GITLAB_API = "/api/v3"
# gitlab的默认登录用户需管理员
LOGIN_USER = Setting.gitlab_login_user
# gitlab的默认登录密码
LOGIN_PASSWORD = Setting.gitlab_login_password
# 用户在项目中的权限级别 # 用户在项目中的权限级别
GUEST = 10 GUEST = 10
@ -33,6 +37,12 @@ module GitlabHelper
Thread.current[:gitlab_token] ||= nil Thread.current[:gitlab_token] ||= nil
end end
def login_check
if GitlabHelper.gitlab_token.nil?
login_gitlab(GitlabHelper.LOGIN_USER,GitlabHelper.LOGIN_PASSWORD)
end
end
# 登录gitlab # 登录gitlab
# add by nwb # add by nwb
def login_gitlab(email,password) def login_gitlab(email,password)
@ -57,6 +67,7 @@ module GitlabHelper
# 创建项目 # 创建项目
# add by nwb # add by nwb
def create_project(project_name,project_id) def create_project(project_name,project_id)
login_check
url = REPO_IP_ADDRESS + GITLAB_API + "/projects" url = REPO_IP_ADDRESS + GITLAB_API + "/projects"
uri = URI.parse(url) uri = URI.parse(url)
data = {name:project_name, private_token:GitlabHelper.gitlab_token} data = {name:project_name, private_token:GitlabHelper.gitlab_token}
@ -92,6 +103,7 @@ module GitlabHelper
# project_id: 项目在trustie中的编号 # project_id: 项目在trustie中的编号
# add by nwb # add by nwb
def create_project_for_user(project_name,project_id,user_id) def create_project_for_user(project_name,project_id,user_id)
login_check
url = REPO_IP_ADDRESS + GITLAB_API + "/projects/user/" + user_id url = REPO_IP_ADDRESS + GITLAB_API + "/projects/user/" + user_id
uri = URI.parse(url) uri = URI.parse(url)
data = {user_id:user_id, name:project_name,private_token:GitlabHelper.gitlab_token} data = {user_id:user_id, name:project_name,private_token:GitlabHelper.gitlab_token}
@ -126,6 +138,7 @@ module GitlabHelper
# loginname登录名称(版本库路径包含) name用户姓名 # loginname登录名称(版本库路径包含) name用户姓名
# add by nwb # add by nwb
def create_user (loginname,name,password,email,userid) def create_user (loginname,name,password,email,userid)
login_check
url = REPO_IP_ADDRESS + GITLAB_API + "/users" url = REPO_IP_ADDRESS + GITLAB_API + "/users"
uri = URI.parse(url) uri = URI.parse(url)
data = {email:email,password:password,username:loginname, name:name, private_token:GitlabHelper.gitlab_token} data = {email:email,password:password,username:loginname, name:name, private_token:GitlabHelper.gitlab_token}
@ -156,6 +169,7 @@ module GitlabHelper
# user_id:用户在gitlab中的id # user_id:用户在gitlab中的id
# add by nwb # add by nwb
def delete_user(user_id) def delete_user(user_id)
login_check
url = REPO_IP_ADDRESS + GITLAB_API + "/users/" + user_id url = REPO_IP_ADDRESS + GITLAB_API + "/users/" + user_id
uri = URI.parse(url) uri = URI.parse(url)
data = {id:user_id,private_token:GitlabHelper.gitlab_token} data = {id:user_id,private_token:GitlabHelper.gitlab_token}
@ -188,6 +202,7 @@ module GitlabHelper
#MASTER = 40 #MASTER = 40
# add by nwb # add by nwb
def add_user_to_project(project_id,user_id,access_level) def add_user_to_project(project_id,user_id,access_level)
login_check
url = REPO_IP_ADDRESS + GITLAB_API + "/projects/" + project_id +"/members" url = REPO_IP_ADDRESS + GITLAB_API + "/projects/" + project_id +"/members"
uri = URI.parse(url) uri = URI.parse(url)
data = {id:project_id,user_id:user_id,access_level:access_level, private_token:GitlabHelper.gitlab_token} data = {id:project_id,user_id:user_id,access_level:access_level, private_token:GitlabHelper.gitlab_token}
@ -208,6 +223,7 @@ module GitlabHelper
# project_id:项目在gitlab中的ids user_id:用户在gitlab中的id # project_id:项目在gitlab中的ids user_id:用户在gitlab中的id
# add by nwb # add by nwb
def delete_user_from_project(project_id,user_id) def delete_user_from_project(project_id,user_id)
login_check
url = REPO_IP_ADDRESS + GITLAB_API + "/projects/" + project_id +"/members/" + user_id url = REPO_IP_ADDRESS + GITLAB_API + "/projects/" + project_id +"/members/" + user_id
uri = URI.parse(url) uri = URI.parse(url)
data = {id:project_id,user_id:user_id,private_token:GitlabHelper.gitlab_token} data = {id:project_id,user_id:user_id,private_token:GitlabHelper.gitlab_token}

@ -28,8 +28,12 @@ border:none
<%= l(:text_repository_identifier_info).html_safe %></em> <%= l(:text_repository_identifier_info).html_safe %></em>
<% end %></p> <% end %></p>
<!-- <p><%= f.text_field :url, :size => 60, :required => true,:readonly=>true, :class=>'textbg'%></p> --> <!-- <p><%= f.text_field :url, :size => 60, :required => true,:readonly=>true, :class=>'textbg'%></p> -->
<p><%= f.text_field :gitlab_user, :required =>true, :label=> :field_account,:value=>User.current.login %>
<em class="info"><%= l(:label_gitlab_account)%></em></p>
<p><%= f.text_field :gitlab_email, :required => true, :label => :field_account, :value => User.current.mail %>
<em class="info"><%= l(:label_gitlab_email) %></em></p>
<p><%= f.password_field :upassword, :required =>true, :label=> :field_password %> <p><%= f.password_field :upassword, :required =>true, :label=> :field_password %>
<em class="info"><%= l(:label_upassword_info)%></em></p> <em class="info"><%= l(:label_gitlab_password)%></em></p>
</div> </div>
<p> <p>
<%= submit_tag(@repository.new_record? ? l(:button_create) : l(:button_save)) %> <%= submit_tag(@repository.new_record? ? l(:button_create) : l(:button_save)) %>

@ -186,6 +186,9 @@ en:
notice_account_deleted: "Your account has been permanently deleted." notice_account_deleted: "Your account has been permanently deleted."
notice_user_successful_create: "User %{id} created." notice_user_successful_create: "User %{id} created."
error_create_gitlab_user: "Create Gitlab user failed."
error_create_gitlab_project: "Create Gitlab project failed."
error_class_period_only_num: "class period can only digital" error_class_period_only_num: "class period can only digital"
error_can_t_load_default_data: "Default configuration could not be loaded: %{value}" error_can_t_load_default_data: "Default configuration could not be loaded: %{value}"
error_scm_not_found: "The entry or revision was not found in the repository." error_scm_not_found: "The entry or revision was not found in the repository."
@ -1363,6 +1366,9 @@ en:
label_all_revisions: All revisions label_all_revisions: All revisions
label_repository_name: Repository name label_repository_name: Repository name
label_upassword_info: The password can be shared in the group label_upassword_info: The password can be shared in the group
label_gitlab_email: The email user to login gitlab
label_gitlab_account: The account user to login gitlab
label_gitlab_password: The password user to login gitlab
label_how_commit_code: How to commit code label_how_commit_code: How to commit code
label_how_commit_code_chinese: Chinese label_how_commit_code_chinese: Chinese
label_welcome_leave_message: Hi!The platform is currently in beta version.If you have any comments and suggestions, please label_welcome_leave_message: Hi!The platform is currently in beta version.If you have any comments and suggestions, please

@ -196,6 +196,9 @@ zh:
error_complete_occupation: "请您填写工作单位,否则本系统的部分功能将无法正常使用。" error_complete_occupation: "请您填写工作单位,否则本系统的部分功能将无法正常使用。"
error_create_gitlab_user: "创建Gitlab用户失败!可能已存在指定的用户名或邮件名。"
error_create_gitlab_project: "创建Gitlab项目失败!指定用户可能已拥有指定的Gitlab项目。"
error_class_period_only_num: "课程学时只能为数字" error_class_period_only_num: "课程学时只能为数字"
error_can_t_load_default_data: "无法载入默认设置:%{value}" error_can_t_load_default_data: "无法载入默认设置:%{value}"
error_scm_not_found: "版本库中不存在该条目和(或)其修订版本。" error_scm_not_found: "版本库中不存在该条目和(或)其修订版本。"
@ -1563,6 +1566,9 @@ zh:
label_have_message : 》有新的留言 label_have_message : 》有新的留言
label_all_revisions: 所有版本: label_all_revisions: 所有版本:
label_upassword_info: 该密码在项目组内可共享 label_upassword_info: 该密码在项目组内可共享
label_gitlab_account: 用户登录Gitlab的账号推荐使用当前用户
label_gitlab_email: 用户登录Gitlab的邮件推荐使用当前用户邮件
label_gitlab_password: 用户登录Gitlab的密码推荐使用当前用户密码
label_how_commit_code: 查看如何提交代码: label_how_commit_code: 查看如何提交代码:
label_how_commit_code_chinese: 中文 label_how_commit_code_chinese: 中文
# modified by bai # modified by bai

@ -251,6 +251,10 @@ course_domain:
default: course.trustie.net default: course.trustie.net
repository_domain: repository_domain:
default: repository.trustie.net default: repository.trustie.net
gitlab_login_user:
default: admin@local.host
gitlab_login_password:
default: 123456
plugin_redmine_ckeditor: plugin_redmine_ckeditor:
serialized: true serialized: true
default: --- !ruby/hash:ActiveSupport::HashWithIndifferentAccess default: --- !ruby/hash:ActiveSupport::HashWithIndifferentAccess

Loading…
Cancel
Save