课程资源文件密级BUG修正

This commit is contained in:
nwb 2014-07-14 15:15:28 +08:00
parent 0950ac2329
commit 2a1a051362
4 changed files with 69 additions and 51 deletions

View File

@ -92,57 +92,74 @@ class RepositoriesController < ApplicationController
end
def create
##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]
@repo_name=User.current.login.to_s+"_"+params[:repository][:identifier]
logger.info "htpasswd -mb "+@root_path+"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!="")&&params[:repository_scm]=="Git")
if params[:repository_scm].to_s == 'Gitlab'
# add by nwb
# 增加对gitlab版本库的支持
attrs = pickup_extra_info
@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
redirect_to settings_project_path(@project, :tab => 'repositories')
else
render :action => 'new'
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]
@repo_name=User.current.login.to_s+"_"+params[:repository][:identifier]
logger.info "htpasswd -mb "+@root_path+"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!="")&&params[: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
#by xianbo
@repository.project = @project
if request.post? && @repository.save
if(params[:repository_scm]=="Git")
system "htpasswd -mb "+@root_path+"user.passwd "+@repo_name+" "+@repository_tag
system "echo -e '"+@repo_name+"-write:"+
" "+@repo_name+"' >> "+@root_path+"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"
# if(create_repo_file&&create_passwd&&create_group&&init_repository&&add_privilege&&init_server_info)
# else
# logger.info "An error occured when authenticating "+"create passwd"+@creat_passwd+"create_group"+
# crate_group+"create repository file "+create_repo_file+"init repository"+init_repostory+
# "aad privilege to rpository"+add_privilege+"init server infos"+init_server_info
# end
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
#by xianbo
@repository.project = @project
if request.post? && @repository.save
if(params[:repository_scm]=="Git")
system "htpasswd -mb "+@root_path+"user.passwd "+@repo_name+" "+@repository_tag
system "echo -e '"+@repo_name+"-write:"+
" "+@repo_name+"' >> "+@root_path+"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"
# if(create_repo_file&&create_passwd&&create_group&&init_repository&&add_privilege&&init_server_info)
# else
# logger.info "An error occured when authenticating "+"create passwd"+@creat_passwd+"create_group"+
# crate_group+"create repository file "+create_repo_file+"init repository"+init_repostory+
# "aad privilege to rpository"+add_privilege+"init server infos"+init_server_info
# end
@repository.update_attributes(:login => User.current.login.to_s)
end
redirect_to settings_project_path(@project, :tab => 'repositories')
else if(@repository_tag)
render :action => 'newrepo', :layout =>'base_projects'
else
render :action => 'new', :layout =>'base_projects'
end
redirect_to settings_project_path(@project, :tab => 'repositories')
else if(@repository_tag)
render :action => 'newrepo', :layout =>'base_projects'
else
render :action => 'new', :layout =>'base_projects'
end
end
end
end
end
def edit

View File

@ -35,7 +35,7 @@
</tr>
<% end -%>
<% container.attachments.each do |file| %>
<%if file.is_public == 0 && !User.current.member_of?(@project)%>
<%if file.is_public == 0 && !User.current.member_of_course?(@course)%>
<%next%>
<%end%>
<tr class="file <%= cycle("odd", "odd") %>">

View File

@ -28,7 +28,7 @@
<% @containers.each do |container| %>
<% next if container.attachments.empty? -%>
<% container.attachments.each do |file| %>
<% if file.is_public == 0 && !User.current.member_of?(@project) %>
<% if file.is_public == 0 && !User.current.member_of_course?(@course) %>
<% next %>
<% end %>
<% if isTypeOk(file, selAttachType, selContentType) %>

View File

@ -11,7 +11,7 @@
#
# It's strongly recommended to check this file into your version control system.
ActiveRecord::Schema.define(:version => 20140711012924) do
ActiveRecord::Schema.define(:version => 20140714021812) do
create_table "activities", :force => true do |t|
t.integer "act_id", :null => false
@ -379,6 +379,7 @@ ActiveRecord::Schema.define(:version => 20140711012924) 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"