From 98241b20e64ac8d5e0afc11e3a8e33f71989c07b Mon Sep 17 00:00:00 2001 From: Pavel Chipiga Date: Fri, 28 Oct 2011 03:04:10 +0300 Subject: [PATCH 01/10] Fix XML RPC. Refs #2136 --- app/models/project.rb | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/app/models/project.rb b/app/models/project.rb index 7afb443c2..0f764721c 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -132,12 +132,21 @@ class Project < ActiveRecord::Base end end - def xml_rpc_destroy - result = BuildServer.delete_project unixname, repository.platform.unixname + def xml_rpc_create + result = BuildServer.create_project unixname, "#{owner.uname}_personal", 'main' if result == BuildServer::SUCCESS return true else - raise "Failed to delete repository #{name} (repo #{repository.name}) inside platform #{repository.platform.name}." + raise "Failed to create project #{name} (repo main) inside platform #{owner.uname}_personal." + end + end + + def xml_rpc_destroy + result = BuildServer.delete_project unixname, "#{owner.uname}_personal" + if result == BuildServer::SUCCESS + return true + else + raise "Failed to delete repository #{name} (repo main) inside platform #{owner.uname}_personal." end end end From ce0625e5d86c30153cd777db5b379430c9dcb0ea Mon Sep 17 00:00:00 2001 From: Pavel Chipiga Date: Fri, 28 Oct 2011 03:19:59 +0300 Subject: [PATCH 02/10] Fix callbacks order. Refs #2136 --- app/models/project.rb | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/app/models/project.rb b/app/models/project.rb index 0f764721c..b417e8372 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -28,11 +28,12 @@ class Project < ActiveRecord::Base scope :by_visibilities, lambda {|v| {:conditions => ['visibility in (?)', v.join(',')]}} scope :addable_to_repository, lambda { |repository_id| where("projects.id NOT IN (SELECT project_to_repositories.project_id FROM project_to_repositories WHERE (project_to_repositories.repository_id != #{ repository_id }))") } - before_create :create_git_repo, :make_owner_rel - before_update :update_git_repo - before_destroy :destroy_git_repo + before_create :make_owner_rel before_create :xml_rpc_create before_destroy :xml_rpc_destroy + before_create :create_git_repo, + before_update :update_git_repo + before_destroy :destroy_git_repo after_create :attach_to_personal_repository def project_versions From 0c9b2f5d846ef1589572ff0e1c23fc268e6cda4e Mon Sep 17 00:00:00 2001 From: Vladimir Sharshov Date: Fri, 28 Oct 2011 04:26:53 +0400 Subject: [PATCH 03/10] Add more information in projects raise --- app/models/project.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/app/models/project.rb b/app/models/project.rb index b417e8372..14ab51918 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -73,7 +73,7 @@ class Project < ActiveRecord::Base if result == BuildServer::SUCCESS return true else - raise "Failed to add project #{name} to repo #{repo.name} of platform #{platf.name}." + raise "Failed to add project #{name} to repo #{repo.name} of platform #{platf.name} with code #{result}." end end @@ -86,7 +86,7 @@ class Project < ActiveRecord::Base if result == BuildServer::SUCCESS return true else - raise "Failed to create project #{name} (repo #{repository.name}) inside platform #{repository.platform.name}." + raise "Failed to create project #{name} (repo #{repository.name}) inside platform #{repository.platform.name} with code #{result}." end end @@ -138,7 +138,7 @@ class Project < ActiveRecord::Base if result == BuildServer::SUCCESS return true else - raise "Failed to create project #{name} (repo main) inside platform #{owner.uname}_personal." + raise "Failed to create project #{name} (repo main) inside platform #{owner.uname}_personal with code #{result}." end end @@ -147,7 +147,7 @@ class Project < ActiveRecord::Base if result == BuildServer::SUCCESS return true else - raise "Failed to delete repository #{name} (repo main) inside platform #{owner.uname}_personal." + raise "Failed to delete repository #{name} (repo main) inside platform #{owner.uname}_personal with code #{result}." end end end From 96a598806ba87d2fe6788720aba81e1c9eeb66ef Mon Sep 17 00:00:00 2001 From: Vladimir Sharshov Date: Fri, 28 Oct 2011 04:28:55 +0400 Subject: [PATCH 04/10] Fix mistype --- app/models/project.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/project.rb b/app/models/project.rb index 14ab51918..8592e3596 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -31,7 +31,7 @@ class Project < ActiveRecord::Base before_create :make_owner_rel before_create :xml_rpc_create before_destroy :xml_rpc_destroy - before_create :create_git_repo, + before_create :create_git_repo before_update :update_git_repo before_destroy :destroy_git_repo after_create :attach_to_personal_repository From 6238012fa93e70e8da2a9f840edb3459370fe004 Mon Sep 17 00:00:00 2001 From: "konstantin.grabar" Date: Fri, 28 Oct 2011 11:20:13 +0400 Subject: [PATCH 05/10] [refs #2106] Move visibility logic to platforms --- .../personal_repositories_controller.rb | 4 +- app/models/personal_repository.rb | 2 +- app/models/platform.rb | 37 +++++++++++++++++++ app/models/repository.rb | 36 ------------------ .../personal_repositories/settings.html.haml | 4 +- ...604_remove_visibility_from_repositories.rb | 9 +++++ db/schema.rb | 13 +++---- public/downloads/test2_personal | 1 + 8 files changed, 57 insertions(+), 49 deletions(-) create mode 100644 db/migrate/20111028070604_remove_visibility_from_repositories.rb create mode 120000 public/downloads/test2_personal diff --git a/app/controllers/personal_repositories_controller.rb b/app/controllers/personal_repositories_controller.rb index 25f9b8f54..f46ae0bc6 100644 --- a/app/controllers/personal_repositories_controller.rb +++ b/app/controllers/personal_repositories_controller.rb @@ -12,13 +12,13 @@ class PersonalRepositoriesController < ApplicationController #TODO: Add git repo move into private repos path. def change_visibility - @repository.change_visibility + @repository.platform.change_visibility redirect_to settings_personal_repository_path(@repository) end def settings - if @repository.hidden? + if @repository.platform.hidden? @urmpi_command = "urpmi -add http://login@password:#{ request.host }/privates/#{ @repository.platform.name }/main/" else @urmpi_command = "urpmi -add http://#{ request.host }/downloads/#{ @repository.platform.name }/main/" diff --git a/app/models/personal_repository.rb b/app/models/personal_repository.rb index 5710ab20e..c9d276429 100644 --- a/app/models/personal_repository.rb +++ b/app/models/personal_repository.rb @@ -13,13 +13,13 @@ module PersonalRepository pl.unixname = "#{self.uname}_personal" pl.platform_type = 'personal' pl.distrib_type = 'mandriva2011' + pl.visibility = 'open' pl.save rep = pl.repositories.build rep.owner = pl.owner rep.name = 'main' rep.unixname = 'main' - rep.visibility = 'open' rep.save end diff --git a/app/models/platform.rb b/app/models/platform.rb index fad51a2a1..5febc59d9 100644 --- a/app/models/platform.rb +++ b/app/models/platform.rb @@ -1,6 +1,8 @@ #require 'lib/build_server.rb' class Platform < ActiveRecord::Base + DOWNLOADS_PATH = RAILS_ROOT + '/public/downloads' VISIBILITIES = ['open', 'hidden'] + relationable :as => :target belongs_to :parent, :class_name => 'Platform', :foreign_key => 'parent_platform_id' @@ -31,10 +33,18 @@ class Platform < ActiveRecord::Base #attr_accessible :visibility + after_create lambda { + add_downloads_symlink unless self.hidden? + } + def path build_path(unixname) end + def hidden? + self.visibility == 'hidden' + end + def clone(new_name, new_unixname) p = Platform.new p.name = new_name @@ -62,6 +72,16 @@ class Platform < ActiveRecord::Base rel.save end end + + def change_visibility + if !self.hidden? + self.update_attribute(:visibility, 'hidden') + remove_downloads_symlink + else + self.update_attribute(:visibility, 'open') + add_downloads_symlink + end + end protected @@ -131,4 +151,21 @@ class Platform < ActiveRecord::Base BuildServer.freeze_platform self.unixname end end + + def symlink_downloads_path + "#{ DOWNLOADS_PATH }/#{ self.unixname }" + end + + def add_downloads_symlink + #raise "Personal platform path #{ symlink_downloads_path } already exists!" if File.exists?(symlink_downloads_path) && File.directory?(symlink_downloads_path) + return true if File.exists?(symlink_downloads_path) && File.directory?(symlink_downloads_path) + FileUtils.symlink path, symlink_downloads_path + end + + def remove_downloads_symlink + #raise "Personal platform path #{ symlink_downloads_path } does not exists!" if !(File.exists?(symlink_downloads_path) && File.directory?(symlink_downloads_path)) + return true if !(File.exists?(symlink_downloads_path) && File.directory?(symlink_downloads_path)) + FileUtils.rm_rf symlink_downloads_path + end + end diff --git a/app/models/repository.rb b/app/models/repository.rb index 39d431dec..66c6f48b4 100644 --- a/app/models/repository.rb +++ b/app/models/repository.rb @@ -1,7 +1,5 @@ class Repository < ActiveRecord::Base - DOWNLOADS_PATH = RAILS_ROOT + '/public/downloads' - VISIBILITIES = ['open', 'hidden'] relationable :as => :target @@ -29,20 +27,12 @@ class Repository < ActiveRecord::Base before_create :xml_rpc_create before_destroy :xml_rpc_destroy - after_create lambda { - add_downloads_symlink unless self.hidden? - } - attr_accessible :visibility, :name, :unixname, :platform_id def path build_path(unixname) end - def hidden? - self.visibility == 'hidden' - end - def clone r = Repository.new r.name = name @@ -50,16 +40,6 @@ class Repository < ActiveRecord::Base r.projects = projects.map(&:clone) return r end - - def change_visibility - if !self.hidden? - self.update_attribute(:visibility, 'hidden') - remove_downloads_symlink - else - self.update_attribute(:visibility, 'open') - add_downloads_symlink - end - end protected @@ -108,21 +88,5 @@ class Repository < ActiveRecord::Base raise "Failed to delete repository #{name} inside platform #{platform.name}." end end - - def symlink_downloads_path - "#{ DOWNLOADS_PATH }/#{ self.platform.unixname }" - end - - def add_downloads_symlink - #raise "Personal platform path #{ symlink_downloads_path } already exists!" if File.exists?(symlink_downloads_path) && File.directory?(symlink_downloads_path) - return true if File.exists?(symlink_downloads_path) && File.directory?(symlink_downloads_path) - FileUtils.symlink platform.path, symlink_downloads_path - end - - def remove_downloads_symlink - #raise "Personal platform path #{ symlink_downloads_path } does not exists!" if !(File.exists?(symlink_downloads_path) && File.directory?(symlink_downloads_path)) - return true if !(File.exists?(symlink_downloads_path) && File.directory?(symlink_downloads_path)) - FileUtils.rm_rf symlink_downloads_path - end end diff --git a/app/views/personal_repositories/settings.html.haml b/app/views/personal_repositories/settings.html.haml index ab691275d..87d73291f 100644 --- a/app/views/personal_repositories/settings.html.haml +++ b/app/views/personal_repositories/settings.html.haml @@ -9,9 +9,9 @@ .group %span= t("activerecord.attributes.repository.visibility") + ":" %span - %i= t("activerecord.attributes.repository.visibility_types.#{ @repository.visibility }") + %i= t("activerecord.attributes.repository.visibility_types.#{ @repository.platform.visibility }") .group - = link_to t("layout.personal_repositories.change_visibility_from_#{ @repository.visibility }"), change_visibility_personal_repository_path(@repository) + = link_to t("layout.personal_repositories.change_visibility_from_#{ @repository.platform.visibility }"), change_visibility_personal_repository_path(@repository) %br .group diff --git a/db/migrate/20111028070604_remove_visibility_from_repositories.rb b/db/migrate/20111028070604_remove_visibility_from_repositories.rb new file mode 100644 index 000000000..f9512b8e8 --- /dev/null +++ b/db/migrate/20111028070604_remove_visibility_from_repositories.rb @@ -0,0 +1,9 @@ +class RemoveVisibilityFromRepositories < ActiveRecord::Migration + def self.up + remove_column :repositories, :visibility + end + + def self.down + add_column :repositories, :visibility, :string, :default => "open" + end +end diff --git a/db/schema.rb b/db/schema.rb index 520386245..65fe810e3 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended to check this file into your version control system. -ActiveRecord::Schema.define(:version => 20111027230610) do +ActiveRecord::Schema.define(:version => 20111028070604) do create_table "arches", :force => true do |t| t.string "name", :null => false @@ -208,20 +208,18 @@ ActiveRecord::Schema.define(:version => 20111027230610) do t.string "object_type" t.integer "target_id" t.string "target_type" - t.integer "role_id" t.datetime "created_at" t.datetime "updated_at" end create_table "repositories", :force => true do |t| - t.string "name", :null => false - t.integer "platform_id", :null => false + t.string "name", :null => false + t.integer "platform_id", :null => false t.datetime "created_at" t.datetime "updated_at" - t.string "unixname", :null => false + t.string "unixname", :null => false t.integer "owner_id" t.string "owner_type" - t.string "visibility", :default => "open" end create_table "rights", :force => true do |t| @@ -271,9 +269,8 @@ ActiveRecord::Schema.define(:version => 20111027230610) do t.datetime "remember_created_at" t.datetime "created_at" t.datetime "updated_at" - t.string "uname" t.text "ssh_key" - t.integer "role_id" + t.string "uname" t.integer "global_role_id" end diff --git a/public/downloads/test2_personal b/public/downloads/test2_personal new file mode 120000 index 000000000..19613d194 --- /dev/null +++ b/public/downloads/test2_personal @@ -0,0 +1 @@ +/var/rosa/platforms/test2_personal \ No newline at end of file From 8f459f8abcbd10dd2cbc162a68f3a6c28a9e52eb Mon Sep 17 00:00:00 2001 From: "konstantin.grabar" Date: Fri, 28 Oct 2011 15:16:32 +0400 Subject: [PATCH 06/10] Fix repository and project_to_repository paths and symbolinks --- app/models/project_to_repository.rb | 54 ++++++++++++++++++++--------- app/models/repository.rb | 46 ++++++++++++------------ 2 files changed, 61 insertions(+), 39 deletions(-) diff --git a/app/models/project_to_repository.rb b/app/models/project_to_repository.rb index b920c09bf..91a468c78 100644 --- a/app/models/project_to_repository.rb +++ b/app/models/project_to_repository.rb @@ -1,36 +1,58 @@ class ProjectToRepository < ActiveRecord::Base belongs_to :project belongs_to :repository + + delegate :path, :to => :project - before_save :create_link - after_destroy :remove_link + #before_save :create_link + before_save :add_compability_link + #after_destroy :remove_link + after_destroy :remove_compability_link after_create lambda { project.xml_rpc_create } - def path - build_path(project.unixname) + #def path + # build_path(project.unixname) + #end + + # This is symbolink to /git_projects//.git + def sym_path + "#{ repository.platform.path }/projects/#{ project.unixname }.git" end protected - def build_path(dir) - File.join(repository.path, dir) - end + #def build_path(dir) + # File.join(repository.path, dir) + #end - def create_link - exists = File.exists?(path) && File.directory?(path) - raise "Symlink #{path} already exists" if exists + #def create_link + # exists = File.exists?(path) && File.directory?(path) + # raise "Symlink #{path} already exists" if exists + # if new_record? + # FileUtils.ln_s(project.path, path) + # end + #end + # + #def remove_link + # exists = File.exists?(path) && File.directory?(path) + # raise "Directory #{path} didn't exists" unless exists + # FileUtils.rm_rf(path) + #end + + def add_compability_link + exists = File.exists?(sym_path) && File.directory?(sym_path) + return false if exists if new_record? - FileUtils.ln_s(project.path, path) + FileUtils.ln_s(path, sym_path) end end - def remove_link - exists = File.exists?(path) && File.directory?(path) - raise "Directory #{path} didn't exists" unless exists - FileUtils.rm_rf(path) + def remove_compability_link + exists = File.exists?(sym_path) && File.directory?(sym_path) + return false unless exists + FileUtils.rm_rf(sym_path) end - end diff --git a/app/models/repository.rb b/app/models/repository.rb index 66c6f48b4..af77a1d88 100644 --- a/app/models/repository.rb +++ b/app/models/repository.rb @@ -29,9 +29,9 @@ class Repository < ActiveRecord::Base attr_accessible :visibility, :name, :unixname, :platform_id - def path - build_path(unixname) - end +# def path +# build_path(unixname) +# end def clone r = Repository.new @@ -50,26 +50,26 @@ class Repository < ActiveRecord::Base end end - def build_path(dir) - File.join(platform.path, dir) - end - - def create_directory - exists = File.exists?(path) && File.directory?(path) - raise "Directory #{path} already exists" if exists - if new_record? - FileUtils.mkdir_p(path) - %w(release updates).each { |subrep| FileUtils.mkdir_p(path + subrep) } - elsif unixname_changed? - FileUtils.mv(build_path(unixname_was), buildpath(unixname)) - end - end - - def remove_directory - exists = File.exists?(path) && File.directory?(path) - raise "Directory #{path} didn't exists" unless exists - FileUtils.rm_rf(path) - end +# def build_path(dir) +# File.join(platform.path, dir) +# end +# +# def create_directory +# exists = File.exists?(path) && File.directory?(path) +# raise "Directory #{path} already exists" if exists +# if new_record? +# FileUtils.mkdir_p(path) +# %w(release updates).each { |subrep| FileUtils.mkdir_p(path + subrep) } +# elsif unixname_changed? +# FileUtils.mv(build_path(unixname_was), buildpath(unixname)) +# end +# end +# +# def remove_directory +# exists = File.exists?(path) && File.directory?(path) +# raise "Directory #{path} didn't exists" unless exists +# FileUtils.rm_rf(path) +# end def xml_rpc_create result = BuildServer.create_repo unixname, platform.unixname From 0718778b3f6b9363490900be06ac18298b665909 Mon Sep 17 00:00:00 2001 From: "konstantin.grabar" Date: Fri, 28 Oct 2011 15:45:00 +0400 Subject: [PATCH 07/10] Add system ln and rm call with sudo --- app/models/project_to_repository.rb | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/app/models/project_to_repository.rb b/app/models/project_to_repository.rb index 91a468c78..598b64f7b 100644 --- a/app/models/project_to_repository.rb +++ b/app/models/project_to_repository.rb @@ -46,13 +46,15 @@ class ProjectToRepository < ActiveRecord::Base exists = File.exists?(sym_path) && File.directory?(sym_path) return false if exists if new_record? - FileUtils.ln_s(path, sym_path) + #FileUtils.ln_s(path, sym_path) + system("sudo ln -s #{ path } #{ sym_path }") end end def remove_compability_link exists = File.exists?(sym_path) && File.directory?(sym_path) return false unless exists - FileUtils.rm_rf(sym_path) + #FileUtils.rm_rf(sym_path) + system("sudo rm -rf #{ sym_path }") end end From dba428de2c3fb2448eac5dada1a0084a97c6a297 Mon Sep 17 00:00:00 2001 From: "konstantin.grabar" Date: Fri, 28 Oct 2011 16:25:14 +0400 Subject: [PATCH 08/10] Comment attr_accessible for project --- app/models/project.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/project.rb b/app/models/project.rb index 8592e3596..a539d7813 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -20,7 +20,7 @@ class Project < ActiveRecord::Base validates :owner, :presence => true validate {errors.add(:base, I18n.t('flash.project.save_warning_ssh_key')) if owner.ssh_key.blank?} - attr_accessible :category_id, :name, :unixname, :description, :visibility + #attr_accessible :category_id, :name, :unixname, :description, :visibility attr_readonly :unixname scope :recent, order("name ASC") From 38d14352d05a9e5374814fa8a915bf31806bc743 Mon Sep 17 00:00:00 2001 From: Vladimir Sharshov Date: Fri, 28 Oct 2011 16:27:13 +0400 Subject: [PATCH 09/10] Add git_project_path to create_project --- lib/build_server.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/build_server.rb b/lib/build_server.rb index b3dcde394..91956ac9f 100644 --- a/lib/build_server.rb +++ b/lib/build_server.rb @@ -56,8 +56,8 @@ class BuildServer self.client.call('delete_container', container_id) end - def self.create_project name, platform_name, repo_name - self.client.call('create_project', name, repo_name, platform_name) + def self.create_project name, platform_name, repo_name, git_project_path + self.client.call('create_project', name, repo_name, platform_name, git_project_path) end def self.delete_project name, platform_name From 6147ebf79ef603a9f84b4b42ce8e11cfe7c49e28 Mon Sep 17 00:00:00 2001 From: "konstantin.grabar" Date: Fri, 28 Oct 2011 16:40:38 +0400 Subject: [PATCH 10/10] Fix create_project XML-RPC and comment project_to_repository symlinks --- app/models/project.rb | 2 +- app/models/project_to_repository.rb | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/app/models/project.rb b/app/models/project.rb index a539d7813..2f3887ef8 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -134,7 +134,7 @@ class Project < ActiveRecord::Base end def xml_rpc_create - result = BuildServer.create_project unixname, "#{owner.uname}_personal", 'main' + result = BuildServer.create_project unixname, "#{owner.uname}_personal", 'main', path if result == BuildServer::SUCCESS return true else diff --git a/app/models/project_to_repository.rb b/app/models/project_to_repository.rb index 598b64f7b..b64a371bd 100644 --- a/app/models/project_to_repository.rb +++ b/app/models/project_to_repository.rb @@ -5,9 +5,9 @@ class ProjectToRepository < ActiveRecord::Base delegate :path, :to => :project #before_save :create_link - before_save :add_compability_link + #before_save :add_compability_link #after_destroy :remove_link - after_destroy :remove_compability_link + #after_destroy :remove_compability_link after_create lambda { project.xml_rpc_create