Merge branch 'szzh' into dev_zanle

This commit is contained in:
lizanle 2015-12-04 16:42:02 +08:00
commit 4c00312f45
10 changed files with 96 additions and 46 deletions

View File

@ -374,6 +374,7 @@ class CoursesController < ApplicationController
def settings
if User.current.allowed_to?(:as_teacher,@course)
@select_tab = params[:tab]
@issue_custom_fields = IssueCustomField.sorted.all
@issue_category ||= IssueCategory.new
@member ||= @course.members.new

View File

@ -64,32 +64,53 @@ class RepositoriesController < ApplicationController
end
def forked
# 被forked的标识如果不满足单个用户唯一性则不执行fork
if is_sigle_identifier?(User.current, @repository.identifier)
# 如果当前用户已经fork过该项目不会新fork项目则跳至已fork的项
unless has_forked?(@project, User.current)
project = project_from_current_project(@project.id, User.current.id)
redirect_to project_path(project)
else
# 单个用户只能拥有一个名字一样的版本库否则不能fork
# if is_sigle_identifier?(User.current, @repository.identifier)
# REDO: 那些人有权限forked项目
g = Gitlab.client
gproject = g.post ("/projects/fork/#{@project.gpid}?user_id=#{User.current.gid}")
gproject = g.fork(@project.gpid, User.current.gid)
if gproject
copy_project(@project, gproject)
forked_count = @project.forked_count.to_i + 1
@project.update_attributes(:forked_count => forked_count)
end
else
flash[:notice] = l(:project_gitlab_fork_double_message)
redirect_to settings_project_url(@project, :tab => 'repositories')
# else
# flash[:notice] = l(:project_gitlab_fork_double_message)
# redirect_to settings_project_url(@project, :tab => 'repositories')
# end
end
end
# 判断用户是否已经fork过该项目
def has_forked?(project, user)
projects = Project.where("user_id =?", user)
projects.map(&:forked_from_project_id).detect{|s| s == @project.id}.nil? ? true : false
end
# 获取当前用户fork过的项目
def project_from_current_project(project, user)
project = Project.where("user_id =? and forked_from_project_id =?",user, project).first
end
# copy a project for fork
def copy_project(project, gproject)
def copy_project(tproject, gproject)
project = Project.new
project.name = @project.name
project.is_public = @project.is_public
project.status = @project.status
project.description = @project.description
project.hidden_repo = @project.hidden_repo
project.name = tproject.name
project.is_public = tproject.is_public
project.status = tproject.status
project.description = tproject.description
project.hidden_repo = tproject.hidden_repo
project.user_id = User.current.id
project.project_type = 0
project.project_new_type = @project.project_new_type
project.project_new_type = tproject.project_new_type
project.gpid = gproject.id
project.forked_from_project_id = tproject.id
if project.save
r = Role.givable.find_by_id(Setting.new_project_user_role_id.to_i) || Role.givable.first
m = Member.new(:user => User.current, :roles => [r])
@ -124,16 +145,16 @@ class RepositoriesController < ApplicationController
def copy_repository(project, gproject)
# 避免
if is_sigle_identifier?(project.user_id, gproject.name)
# if is_sigle_identifier?(project.user_id, gproject.name)
repository = Repository.factory('Git')
repository.project_id = project.id
repository.type = 'Repository::Gitlab'
repository.url = gproject.name
repository.identifier = gproject.name
repository = repository.save
else
flash[:notice] = l(:project_gitlab_create_double_message)
end
# else
# flash[:notice] = l(:project_gitlab_create_double_message)
# end
end
def newrepo

View File

@ -1,5 +1,10 @@
<div class="project_r_h">
<h2 class="project_h2"><%= @subPage_title%></h2>
<h2 class="project_h2 fl"><%= @subPage_title%></h2>
<% if User.current.allowed_to?(:as_teacher,@course) %>
<span class="fr f14 fontGrey2" style="height: 40px; line-height: 40px; margin-right: 15px;">
<%=link_to "修改角色", :controller => 'courses', :action => 'settings', :id => @course.id, :tab=>'member' %>
</span>
<% end %>
</div>
<% if @subPage_title == l(:label_student_list)%>
<%= render :partial => 'course_student', :locals => {:members => @members} %>

View File

@ -1,6 +1,13 @@
<div class="project_r_h">
<h2 class="project_h2"><%= l(:label_course_modify_settings)%></h2>
</div>
<script>
$(function(){
<% if @select_tab == 'member'%>
$("#tb_2").click();
<% end %>
})
</script>
<div class="hwork_new">
<div id="tb_" class="hwork_tb_">
<ul>

