frok功能开发--权限还未完成

This commit is contained in:
huang 2015-11-13 17:30:14 +08:00
parent af70dc0ca3
commit a40e5c5b54
8 changed files with 103 additions and 7 deletions

View File

@ -31,10 +31,10 @@ class RepositoriesController < ApplicationController
default_search_scope :changesets
before_filter :find_project_by_project_id, :only => [:new, :create, :newrepo]
before_filter :find_repository, :only => [:edit, :update, :destroy, :committers]
before_filter :find_repository, :only => [:edit, :update, :destroy, :committers, :forked]
before_filter :find_project_repository, :except => [:new, :create, :newcreate, :edit, :update, :destroy, :committers, :newrepo,:to_gitlab]
before_filter :find_changeset, :only => [:revision, :add_related_issue, :remove_related_issue]
before_filter :authorize , :except => [:newrepo,:newcreate,:fork, :to_gitlab]
before_filter :authorize , :except => [:newrepo,:newcreate,:fork, :to_gitlab, :forked]
accept_rss_auth :revisions
# hidden repositories filter // 隐藏代码过滤器
before_filter :check_hidden_repo, :only => [:show, :stats, :revisions, :revision, :diff ]
@ -63,6 +63,72 @@ class RepositoriesController < ApplicationController
end
def forked
# REDO: 那些人有权限forked项目
# g = Gitlab.client
# gproject = g.post ("/projects/fork/#{@project.gpid}")
if gproject
copy_project(@project, gproject)
end
# render :layout => 'base_projects'
end
# copy a project for fork
def copy_project(project, gproject)
project = Project.new
project.name = @project.name
project.is_public = @project.is_public
project.status = @project.status
project.hidden_repo = @project.hidden_repo
project.user_id = User.current.id
project.project_type = 0
project.project_new_type = @project.project_new_type
project.gpid = gproject.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])
project_info = ProjectInfo.new(:user_id => User.current.id, :project_id => project.id)
user_grades = UserGrade.create(:user_id => User.current.id, :project_id => project.id)
Rails.logger.debug "UserGrade created: #{user_grades.to_json}"
project_status = ProjectStatus.create(:project_id => @project.id, :watchers_count => 0, :changesets_count => 0, :project_type => @project.project_type,:grade => 0)
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 {
flash[:notice] = l(:notice_successful_create)
if params[:continue]
attrs = {:parent_id => project.parent_id}.reject {|k,v| v.nil?}
redirect_to new_project_url(attrs, :course => '0')
else
redirect_to settings_project_url(project)
end
}
format.api { render :action => 'show', :status => :created, :location => url_for(:controller => 'projects', :action => 'show', :id => project.id) }
format.js
end
else
respond_to do |format|
format.html { render :action => 'forked', :layout => 'base_projects'}
format.api { render_validation_errors(@project) }
end
end
end
def copy_repository(project, gproject)
# 避免
if is_sigle_identifier?(project.owner, gproject.name)
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
scm = params[:repository_scm] || (Redmine::Scm::Base.all & Setting.enabled_scm).first

View File

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

View File

@ -40,7 +40,8 @@ class Repository < ActiveRecord::Base
validates_length_of :identifier, :maximum => IDENTIFIER_MAX_LENGTH, :allow_blank => true
validates_presence_of :identifier#, :unless => Proc.new { |r| r.is_default? || r.set_as_default? }
#validates_uniqueness_of :identifier, :scope => :project_id, :allow_blank => true
validates_uniqueness_of :identifier, :allow_blank => true
# 改成同一用户不能有两个相同名字的版本库
# validates_uniqueness_of :identifier, :allow_blank => true
validates_exclusion_of :identifier, :in => %w(show entry raw changes annotate diff show stats graph)
# donwcase letters, digits, dashes, underscores but not digits only
validates_format_of :identifier, :with => /^[a-z0-9_\-]+$/, :allow_blank => true
@ -52,7 +53,8 @@ class Repository < ActiveRecord::Base
'password',
'path_encoding',
'log_encoding',
'is_default'
'is_default',
'type'
safe_attributes 'url',
:if => lambda {|repository, user| repository.new_record?}
@ -63,6 +65,10 @@ class Repository < ActiveRecord::Base
end
def repo_create_validation
# 之所以可以这样改是因为Fork的时候不需要从Trustie创建版本库只需从Gitlab关联即可
if self.class.name.demodulize == "Repository"
return
end
unless Setting.enabled_scm.include?(self.class.name.demodulize)
errors.add(:type, :invalid)
end

View File

@ -1,12 +1,12 @@
<div class="git_usr_title">
<%=link_to @project.owner, user_path(@project.owner), :class => "repository-title-dec" %>
/
<span><%= link_to @repository.identifier.present? ? h(@repository.identifier) : 'root',
{:action => 'show', :id => @project,
:repository_id => @repository.identifier_param,
:path => nil, :rev => @rev },
:class => "repository-title-dec"
%>
/
<%=link_to @project.owner, user_path(@project.owner), :class => "repository-title-dec" %>
</span>
</div>

View File

@ -0,0 +1,10 @@
<div class="project_r_h">
<div class="fl"><h2 class="project_h2_repository"><%= render :partial => 'breadcrumbs', :locals => {:path => @path, :kind => 'dir', :revision => @rev} %></h2></div>
</div>
<%= form_for('forked',:url => {:controller => 'repositories', :action => 'forked'},:method => "post") do |f| %>
<input type="text" name="repo_name"/>
<button type="submit">确定</button>
<% end %>
<%= @project.id %>
<%= @repository.id %>
<%= User.current %>

View File

@ -25,7 +25,7 @@
<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="cl"></div>
<div class="recordBanner mt10">
<% if @changesets && !@changesets.empty? %>

View File

@ -551,6 +551,7 @@ RedmineApp::Application.routes.draw do
# get 'create', :via=>[:get, :post]
end
end
match 'wiki/index', :via => :get
resources :wiki, :except => [:index, :new, :create], :as => 'wiki_page' do
member do
@ -647,6 +648,7 @@ RedmineApp::Application.routes.draw do
get 'projects/:id/repository/changes(/*path(.:ext))', :to => 'repositories#changes'
get 'projects/:id/repository/forked', :to => 'repositories#forked'
get 'projects/:id/repository/revisions', :to => 'repositories#revisions'
get 'projects/:id/repository/revisions/:rev', :to => 'repositories#revision'
get 'projects/:id/repository/revision', :to => 'repositories#revision'