报告人员只能克隆,不能提交,其他可以克隆和提交

sw_new_course
guange 10 years ago
parent 8da9805bcc
commit b762ae6bdd

@ -127,19 +127,18 @@ update
end end
else # 原逻辑 else # 原逻辑
##xianbo ##xianbo
params[:repository_scm] = "Git"
@root_path=RepositoriesHelper::ROOT_PATH @root_path=RepositoriesHelper::ROOT_PATH
@repository_name=User.current.login.to_s+"/"+params[:repository][:identifier]+".git" @repository_name=User.current.login.to_s+"/"+params[:repository][:identifier]+".git"
@project_path=@root_path+"htdocs/"+@repository_name @project_path=@root_path+"htdocs/"+@repository_name
@repository_tag=params[:repository][:upassword] || params[:repository][:password] @repository_tag=params[:repository][:upassword] || params[:repository][:password] || '1234'
@repo_name=User.current.login.to_s+"_"+params[:repository][:identifier] @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 "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 logger.info "the value of create repository"+@root_path+": "+@repository_name+": "+@project_path+": "+@repo_name
attrs = pickup_extra_info attrs = pickup_extra_info
if((@repository_tag!="")&&params[:repository_scm]=="Git") params[:repository][:url]=@project_path
params[:repository][:url]=@project_path
end
###xianbo ###xianbo
@repository = Repository.factory(params[:repository_scm]) @repository = Repository.factory(params[:repository_scm]||"Git")
@repository.safe_attributes = params[:repository] @repository.safe_attributes = params[:repository]
if attrs[:attrs_extra].keys.any? if attrs[:attrs_extra].keys.any?
@repository.merge_extra_info(attrs[:attrs_extra]) @repository.merge_extra_info(attrs[:attrs_extra])
@ -270,7 +269,8 @@ update
@course_tag = params[:course] @course_tag = params[:course]
project_path_cut = RepositoriesHelper::PROJECT_PATH_CUT project_path_cut = RepositoriesHelper::PROJECT_PATH_CUT
ip = RepositoriesHelper::REPO_IP_ADDRESS ip = RepositoriesHelper::REPO_IP_ADDRESS
@repos_url = "http://"+@repository.login.to_s+"_"+@repository.identifier.to_s+"@"+ip.to_s+ # @repos_url = "http://"+@repository.login.to_s+"_"+@repository.identifier.to_s+"@"+ip.to_s+
@repos_url = "http://#{Setting.host_name}/#{@repository.login.to_s}/#{@repository.identifier.to_s}.git"
@repository.url.slice(project_path_cut, @repository.url.length).to_s @repository.url.slice(project_path_cut, @repository.url.length).to_s
if @course_tag == 1 if @course_tag == 1
render :action => 'show', :layout => 'base_courses' render :action => 'show', :layout => 'base_courses'

@ -19,7 +19,7 @@
module RepositoriesHelper module RepositoriesHelper
if Rails.env.development? if Rails.env.development?
ROOT_PATH="/tmp/" if Rails.env.development? ROOT_PATH="/private/tmp/"
else else
ROOT_PATH="/home/pdl/redmine-2.3.2-0/apache2/" ROOT_PATH="/home/pdl/redmine-2.3.2-0/apache2/"
end end

