Merge branch 'gitolite'
This commit is contained in:
commit
e14a0eb8d0
28 changed files with 283 additions and 152 deletions
|
@ -3,8 +3,8 @@ class ApplicationController < ActionController::Base
|
|||
protect_from_forgery
|
||||
helper_method :abilities, :can?
|
||||
|
||||
rescue_from Gitosis::AccessDenied do |exception|
|
||||
render :file => File.join(Rails.root, "public", "gitosis_error"), :layout => false
|
||||
rescue_from Gitlabhq::Gitolite::AccessDenied do |exception|
|
||||
render :file => File.join(Rails.root, "public", "githost_error"), :layout => false
|
||||
end
|
||||
|
||||
layout :layout_by_resource
|
||||
|
@ -70,7 +70,7 @@ class ApplicationController < ActionController::Base
|
|||
end
|
||||
|
||||
def require_non_empty_project
|
||||
redirect_to @project unless @project.repo_exists?
|
||||
redirect_to @project unless @project.repo_exists? && @project.has_commits?
|
||||
end
|
||||
|
||||
def respond_with_notes
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
class ErrorsController < ApplicationController
|
||||
def gitosis
|
||||
render :file => File.join(Rails.root, "public", "gitosis_error"), :layout => false
|
||||
def githost
|
||||
render :file => File.join(Rails.root, "public", "githost_error"), :layout => false
|
||||
end
|
||||
end
|
||||
|
|
|
@ -8,7 +8,7 @@ class ProjectsController < ApplicationController
|
|||
before_filter :add_project_abilities
|
||||
before_filter :authorize_read_project!, :except => [:index, :new, :create]
|
||||
before_filter :authorize_admin_project!, :only => [:edit, :update, :destroy]
|
||||
before_filter :require_non_empty_project, :only => [:blob, :tree]
|
||||
before_filter :require_non_empty_project, :only => [:blob, :tree, :graph]
|
||||
before_filter :load_refs, :only => :tree # load @branch, @tag & @ref
|
||||
|
||||
def index
|
||||
|
@ -42,8 +42,8 @@ class ProjectsController < ApplicationController
|
|||
format.js
|
||||
end
|
||||
end
|
||||
rescue Gitosis::AccessDenied
|
||||
render :js => "location.href = '#{errors_gitosis_path}'" and return
|
||||
rescue Gitlabhq::Gitolite::AccessDenied
|
||||
render :js => "location.href = '#{errors_githost_path}'" and return
|
||||
rescue StandardError => ex
|
||||
@project.errors.add(:base, "Cant save project. Please try again later")
|
||||
respond_to do |format|
|
||||
|
@ -65,7 +65,7 @@ class ProjectsController < ApplicationController
|
|||
end
|
||||
|
||||
def show
|
||||
return render "projects/empty" unless @project.repo_exists?
|
||||
return render "projects/empty" unless @project.repo_exists? && @project.has_commits?
|
||||
limit = (params[:limit] || 20).to_i
|
||||
@activities = @project.cached_updates(limit)
|
||||
end
|
||||
|
|
|
@ -1,14 +1,15 @@
|
|||
class RefsController < ApplicationController
|
||||
before_filter :project
|
||||
before_filter :ref
|
||||
before_filter :define_tree_vars, :only => [:tree, :blob]
|
||||
layout "project"
|
||||
|
||||
# Authorize
|
||||
before_filter :add_project_abilities
|
||||
before_filter :authorize_read_project!
|
||||
before_filter :require_non_empty_project
|
||||
|
||||
before_filter :ref
|
||||
before_filter :define_tree_vars, :only => [:tree, :blob]
|
||||
layout "project"
|
||||
|
||||
def switch
|
||||
new_path = if params[:destination] == "tree"
|
||||
tree_project_ref_path(@project, params[:ref])
|
||||
|
@ -51,6 +52,8 @@ class RefsController < ApplicationController
|
|||
@commit = project.commit(@ref)
|
||||
@tree = Tree.new(@commit.tree, project, @ref, params[:path])
|
||||
@tree = TreeDecorator.new(@tree)
|
||||
rescue
|
||||
return render_404
|
||||
end
|
||||
|
||||
def ref
|
||||
|
|
|
@ -11,29 +11,29 @@ class Key < ActiveRecord::Base
|
|||
:length => { :within => 0..5000 }
|
||||
|
||||
before_save :set_identifier
|
||||
after_save :update_gitosis
|
||||
after_destroy :gitosis_delete_key
|
||||
after_save :update_repository
|
||||
after_destroy :repository_delete_key
|
||||
|
||||
def set_identifier
|
||||
self.identifier = "#{user.identifier}_#{Time.now.to_i}"
|
||||
end
|
||||
|
||||
def update_gitosis
|
||||
Gitosis.new.configure do |c|
|
||||
def update_repository
|
||||
Gitlabhq::GitHost.system.new.configure do |c|
|
||||
c.update_keys(identifier, key)
|
||||
|
||||
projects.each do |project|
|
||||
c.update_project(project.path, project.gitosis_writers)
|
||||
c.update_project(project.path, project.repository_writers)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def gitosis_delete_key
|
||||
Gitosis.new.configure do |c|
|
||||
def repository_delete_key
|
||||
Gitlabhq::GitHost.system.new.configure do |c|
|
||||
c.delete_key(identifier)
|
||||
|
||||
projects.each do |project|
|
||||
c.update_project(project.path, project.gitosis_writers)
|
||||
c.update_project(project.path, project.repository_writers)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -40,8 +40,8 @@ class Project < ActiveRecord::Base
|
|||
validate :check_limit
|
||||
validate :repo_name
|
||||
|
||||
after_destroy :destroy_gitosis_project
|
||||
after_save :update_gitosis_project
|
||||
after_destroy :destroy_repository
|
||||
after_save :update_repository
|
||||
|
||||
attr_protected :private_flag, :owner_id
|
||||
|
||||
|
@ -54,8 +54,8 @@ class Project < ActiveRecord::Base
|
|||
delegate :repo,
|
||||
:url_to_repo,
|
||||
:path_to_repo,
|
||||
:update_gitosis_project,
|
||||
:destroy_gitosis_project,
|
||||
:update_repository,
|
||||
:destroy_repository,
|
||||
:tags,
|
||||
:repo_exists?,
|
||||
:commit,
|
||||
|
@ -95,6 +95,10 @@ class Project < ActiveRecord::Base
|
|||
notes.where(:noteable_id => commit.id, :noteable_type => "Commit")
|
||||
end
|
||||
|
||||
def has_commits?
|
||||
!!commit
|
||||
end
|
||||
|
||||
def add_access(user, *access)
|
||||
opts = { :user => user }
|
||||
access.each { |name| opts.merge!(name => true) }
|
||||
|
@ -109,7 +113,7 @@ class Project < ActiveRecord::Base
|
|||
@writers ||= users_projects.includes(:user).where(:write => true).map(&:user)
|
||||
end
|
||||
|
||||
def gitosis_writers
|
||||
def repository_writers
|
||||
keys = Key.joins({:user => :users_projects}).where("users_projects.project_id = ? AND users_projects.write = ?", id, true)
|
||||
keys.map(&:identifier)
|
||||
end
|
||||
|
@ -180,8 +184,8 @@ class Project < ActiveRecord::Base
|
|||
end
|
||||
|
||||
def repo_name
|
||||
if path == "gitosis-admin"
|
||||
errors.add(:path, " like 'gitosis-admin' is not allowed")
|
||||
if path == "gitolite-admin"
|
||||
errors.add(:path, " like 'gitolite-admin' is not allowed")
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
require File.join(Rails.root, "lib", "gitlabhq", "git_host")
|
||||
|
||||
class Repository
|
||||
attr_accessor :project
|
||||
|
||||
|
@ -22,25 +24,21 @@ class Repository
|
|||
end
|
||||
|
||||
def url_to_repo
|
||||
if !GITOSIS["port"] or GITOSIS["port"] == 22
|
||||
"#{GITOSIS["git_user"]}@#{GITOSIS["host"]}:#{path}.git"
|
||||
else
|
||||
"ssh://#{GITOSIS["git_user"]}@#{GITOSIS["host"]}:#{GITOSIS["port"]}/#{path}.git"
|
||||
end
|
||||
Gitlabhq::GitHost.url_to_repo(path)
|
||||
end
|
||||
|
||||
def path_to_repo
|
||||
GITOSIS["base_path"] + path + ".git"
|
||||
GIT_HOST["base_path"] + path + ".git"
|
||||
end
|
||||
|
||||
def update_gitosis_project
|
||||
Gitosis.new.configure do |c|
|
||||
c.update_project(path, project.gitosis_writers)
|
||||
def update_repository
|
||||
Gitlabhq::GitHost.system.new.configure do |c|
|
||||
c.update_project(path, project.repository_writers)
|
||||
end
|
||||
end
|
||||
|
||||
def destroy_gitosis_project
|
||||
Gitosis.new.configure do |c|
|
||||
def destroy_repository
|
||||
Gitlabhq::GitHost.system.new.configure do |c|
|
||||
c.destroy_project(@project)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -4,7 +4,7 @@ class UsersProject < ActiveRecord::Base
|
|||
|
||||
attr_protected :project_id, :project
|
||||
|
||||
after_commit :update_gitosis_project
|
||||
after_commit :update_repository
|
||||
|
||||
validates_uniqueness_of :user_id, :scope => [:project_id]
|
||||
validates_presence_of :user_id
|
||||
|
@ -13,9 +13,9 @@ class UsersProject < ActiveRecord::Base
|
|||
|
||||
delegate :name, :email, :to => :user, :prefix => true
|
||||
|
||||
def update_gitosis_project
|
||||
def update_repository
|
||||
Gitosis.new.configure do |c|
|
||||
c.update_project(project.path, project.gitosis_writers)
|
||||
c.update_project(project.path, project.repository)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -20,13 +20,13 @@
|
|||
%tr
|
||||
%td
|
||||
.left= f.label :path
|
||||
%cite.right= "git@#{GITOSIS["host"]}:"
|
||||
%cite.right= "git@#{GIT_HOST["host"]}:"
|
||||
%td
|
||||
= f.text_field :path, :placeholder => "example_project", :disabled => !@project.new_record?
|
||||
%tr
|
||||
%td
|
||||
.left= f.label :code
|
||||
%cite.right= "http://#{GITOSIS["host"]}/"
|
||||
%cite.right= "http://#{GIT_HOST["host"]}/"
|
||||
%td= f.text_field :code, :placeholder => "example"
|
||||
|
||||
%tr
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue