refcatoring. cleaning after gitosis
This commit is contained in:
parent
8134fe0efe
commit
bdc658095c
13 changed files with 58 additions and 124 deletions
|
@ -3,8 +3,8 @@ class ApplicationController < ActionController::Base
|
|||
protect_from_forgery
|
||||
helper_method :abilities, :can?
|
||||
|
||||
rescue_from Gitlabhq::Gitosis::AccessDenied, Gitlabhq::Gitolite::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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -42,8 +42,8 @@ class ProjectsController < ApplicationController
|
|||
format.js
|
||||
end
|
||||
end
|
||||
rescue Gitlabhq::Gitosis::AccessDenied, Gitlabhq::Gitolite::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|
|
||||
|
|
|
@ -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
|
||||
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
|
||||
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,
|
||||
|
@ -113,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
|
||||
|
@ -184,8 +184,8 @@ class Project < ActiveRecord::Base
|
|||
end
|
||||
|
||||
def repo_name
|
||||
if path == "gitosis-admin" && path == "gitolite-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
|
||||
|
||||
|
|
|
@ -24,24 +24,20 @@ class Repository
|
|||
end
|
||||
|
||||
def url_to_repo
|
||||
if !GIT_HOST["port"] or GIT_HOST["port"] == 22
|
||||
"#{GIT_HOST["git_user"]}@#{GIT_HOST["host"]}:#{path}.git"
|
||||
else
|
||||
"ssh://#{GIT_HOST["git_user"]}@#{GIT_HOST["host"]}:#{GIT_HOST["port"]}/#{path}.git"
|
||||
end
|
||||
Gitlabhq::GitHost.url_to_repo(path)
|
||||
end
|
||||
|
||||
def path_to_repo
|
||||
GIT_HOST["base_path"] + path + ".git"
|
||||
end
|
||||
|
||||
def update_gitosis_project
|
||||
def update_repository
|
||||
Gitlabhq::GitHost.system.new.configure do |c|
|
||||
c.update_project(path, project.gitosis_writers)
|
||||
c.update_project(path, project.repository_writers)
|
||||
end
|
||||
end
|
||||
|
||||
def destroy_gitosis_project
|
||||
def destroy_repository
|
||||
Gitlabhq::GitHost.system.new.configure do |c|
|
||||
c.destroy_project(@project)
|
||||
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
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue