每个用户不能创建同名版本库

不同的用户可以创建不同版本库
更新fork接口方法
This commit is contained in:
huang 2015-11-13 20:24:30 +08:00
parent a40e5c5b54
commit ddbc9003c2
3 changed files with 48 additions and 32 deletions

View File

@ -64,13 +64,18 @@ class RepositoriesController < ApplicationController
end
def forked
# REDO: 那些人有权限forked项目
# g = Gitlab.client
# gproject = g.post ("/projects/fork/#{@project.gpid}")
if gproject
copy_project(@project, gproject)
# 被forked的标识如果不满足单个用户唯一性则不执行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.id}")
if gproject
copy_project(@project, gproject)
end
else
flash[:notice] = l(:project_gitlab_fork_double_message)
redirect_to settings_project_url(@project, :tab => 'repositories')
end
# render :layout => 'base_projects'
end
# copy a project for fork
@ -79,6 +84,7 @@ class RepositoriesController < ApplicationController
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.user_id = User.current.id
project.project_type = 0
@ -94,7 +100,6 @@ class RepositoriesController < ApplicationController
Rails.logger.debug "ProjectStatus created: #{project_status.to_json}"
project.members << m
project.project_infos << project_info
repository = Repository.create(:project_id => project.id, :url =>'ddd222', :type => 'Repository::Gitlab', :identifier => 'ddd222', :is_default => true)
copy_repository(project, gproject)
respond_to do |format|
format.html {
@ -119,15 +124,16 @@ class RepositoriesController < ApplicationController
def copy_repository(project, gproject)
# 避免
if is_sigle_identifier?(project.owner, 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
repository = Repository.factory('Git')
repository.project_id = project.id
repository.type = 'Repository::Gitlab'
repository.url = gproject.name
repository.identifier = gproject.name
repository = repository.save
end
def newrepo
@ -181,21 +187,27 @@ update
}
def create
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
s = Trustie::Gitlab::Sync.new
s.create_project(@project, @repository)
# 判断版本库创建者是否有同名版本库,避免版本库路径一致问题
unless is_sigle_identifier?(@project.user_id, params[:repository].first[1])
flash[:notice] = l(:project_gitlab_create_double_message)
redirect_to settings_project_url(@project, :tab => 'repositories')
else
redirect_to settings_project_url(@project, :tab => 'repositories',:repository_error_message=>@repository.errors.full_messages)
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
s = Trustie::Gitlab::Sync.new
s.create_project(@project, @repository)
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
end

View File

@ -28,15 +28,17 @@ module RepositoriesHelper
REPO_GITLAB_ADDRESS = "git.trustie.net"
# 某个成员不能拥有同名版本库,不同的成员可以创建同名版本库
def is_sigle_identifier?(user, iden)
projects = Project.where("user_id =?",user)
def is_sigle_identifier?(user_id, iden)
projects = Project.where("user_id =?",user_id)
identifiers = []
projects.each do |project|
# 只针对gitlab类型的git类型的后期清掉
repository = Repository.where("project_id =? and type =?", project.id, "Repository::Gitlab").first
identifiers << repository.identifier
if repository
identifiers << repository.identifier
end
end
identifiers
identifiers.include?(iden) ? false :true
end
def format_revision(revision)

View File

@ -89,6 +89,8 @@ zh:
project_module_repository: 版本库
project_module_create_repository: 创建版本库
project_gitlab_create_repository: 新版本库
project_gitlab_create_double_message: 亲,您已经创建了一个同名的版本库,换个特别点的名字同名的概率就会变小哦~
project_gitlab_fork_double_message: 您已经有了一个相同名字的版本库所以不能fork改版本库~
label_project_more: 更多