@ -62,15 +62,6 @@
<%= labelled_form_for :repository, @repository, :url =>project_repositories_path(@project),:html => {:id => 'repository-form',:method=>"post"} do |f| %> <%= labelled_form_for :repository, @repository, :url =>project_repositories_path(@project),:html => {:id => 'repository-form',:method=>"post"} do |f| %>
<div id="pro_st_edit_ku" class="pro_st_edit_ku"> <div id="pro_st_edit_ku" class="pro_st_edit_ku">
<ul> <ul>
<li >
<label class="label02"><%=l(:label_scm)%></label>
<%= select_tag('repository_scm',
options_for_select(["Git"],@repository.class.name.demodulize),
:data => {:remote => true, :method => 'get'})%>
<% if @repository && ! @repository.class.scm_available %>
<span class="c_grey"><%= l(:text_scm_command_not_available) %></span>
<% end %>
</li>
<% unless judge_main_repository(@project) %> <% unless judge_main_repository(@project) %>
<li> <li>
<label class="label02"><%=l(:field_repository_is_default)%></label> <label class="label02"><%=l(:field_repository_is_default)%></label>
@ -84,14 +75,9 @@
<span class="c_grey"><%=l(:text_length_between,:min=>1,:max=>254)<<l(:text_project_identifier_info) %></span> <span class="c_grey"><%=l(:text_length_between,:min=>1,:max=>254)<<l(:text_project_identifier_info) %></span>
<% end %> <% end %>
</li> </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> <div class="cl"></div>
</ul> </ul>
<a href="#" onclick="$('#repository-form').submit();" class="blue_btn fl ml110"><%=l(:button_save)%></a> <a href="#" onclick="$('#repository-form').submit();" class="blue_btn fl ml110"><%=l(:button_save)%></a>
<a href="<%= settings_project_path(@project, :tab => 'repositories')%>" class="grey_btn fl ml10"><%=l(:button_cancel)%></a> <a href="<%= settings_project_path(@project, :tab => 'repositories')%>" class="grey_btn fl ml10"><%=l(:button_cancel)%></a>
</div><!--pro_st_edit_issues end--> </div><!--pro_st_edit_issues end-->
<% end %> <% end %>

@ -33,8 +33,9 @@
<div id="repos_git_more"> <div id="repos_git_more">
<br> <br>
<div class=" c_dark f14"> <div class=" c_dark f14">
<p color="red">git 克隆和提交的用户名和密码为登录用户名和密码 </p>
<p>项目代码请设置好正确的编码方式utf-8否则中文会出现乱码。</p> <p>项目代码请设置好正确的编码方式utf-8否则中文会出现乱码。</p>
<p>通过cmd命令提示符进入代码对应文件夹的根目录假设当前用户的登录名为user版本库名称为demo需要操作的版本库分支为branch。 <p>通过cmd命令提示符进入代码对应文件夹的根目录
如果是首次提交代码,执行如下命令:</p> 如果是首次提交代码,执行如下命令:</p>
</div> </div>
<div class="repos_explain"> <div class="repos_explain">
@ -45,19 +46,19 @@
<p>git commit -m "first commit"</p> <p>git commit -m "first commit"</p>
<p>git remote add origin <p>git remote add origin
http://user_demo@repository.trustie.net/user/demo.git <%= @repos_url %>
</p> </p>
<p>git config http.postBuffer 524288000 #设置本地post缓存为500MB</p> <p>git config http.postBuffer 524288000 #设置本地post缓存为500MB</p>
<p>git push -u origin branch:branch</p> <p>git push -u origin master</p>
</div> </div>
<!--repos_explain end--> <!--repos_explain end-->
<div class="c_dark f14"> <div class="c_dark f14">
<p>已经有本地库,还没有配置远程地址,打开命令行执行如下:</p> <p>已经有本地库,还没有配置远程地址,打开命令行执行如下:</p>
</div> </div>
<div class="repos_explain"> <div class="repos_explain">
<p>git remote add origin http://user_demo@repository.trustie.net/user/demo.git</p> <p>git remote add origin <%= @repos_url %></p>
<p>git add .</p> <p>git add .</p>
@ -65,14 +66,14 @@
<p>git config http.postBuffer 524288000 #设置本地post缓存为500MB</p> <p>git config http.postBuffer 524288000 #设置本地post缓存为500MB</p>
<p>git push -u origin branch:branch</p> <p>git push -u origin master</p>
</div> </div>
<!--repos_explain end--> <!--repos_explain end-->
<div class="c_dark f14"> <div class="c_dark f14">
<p>已有远程地址,创建一个远程分支,并切换到该分支,打开命令行执行如下:</p> <p>已有远程地址,创建一个远程分支,并切换到该分支,打开命令行执行如下:</p>
</div> </div>
<div class="repos_explain"> <div class="repos_explain">
<p>git clone http://user_demo@repository.trustie.net/user/demo.git</p> <p>git clone <%= @repos_url %></p>
<p>git push</p> <p>git push</p>
@ -86,7 +87,7 @@
</div> </div>
<div class="repos_explain"> <div class="repos_explain">
<p>git remote add trustie <p>git remote add trustie
http://user_demo@repository.trustie.net/user/demo.git <%= @repos_url %>
</p> </p>
<p>git add .</p> <p>git add .</p>

