可以通过gitlab创建项目
This commit is contained in:
parent
65e6444272
commit
11d1cac40d
|
@ -38,7 +38,8 @@ class ApplicationController < ActionController::Base
|
|||
protect_from_forgery
|
||||
def handle_unverified_request
|
||||
super
|
||||
cookies.delete(autologin_cookie_name)
|
||||
raise(ActionController::InvalidAuthenticityToken)
|
||||
# cookies.delete(autologin_cookie_name)
|
||||
end
|
||||
|
||||
before_filter :find_first_page
|
||||
|
|
|
@ -115,74 +115,34 @@ update
|
|||
}
|
||||
|
||||
def create
|
||||
if params[:repository_scm].to_s == 'Gitlab'
|
||||
# add by nwb
|
||||
# 增加对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
|
||||
redirect_to settings_project_url(@project, :tab => 'repositories')
|
||||
else
|
||||
redirect_to settings_project_url(@project, :tab => 'repositories')
|
||||
end
|
||||
else # 原逻辑
|
||||
##xianbo
|
||||
@root_path=RepositoriesHelper::ROOT_PATH
|
||||
@repository_name=User.current.login.to_s+"/"+params[:repository][:identifier]+".git"
|
||||
@project_path=@root_path+"htdocs/"+@repository_name
|
||||
@repository_tag=params[:repository][:upassword] || params[:repository][:password]
|
||||
@repo_name=User.current.login.to_s+"_"+params[:repository][:identifier]
|
||||
logger.info "htpasswd -mb "+@root_path+"htdocs/user.passwd "+@repo_name+": "+@repository_tag
|
||||
logger.info "the value of create repository"+@root_path+": "+@repository_name+": "+@project_path+": "+@repo_name
|
||||
attrs = pickup_extra_info
|
||||
if((@repository_tag!="")&¶ms[:repository_scm]=="Git")
|
||||
params[:repository][:url]=@project_path
|
||||
end
|
||||
###xianbo
|
||||
@repository = Repository.factory(params[:repository_scm])
|
||||
@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(params[:repository_scm]=="Git")
|
||||
system "htpasswd -mb "+@root_path+"htdocs/user.passwd "+@repo_name+" "+@repository_tag
|
||||
system "echo -e '"+@repo_name+"-write:"+
|
||||
" "+@repo_name+"' >> "+@root_path+"htdocs/group.passwd"
|
||||
system "mkdir "+@root_path+"htdocs/"+User.current.login.to_s
|
||||
system "git init --bare "+@project_path
|
||||
system "mv "+@project_path+"/hooks/post-update{.sample,}"
|
||||
system "chmod a+x "+@project_path+"/hooks/post-update"
|
||||
system "echo -e 'Allow from all \n Order Deny,Allow \n "+
|
||||
"<Limit PUT POST DELETE PROPPATCH MKCOL COPY MOVE LOCK UNLOCK> \n"+
|
||||
"Require group "+@repo_name+"-write \n "+
|
||||
"</Limit> \n ' >> "+
|
||||
@root_path+"htdocs/"+ @repository_name+"/.htaccess"
|
||||
system "cd "+@project_path+" ;git update-server-info"
|
||||
|
||||
File.open(@project_path+"/hooks/post-update", "w+") do |f|
|
||||
f.write(HOOK_TEMPLATE)
|
||||
end
|
||||
|
||||
@repository.update_attributes(:login => User.current.login.to_s)
|
||||
end
|
||||
redirect_to settings_project_url(@project, :tab => 'repositories',:repository_error_message=>@repository.errors.full_messages)
|
||||
else if(@repository_tag.blank?)
|
||||
#render :action => 'newrepo', :layout =>'base_projects'
|
||||
redirect_to settings_project_url(@project, :tab => 'repositories',:repository => "pswd_is_null",:repository_error_message=>@repository.errors.full_messages)
|
||||
else
|
||||
redirect_to settings_project_url(@project, :tab => 'repositories',:repository => @repository,:repository_error_message=>@repository.errors.full_messages)
|
||||
end
|
||||
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
|
||||
@repository.type = 'Repository::Gitlab'
|
||||
@repository.url = @repository.identifier
|
||||
if request.post? && @repository.save
|
||||
g = ::Gitlab.client
|
||||
gid = @project.owner.gid
|
||||
gproject = g.create_project(@repository.identifier,
|
||||
path: @repository.identifier,
|
||||
description: @project.description,
|
||||
wiki_enabled: false,
|
||||
wall_enabled: false,
|
||||
issues_enabled: false,
|
||||
snippets_enabled: false,
|
||||
public: false,
|
||||
user_id: gid
|
||||
)
|
||||
@project.gpid = gproject.id
|
||||
@project.save!
|
||||
|
||||
redirect_to settings_project_url(@project, :tab => 'repositories')
|
||||
else
|
||||
redirect_to settings_project_url(@project, :tab => 'repositories',:repository_error_message=>@repository.errors.full_messages)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -266,7 +226,7 @@ update
|
|||
end
|
||||
end
|
||||
|
||||
unless @repository && @repository.type == 'Repository::Gitlab'
|
||||
unless @repository.gitlab?
|
||||
# redirect_to to_gitlab_project_repository_path(@project, @repository)
|
||||
render :to_gitlab
|
||||
return
|
||||
|
|
|
@ -57,6 +57,11 @@ class Repository < ActiveRecord::Base
|
|||
safe_attributes 'url',
|
||||
:if => lambda {|repository, user| repository.new_record?}
|
||||
|
||||
|
||||
def gitlab?
|
||||
self.type == 'Repository::Gitlab'
|
||||
end
|
||||
|
||||
def repo_create_validation
|
||||
unless Setting.enabled_scm.include?(self.class.name.demodulize)
|
||||
errors.add(:type, :invalid)
|
||||
|
|
|
@ -73,13 +73,6 @@
|
|||
<span class="c_grey"><%= l(:text_scm_command_not_available) %></span>
|
||||
<% end %>
|
||||
</li>
|
||||
|
||||
<% unless judge_main_repository(@project) %>
|
||||
<li>
|
||||
<label class="label02"><%=l(:field_repository_is_default)%>:</label>
|
||||
<%= f.check_box :is_default, :label => "", :no_label => true %></p>
|
||||
</li>
|
||||
<% end %>
|
||||
<li >
|
||||
<input type="text" style="display: none"/> <!--阻止表单自动填充 -->
|
||||
<input type="password" style="display: none"/> <!--阻止表单自动填充 -->
|
||||
|
@ -89,11 +82,6 @@
|
|||
<span class="c_grey"><%=l(:text_length_between,:min=>1,:max=>254)<<l(:text_project_identifier_info) %></span>
|
||||
<% end %>
|
||||
</li>
|
||||
<li >
|
||||
<label class="label02"><span class="c_red">*</span><%=l(:label_password)%></label>
|
||||
<%= f.password_field :upassword, :label=> "", :no_label => true%>
|
||||
<span class="c_grey"><%= l(:label_upassword_info)%></span>
|
||||
</li>
|
||||
<div class="cl"></div>
|
||||
</ul>
|
||||
<a href="#" onclick="$('#repository-form').submit();" class="blue_btn fl ml110"><%=l(:button_save)%></a>
|
||||
|
|
|
@ -31,12 +31,7 @@
|
|||
<%= f.text_field :login, :size => 30 %>
|
||||
<input type="text" hidden="hidden">
|
||||
</p>
|
||||
<p>
|
||||
<%= f.password_field :password, :size => 30, :name => 'ignore',
|
||||
:value => ((@repository.new_record? || @repository.password.blank?) ? '' : ('x'*15)),
|
||||
:onfocus => "this.value=''; this.name='repository[password]';",
|
||||
:onchange => "this.name='repository[password]';" %>
|
||||
</p>
|
||||
|
||||
</div>
|
||||
<!--Ended by tanxianbo-->
|
||||
<p>
|
||||
|
|
|
@ -26,7 +26,6 @@ border:none
|
|||
<em class="info error"><%= l(:text_scm_command_not_available) %></em>
|
||||
<% end %>
|
||||
</p>
|
||||
<p><%= f.check_box :is_default, :label => :field_repository_is_default %></p>
|
||||
|
||||
<p>
|
||||
<input id="googleinputcache" size="30" type="text">
|
||||
|
@ -36,8 +35,6 @@ border:none
|
|||
<%= l(:text_repository_identifier_info).html_safe %></em>
|
||||
<% end %></p>
|
||||
<!-- <p><%#= f.text_field :url, :size => 60, :required => true,:readonly=>true, :class=>'textbg'%></p> -->
|
||||
<p><%= f.password_field :upassword, :required =>true, :label=> :field_password %>
|
||||
<em class="info"><%= l(:label_upassword_info)%></em></p>
|
||||
</div>
|
||||
<p>
|
||||
<%= submit_tag(@repository.new_record? ? l(:button_create) : l(:button_save)) %>
|
||||
|
|
|
@ -0,0 +1,37 @@
|
|||
#coding=utf-8
|
||||
|
||||
module Trustie
|
||||
module Gitlab
|
||||
module Helper
|
||||
def change_password(uid, en_pwd, salt)
|
||||
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 add_user(user)
|
||||
u = nil
|
||||
begin
|
||||
u = self.g.get("/users?search=#{user.mail}").first
|
||||
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)
|
||||
## gitlab unimplement
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
|
@ -14,27 +14,41 @@ module Trustie
|
|||
end
|
||||
|
||||
def change_gitlab_member
|
||||
if self.member.project_id == 2
|
||||
if isGitlabProject?
|
||||
@g ||= ::Gitlab.client
|
||||
@g.edit_team_member(11, self.member.user.gid, self.role.to_gitlab_role )
|
||||
@g.edit_team_member(project.gpid, self.member.user.gid, self.role.to_gitlab_role )
|
||||
end
|
||||
end
|
||||
|
||||
def add_gitlab_member
|
||||
if self.member.project_id == 2
|
||||
if isGitlabProject?
|
||||
@g ||= ::Gitlab.client
|
||||
@g.add_team_member(11, self.member.user.gid, self.role.to_gitlab_role )
|
||||
@g.add_team_member(project.gpid, self.member.user.gid, self.role.to_gitlab_role )
|
||||
end
|
||||
end
|
||||
|
||||
def delete_gitlab_member
|
||||
if member.roles.count <=1
|
||||
if self.member.project_id == 2
|
||||
@g ||= ::Gitlab.client
|
||||
@g.remove_team_member(11, self.member.user.gid)
|
||||
if isGitlabProject?
|
||||
if member.roles.count <=1
|
||||
@g ||= ::Gitlab.client
|
||||
@g.remove_team_member(project.gpid, self.member.user.gid)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
def project
|
||||
self.member.project
|
||||
end
|
||||
|
||||
def repository
|
||||
project.repository
|
||||
end
|
||||
|
||||
def isGitlabProject?
|
||||
repository && repository.gitlab?
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -0,0 +1,37 @@
|
|||
#coding=utf-8
|
||||
#
|
||||
#
|
||||
require_relative 'helper'
|
||||
module Trustie
|
||||
module Gitlab
|
||||
module ManageUser
|
||||
include Helper
|
||||
|
||||
def self.included(base)
|
||||
base.class_eval {
|
||||
before_create :add_gitlab_user
|
||||
before_destroy :delete_gitlab_user
|
||||
before_save :change_gitlab_user
|
||||
}
|
||||
end
|
||||
|
||||
def add_gitlab_user
|
||||
add_user(self)
|
||||
end
|
||||
|
||||
def delete_gitlab_user
|
||||
del_user(self)
|
||||
end
|
||||
|
||||
def change_gitlab_user
|
||||
change_password(self.gid, self.hashed_password, self.salt)
|
||||
end
|
||||
|
||||
private
|
||||
def g
|
||||
@g ||= ::Gitlab.client
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,3 +1,7 @@
|
|||
#coding=utf-8
|
||||
|
||||
require_relative 'helper'
|
||||
|
||||
module Trustie
|
||||
module Gitlab
|
||||
module UserLevel
|
||||
|
@ -10,33 +14,17 @@ module Trustie
|
|||
|
||||
class Sync
|
||||
attr :g
|
||||
include Helper
|
||||
|
||||
def initialize
|
||||
@g = ::Gitlab.client
|
||||
end
|
||||
|
||||
def change_password(uid, en_pwd, salt)
|
||||
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 sync_user(user)
|
||||
begin
|
||||
u = self.g.get("/users?search=#{user.mail}").first
|
||||
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
|
||||
user.save!
|
||||
puts "create user #{user.login}"
|
||||
end
|
||||
change_password(u.id, user.hashed_password, user.salt)
|
||||
rescue => e
|
||||
puts e
|
||||
end
|
||||
u = add_user(user)
|
||||
user.save! if u
|
||||
end
|
||||
|
||||
|
||||
def sync_project(project, opt={})
|
||||
gid = project.owner.gid
|
||||
raise "unknow gid" unless gid
|
||||
|
@ -48,7 +36,6 @@ module Trustie
|
|||
if opt[:password]
|
||||
import_url.sub('@', ":#{opt[:password]}@")
|
||||
end
|
||||
|
||||
|
||||
# import url http://xianbo_trustie2:1234@repository.trustie.net/xianbo/trustie2.git
|
||||
# can use password
|
||||
|
@ -80,7 +67,7 @@ module Trustie
|
|||
|
||||
def remove_project
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
end
|
Loading…
Reference in New Issue