View File

@ -208,7 +208,7 @@
<div class="cl"></div>
<% unless contributor_course_scor(@course.id).count == 0 %>
<ul class="rankList">
<h4>课程贡献榜</h4>
<h4>课程活跃度</h4>
<% contributor_course_scor(@course.id).each do |contributor_score| %>
<% unless contributor_score.total_score ==0 %>
<li> <a href="javascript:void:(0);"><%=link_to image_tag(url_to_avatar(contributor_score.user), :width => "35", :height => "35", :class=> "rankPortrait"),user_path(contributor_score.user) %></a>

View File

@ -15,7 +15,7 @@
版本库地址:<%= @repos_url %>
<% else %>
版本库地址:<%= h @repository.url %>
<% end %>
<% end %>-
<!-- added by bai -->
<div class="cl"></div>
</div>
@ -25,8 +25,10 @@
<textarea id="copy_rep_content" class="cloneUrl mt5 fl" type="input" placeholder="http://xianbo_trustie2@repository.trustie.net/xianbo/trustie2.git"><%=@repository.type.to_s=="Repository::Gitlab" ? @repos_url.to_s.lstrip : @repository.url %></textarea>
<a href="javascript:void(0);" class="clone_btn mt5" onclick="jsCopy()"><span class="vl_copy" title="点击复制版本库地址"></span></a>
<div class="fl mt5 ml15"><a href="javascript:void(0);" class="vl_btn fb" onclick="zip()"><span class="vl_zip"></span>ZIP</a> </div>
<div class="fr mt5"><a href="javascript:void(0);" class="vl_btn fb" onclick="zip()"><span class="vl_fork"></span>Fork</a> <span href="javascript:void(0);" class="vl_btn_2 fb">0</span> </div>
<!--<div class="fr mt5"><a href="javascript:void(0);" class="vl_btn fb" onclick="zip()"><span class="vl_fork"></span><%= link_to "Fork", :controller => 'repositories', :action => 'forked' %></a> <span href="javascript:void(0);" class="vl_btn_2 fb">0</span> </div>-->
<!--<div class="fr mt5"><a href="javascript:void(0);" class="vl_btn fb" onclick="zip()"><span class="vl_fork"></span>Fork</a> <span href="javascript:void(0);" class="vl_btn_2 fb">0</span> </div>-->
<div class="fr mt5"><span class="vl_fork"></span><%= link_to "Fork", :controller => 'repositories', :action => 'forked'%>
<span href="javascript:void(0);" class="vl_btn_2 fb"><%= @project.forked_count.to_i %></span> </div>
<div class="cl"></div>
<div class="recordBanner mt10">
<% if @changesets && !@changesets.empty? %>

View File

@ -0,0 +1,5 @@
class AddForkedFromProjectIdToProjects < ActiveRecord::Migration
def change
add_column :projects, :forked_from_project_id, :integer
end
end

View File

@ -0,0 +1,5 @@
class AddForkedCountToProjects < ActiveRecord::Migration
def change
add_column :projects, :forked_count, :integer
end
end

View File

@ -11,7 +11,7 @@
#
# It's strongly recommended to check this file into your version control system.
ActiveRecord::Schema.define(:version => 20151203030635) do
ActiveRecord::Schema.define(:version => 20151204062220) do
create_table "activities", :force => true do |t|
t.integer "act_id", :null => false
@ -970,6 +970,7 @@ ActiveRecord::Schema.define(:version => 20151203030635) do
t.integer "course_group_id", :default => 0
end
add_index "members", ["course_id"], :name => "index_members_on_course_id"
add_index "members", ["project_id"], :name => "index_members_on_project_id"
add_index "members", ["user_id", "project_id", "course_id"], :name => "index_members_on_user_id_and_project_id", :unique => true
add_index "members", ["user_id"], :name => "index_members_on_user_id"
@ -1324,6 +1325,8 @@ ActiveRecord::Schema.define(:version => 20151203030635) do
t.integer "organization_id"
t.integer "project_new_type"
t.integer "gpid"
t.integer "forked_from_project_id"
t.integer "forked_count"
end
add_index "projects", ["lft"], :name => "index_projects_on_lft"

View File

@ -241,8 +241,9 @@ class Gitlab::Client
# Forks a project into the user namespace of the authenticated user.
# @param [Integer] - The ID of the project to be forked
def fork(id)
post("/projects/fork/#{id}")
def fork(gpid, gid)
post ("/projects/fork/#{gpid}?user_id=#{gid}")
# post("/projects/fork/#{id}")
end
# Mark this project as forked from the other