@ -197,7 +197,7 @@ default:
#max_concurrent_ajax_uploads: 2 #max_concurrent_ajax_uploads: 2
#pic_types: "bmp,jpeg,jpg,png,gif" #pic_types: "bmp,jpeg,jpg,png,gif"
repository_root_path: '/Users/guange/repository' repository_root_path: '/tmp/htdocs'
# specific configuration options for production environment # specific configuration options for production environment
# that overrides the default ones # that overrides the default ones

@ -50,7 +50,7 @@ module Grack
return render_method_not_allowed if cmd == 'not_allowed' return render_method_not_allowed if cmd == 'not_allowed'
return render_not_found unless cmd return render_not_found unless cmd
@git = get_git(path) @git = get_git(env["REP_PATH"] || path)
return render_not_found unless git.valid_repo? return render_not_found unless git.valid_repo?
self.method(cmd).call self.method(cmd).call
@ -195,8 +195,8 @@ module Grack
end end
def get_git(path) def get_git(path)
root = @config[:project_root] || Dir.pwd # root = @config[:project_root] || Dir.pwd
path = File.join(root, path) # path = File.join(root, path)
Grack::Git.new(@config[:git_path], path) Grack::Git.new(@config[:git_path], path)
end end

@ -1,9 +1,16 @@
#coding=utf-8
#
require 'rack/auth/basic' require 'rack/auth/basic'
require 'rack/auth/abstract/handler' require 'rack/auth/abstract/handler'
require 'rack/auth/abstract/request' require 'rack/auth/abstract/request'
module Grack module Grack
class Auth < Rack::Auth::Basic class Auth < Rack::Auth::Basic
DOWNLOAD_COMMANDS = %w{ git-upload-pack git-upload-archive }
PUSH_COMMANDS = %w{ git-receive-pack }
attr_accessor :user, :repository
def call(env) def call(env)
@env = env @env = env
@request = Rack::Request.new(env) @request = Rack::Request.new(env)
@ -16,6 +23,7 @@ module Grack
else else
result = if (access = valid?(@auth) and access == true) result = if (access = valid?(@auth) and access == true)
@env['REMOTE_USER'] = @auth.username @env['REMOTE_USER'] = @auth.username
env['REP_PATH'] = repository.root_url
@app.call(env) @app.call(env)
else else
if access == '404' if access == '404'
@ -37,19 +45,59 @@ module Grack
end end
def valid?(auth) def valid?(auth)
self.repository = auth_rep
return "404" unless repository
username, password = auth.credentials
self.user = auth_user(username, password)
return '403' unless user
access = auth_request
puts "access #{access}"
access
end
def auth_rep
rep = nil
match = @request.path_info.match(/(\/.+\.git)\//) match = @request.path_info.match(/(\/.+\.git)\//)
if match if match
rep = Repository.where("root_url like ?", "%#{match[1]}") rep = Repository.where("root_url like ?", "%#{match[1]}").first
return "404" if rep.empty? end
username, password = auth.credentials rep
user, last_login_on = User.try_to_login(username, password) end
return '403' unless user
if user.member_of?(rep.first.project) || user.admin? def auth_user(username, password)
return true u, last_login_on = User.try_to_login(username, password)
unless u && (u.member_of?(repository.project) || u.admin?)
u = nil
end end
u
end
def auth_request
case git_cmd
when *DOWNLOAD_COMMANDS
user != nil
when *PUSH_COMMANDS
unless user
false
else
### 只有Manager和Development才有push权限
repository.project.members.where(user_id: user.id).first.roles.any?{|r| r.name == 'Manager' || r.name == 'Developer'}
end
else
false
end
end
def git_cmd
if @request.get?
@request.params['service']
elsif @request.post?
File.basename(@request.path)
else
nil
end end
false
end end
end# class Auth end# class Auth
end# module Grack end# module Grack

Loading…
Cancel
Save