diff --git a/app/controllers/git/blobs_controller.rb b/app/controllers/git/blobs_controller.rb index 0b93db28f..3300c98e8 100644 --- a/app/controllers/git/blobs_controller.rb +++ b/app/controllers/git/blobs_controller.rb @@ -29,8 +29,8 @@ class Git::BlobsController < Git::BaseController # @git_repository.after_update_file do |repo, sha| # end - res = @git_repository.update_file(params[:path], params[:content], - :message => params[:message], :actor => current_user, :head => @treeish) + res = @git_repository.update_file(params[:path], params[:content].gsub("\r", ''), + :message => params[:message].gsub("\r", ''), :actor => current_user, :head => @treeish) if res flash[:notice] = t("flash.blob.successfully_updated", :name => params[:path].encode_to_default) else diff --git a/app/controllers/personal_repositories_controller.rb b/app/controllers/personal_repositories_controller.rb index c76c21623..122ed928a 100644 --- a/app/controllers/personal_repositories_controller.rb +++ b/app/controllers/personal_repositories_controller.rb @@ -12,7 +12,7 @@ class PersonalRepositoriesController < ApplicationController else @projects = @repository.projects.recent.paginate :page => params[:project_page], :per_page => 30 end - @user = @repository.owner + @user = @repository.platform.owner @urpmi_commands = @repository.platform.urpmi_list(request.host) end diff --git a/app/controllers/platforms_controller.rb b/app/controllers/platforms_controller.rb index 060fe99e0..01cbc0eec 100644 --- a/app/controllers/platforms_controller.rb +++ b/app/controllers/platforms_controller.rb @@ -8,11 +8,7 @@ class PlatformsController < ApplicationController autocomplete :user, :uname def build_all - @platform.repositories.each do |repository| - repository.projects.each do |project| - project.delay.build_for(@platform, current_user) - end - end + @platform.delay.build_all(current_user) redirect_to(platform_path(@platform), :notice => t("flash.platform.build_all_success")) end @@ -109,24 +105,24 @@ class PlatformsController < ApplicationController end def clone - if request.post? - @cloned = @platform.make_clone(:name => params[:platform]['name'], :description => params[:platform]['description'], - :owner_id => current_user.id, :owner_type => current_user.class.to_s) - if @cloned.persisted? - flash[:notice] = I18n.t("flash.platform.clone_success") - redirect_to @cloned - else - flash[:error] = @cloned.errors.full_messages.join('. ') - end + @cloned = Platform.new + @cloned.name = @platform.name + "_clone" + @cloned.description = @platform.description + "_clone" + end + + def make_clone + @cloned = @platform.full_clone params[:platform].merge(:owner => current_user) + if @cloned.persisted? + flash[:notice] = I18n.t("flash.platform.clone_success") + redirect_to @cloned else - @cloned = Platform.new - @cloned.name = @platform.name + "_clone" - @cloned.description = @platform.description + "_clone" + flash[:error] = @cloned.errors.full_messages.join('. ') + render 'clone' end end def destroy - @platform.destroy if @platform + @platform.delay.destroy if @platform flash[:notice] = t("flash.platform.destroyed") redirect_to root_path diff --git a/app/controllers/register_requests_controller.rb b/app/controllers/register_requests_controller.rb index 74ddd6627..85c915a52 100644 --- a/app/controllers/register_requests_controller.rb +++ b/app/controllers/register_requests_controller.rb @@ -5,7 +5,7 @@ class RegisterRequestsController < ApplicationController before_filter :find_register_request, :only => [:approve, :reject] def index - @register_requests = @register_requests.unprocessed.paginate(:page => params[:page]) + @register_requests = @register_requests.send((params[:scope] || 'unprocessed').to_sym).paginate(:page => params[:page]) end def new diff --git a/app/controllers/repositories_controller.rb b/app/controllers/repositories_controller.rb index 317683699..693be6034 100644 --- a/app/controllers/repositories_controller.rb +++ b/app/controllers/repositories_controller.rb @@ -42,7 +42,6 @@ class RepositoriesController < ApplicationController def create @repository = Repository.new(params[:repository]) @repository.platform_id = params[:platform_id] - @repository.owner = get_owner if @repository.save flash[:notice] = t('flash.repository.saved') redirect_to @repositories_path diff --git a/app/controllers/wiki_controller.rb b/app/controllers/wiki_controller.rb index b334262e3..7364f1943 100644 --- a/app/controllers/wiki_controller.rb +++ b/app/controllers/wiki_controller.rb @@ -117,19 +117,25 @@ class WikiController < ApplicationController def compare_wiki if request.post? @versions = params[:versions] || [] - if @versions.size < 2 - redirect_to history_project_wiki_index_path(@project) - else - redirect_to compare_versions_project_wiki_index_path(@project, - sprintf('%s...%s', @versions.last, @versions.first)) + versions_string = case @versions.size + when 1 then @versions.first + when 2 then sprintf('%s...%s', @versions.last, @versions.first) + else begin + redirect_to history_project_wiki_index_path(@project) + return + end end + redirect_to compare_versions_project_wiki_index_path(@project, versions_string) elsif request.get? - @versions = params[:versions].split(/\.{2,3}/) - if @versions.size < 2 - redirect_to history_project_wiki_index_path(@project) - return + @versions = params[:versions].split(/\.{2,3}/) || [] + @diffs = case @versions.size + when 1 then @wiki.repo.commit_diff(@versions.first) + when 2 then @wiki.repo.diff(@versions.first, @versions.last) + else begin + redirect_to history_project_wiki_index_path(@project) + return + end end - @diffs = @wiki.repo.diff(@versions.first, @versions.last) render :compare else redirect_to project_wiki_path(@project, CGI.escape(@name)) @@ -141,8 +147,9 @@ class WikiController < ApplicationController @page = @wiki.page(@name) sha1 = params[:sha1] sha2 = params[:sha2] + sha2 = nil if params[:sha2] == 'prev' - if @wiki.revert_page(@page, sha1, sha2, {:committer => committer}).commit + if c = @wiki.revert_page(@page, sha1, sha2, {:committer => committer}) and c.commit flash[:notice] = t("flash.wiki.revert_success") redirect_to project_wiki_path(@project, CGI.escape(@name)) else @@ -162,14 +169,14 @@ class WikiController < ApplicationController def revert_wiki sha1 = params[:sha1] sha2 = params[:sha2] - if @wiki.revert_commit(sha1, sha2, {:committer => committer}).commit + sha2 = nil if sha2 == 'prev' + if c = @wiki.revert_commit(sha1, sha2, {:committer => committer}) and c.commit flash[:notice] = t("flash.wiki.revert_success") redirect_to project_wiki_index_path(@project) else sha2, sha1 = sha1, "#{sha1}^" if !sha2 @versions = [sha1, sha2] - diffs = @wiki.repo.diff(@versions.first, @versions.last) - @diffs = [diffs.first] + @diffs = @wiki.repo.diff(@versions.first, @versions.last) flash[:error] = t("flash.wiki.patch_does_not_apply") render :compare end diff --git a/app/helpers/diff_helper.rb b/app/helpers/diff_helper.rb index 0addc764b..646135d1e 100644 --- a/app/helpers/diff_helper.rb +++ b/app/helpers/diff_helper.rb @@ -8,7 +8,7 @@ module DiffHelper res += "" res += "" - res += diff_display.render(Git::Diff::InlineCallback.new) + res += diff_display.render(Git::Diff::InlineCallback.new).encode_to_default res += "" res += "
" diff --git a/app/helpers/projects_helper.rb b/app/helpers/projects_helper.rb index 06c4de5b0..827e4cda0 100644 --- a/app/helpers/projects_helper.rb +++ b/app/helpers/projects_helper.rb @@ -2,9 +2,9 @@ module ProjectsHelper def git_repo_url(name) if current_user - "http://#{current_user.uname}@#{request.host_with_port}/#{name}.git" + "https://#{current_user.uname}@#{request.host_with_port}/#{name}.git" else - "http://#{request.host_with_port}/#{name}.git" + "https://#{request.host_with_port}/#{name}.git" end end end diff --git a/app/models/ability.rb b/app/models/ability.rb index 113b50dd1..bbbb6fd9d 100644 --- a/app/models/ability.rb +++ b/app/models/ability.rb @@ -17,6 +17,8 @@ class Ability cannot :destroy, Subscribe cannot :create, Subscribe cannot :create, RegisterRequest + cannot :approve, RegisterRequest, :approved => true + cannot :reject, RegisterRequest, :rejected => true else # Shared rights between guests and registered users can :forbidden, Platform @@ -64,22 +66,21 @@ class Ability can :read, Platform, :owner_type => 'User', :owner_id => user.id can :read, Platform, :owner_type => 'Group', :owner_id => user.group_ids can(:read, Platform, read_relations_for('platforms')) {|platform| local_reader? platform} - can(:update, Platform) {|platform| local_admin? platform} + can([:update, :build_all], Platform) {|platform| local_admin? platform} can([:freeze, :unfreeze, :destroy], Platform) {|platform| owner? platform} can :autocomplete_user_uname, Platform - # TODO delegate to platform? can :read, Repository, :platform => {:visibility => 'open'} - can :read, Repository, :owner_type => 'User', :owner_id => user.id - can :read, Repository, :owner_type => 'Group', :owner_id => user.group_ids - can(:read, Repository, read_relations_for('repositories')) {|repository| local_reader? repository} - can(:create, Repository) {|repository| local_admin? repository.platform} - can([:update, :add_project, :remove_project], Repository) {|repository| local_admin? repository} - can([:change_visibility, :settings, :destroy], Repository) {|repository| owner? repository} + can :read, Repository, :platform => {:owner_type => 'User', :owner_id => user.id} + can :read, Repository, :platform => {:owner_type => 'Group', :owner_id => user.group_ids} + can(:read, Repository, read_relations_for('repositories', 'platforms')) {|repository| local_reader? repository.platform} + can([:create, :update, :projects_list, :add_project, :remove_project], Repository) {|repository| local_admin? repository.platform} + can([:change_visibility, :settings, :destroy], Repository) {|repository| owner? repository.platform} can :read, Product, :platform => {:owner_type => 'User', :owner_id => user.id} can :read, Product, :platform => {:owner_type => 'Group', :owner_id => user.group_ids} can(:manage, Product, read_relations_for('products', 'platforms')) {|product| local_admin? product.platform} + can(:create, ProductBuildList) {|pbl| pbl.product.can_build? and can?(:update, pbl.product)} can [:read, :platforms], Category diff --git a/app/models/group.rb b/app/models/group.rb index d74161e25..e668835b8 100644 --- a/app/models/group.rb +++ b/app/models/group.rb @@ -2,16 +2,16 @@ class Group < ActiveRecord::Base belongs_to :owner, :class_name => 'User' - has_many :own_projects, :as => :owner, :class_name => 'Project' - + has_many :relations, :as => :object, :dependent => :destroy has_many :objects, :as => :target, :class_name => 'Relation' has_many :targets, :as => :object, :class_name => 'Relation' has_many :members, :through => :objects, :source => :object, :source_type => 'User', :autosave => true has_many :projects, :through => :targets, :source => :target, :source_type => 'Project', :autosave => true - has_many :platforms, :through => :targets, :source => :target, :source_type => 'Platform', :autosave => true, :dependent => :destroy - has_many :repositories, :through => :targets, :source => :target, :source_type => 'Repository', :autosave => true - has_many :relations, :as => :object, :dependent => :destroy + has_many :platforms, :through => :targets, :source => :target, :source_type => 'Platform', :autosave => true + + has_many :own_projects, :as => :owner, :class_name => 'Project', :dependent => :destroy + has_many :own_platforms, :as => :owner, :class_name => 'Platform', :dependent => :destroy validates :name, :owner, :presence => true validates :uname, :presence => true, :uniqueness => {:case_sensitive => false}, :format => { :with => /^[a-z0-9_]+$/ } @@ -24,11 +24,12 @@ class Group < ActiveRecord::Base after_create :add_owner_to_members include Modules::Models::PersonalRepository -# include Modules::Models::Owner + # include Modules::Models::Owner protected - def add_owner_to_members - Relation.create_with_role(self.owner, self, 'admin') -# members << self.owner if !members.exists?(:id => self.owner.id) - end + + def add_owner_to_members + Relation.create_with_role(self.owner, self, 'admin') + # members << self.owner if !members.exists?(:id => self.owner.id) + end end diff --git a/app/models/platform.rb b/app/models/platform.rb index e7b552ba2..6a109fa2d 100644 --- a/app/models/platform.rb +++ b/app/models/platform.rb @@ -14,10 +14,11 @@ class Platform < ActiveRecord::Base has_many :members, :through => :objects, :source => :object, :source_type => 'User' has_many :groups, :through => :objects, :source => :object, :source_type => 'Group' - validates :description, :presence => true, :uniqueness => true + validates :description, :presence => true validates :name, :uniqueness => {:case_sensitive => false}, :presence => true, :format => { :with => /^[a-zA-Z0-9_\-]+$/ } validates :distrib_type, :presence => true, :inclusion => {:in => APP_CONFIG['distr_types']} + before_create :create_directory, :if => lambda {Thread.current[:skip]} # TODO remove this when core will be ready before_create :xml_rpc_create, :unless => lambda {Thread.current[:skip]} before_destroy :xml_rpc_destroy # before_update :check_freezing @@ -98,27 +99,23 @@ class Platform < ActiveRecord::Base platform_type == 'personal' end - def full_clone(attrs) # :description, :name, :owner + def base_clone(attrs = {}) # :description, :name, :owner clone.tap do |c| - c.attributes = attrs + c.attributes = attrs # attrs.each {|k,v| c.send("#{k}=", v)} c.updated_at = nil; c.created_at = nil # :id = nil c.parent = self - new_attrs = {:platform_id => nil} - c.repositories = repositories.map{|r| r.full_clone(new_attrs.merge(:owner_id => attrs[:owner_id], :owner_type => attrs[:owner_type]))} - c.products = products.map{|p| p.full_clone(new_attrs)} end end - # TODO * make it Delayed Job * - def make_clone(attrs) - p = full_clone(attrs) - begin - Thread.current[:skip] = true - p.save and xml_rpc_clone(attrs[:name]) - ensure - Thread.current[:skip] = false + def clone_relations(from = parent) + self.repositories = from.repositories.map{|r| r.full_clone(:platform_id => id)} + self.products = from.products.map(&:full_clone) + end + + def full_clone(attrs = {}) + base_clone(attrs).tap do |c| + with_skip {c.save} and c.clone_relations(self) and c.delay.xml_rpc_clone end - p end def name @@ -135,9 +132,13 @@ class Platform < ActiveRecord::Base end end + def create_directory + system("sudo mkdir -p -m 0777 #{path}") + end + def mount_directory_for_rsync # umount_directory_for_rsync # TODO ignore errors - system("sudo mkdir -p #{mount_path}") + system("sudo mkdir -p -m 0777 #{mount_path}") system("sudo mount --bind #{path} #{mount_path}") Arch.all.each do |arch| str = "country=Russian Federation,city=Moscow,latitude=52.18,longitude=48.88,bw=1GB,version=2011,arch=#{arch.name},type=distrib,url=#{public_downloads_url}\n" @@ -157,6 +158,23 @@ class Platform < ActiveRecord::Base end end + def build_all(user) + repositories.find_by_name('main').projects.find_in_batches(:batch_size => 5) do |group| + sleep 1 + group.each do |p| + begin + p.build_for(self, user) + rescue RuntimeError, Exception + p.delay.build_for(self, user) + end + end + end + end + + def destroy + with_skip {super} # avoid cascade XML RPC requests + end + protected def build_path(dir) @@ -181,12 +199,12 @@ class Platform < ActiveRecord::Base end end - def xml_rpc_clone(new_name) - result = BuildServer.clone_platform new_name, self.name, APP_CONFIG['root_path'] + '/platforms' + def xml_rpc_clone(old_name = parent.name, new_name = name) + result = BuildServer.clone_platform new_name, old_name, APP_CONFIG['root_path'] + '/platforms' if result == BuildServer::SUCCESS return true else - raise "Failed to clone platform #{name} with code #{result}. Path: #{build_path(name)} to platform #{new_name}" + raise "Failed to clone platform #{old_name} with code #{result}. Path: #{build_path(old_name)} to platform #{new_name}" end end diff --git a/app/models/product.rb b/app/models/product.rb index 94e355d20..536b3dbbf 100644 --- a/app/models/product.rb +++ b/app/models/product.rb @@ -59,9 +59,10 @@ class Product < ActiveRecord::Base EOF end - def full_clone(attrs) # owner + def full_clone(attrs = {}) clone.tap do |c| # dup - c.attributes = attrs + c.platform_id = nil + attrs.each {|k,v| c.send("#{k}=", v)} c.updated_at = nil; c.created_at = nil # :id = nil end end diff --git a/app/models/product_build_list.rb b/app/models/product_build_list.rb index b01ee85e4..f9078f19d 100644 --- a/app/models/product_build_list.rb +++ b/app/models/product_build_list.rb @@ -15,6 +15,10 @@ class ProductBuildList < ActiveRecord::Base after_create :xml_rpc_create + def container_path + "/downloads/#{product.platform.name}/product/#{id}/" + end + def human_status I18n.t("layout.product_build_lists.statuses.#{status}") end diff --git a/app/models/project.rb b/app/models/project.rb index 68bdc9f62..e268132fe 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -18,7 +18,7 @@ class Project < ActiveRecord::Base has_many :collaborators, :through => :relations, :source => :object, :source_type => 'User' has_many :groups, :through => :relations, :source => :object, :source_type => 'Group' - validates :name, :uniqueness => {:scope => [:owner_id, :owner_type], :case_sensitive => false}, :presence => true, :format => { :with => /^[a-zA-Z0-9_\-\+\.]+$/ } + validates :name, :uniqueness => {:scope => [:owner_id, :owner_type], :case_sensitive => false}, :presence => true, :format => {:with => /^[a-zA-Z0-9_\-\+\.]+$/} validates :owner, :presence => true validate { errors.add(:base, :can_have_less_or_equal, :count => MAX_OWN_PROJECTS) if owner.projects.size >= MAX_OWN_PROJECTS } # validate {errors.add(:base, I18n.t('flash.project.save_warning_ssh_key')) if owner.ssh_key.blank?} @@ -61,14 +61,13 @@ class Project < ActiveRecord::Base end end - def build_for(platform, user) + def build_for(platform, user) build_lists.create do |bl| bl.pl = platform bl.bpl = platform - bl.update_type = 'recommended' + bl.update_type = 'newpackage' bl.arch = Arch.find_by_name('x86_64') # Return i586 after mass rebuild - # FIXME: Need to set "latest_#{platform.name}" - bl.project_version = "latest_import_mandriva2011" + bl.project_version = "latest_#{platform.name}" # "latest_import_mandriva2011" bl.build_requires = false # already set as db default bl.user = user bl.auto_publish = true # already set as db default @@ -212,9 +211,20 @@ class Project < ActiveRecord::Base end def write_hook + is_production = ENV['RAILS_ENV'] == 'production' + hook = File.join(::Rails.root.to_s, 'tmp', "post-receive-hook") + FileUtils.cp(File.join(::Rails.root.to_s, 'bin', "post-receive-hook.partial"), hook) + File.open(hook, 'a') do |f| + s = "\n /bin/bash -l -c \"cd #{is_production ? '/srv/rosa_build/current' : Rails.root.to_s} && #{is_production ? 'RAILS_ENV=production' : ''} bundle exec rails runner 'Project.delay.process_hook(\"$owner\", \"$reponame\", \"$newrev\", \"$oldrev\", \"$ref\", \"$newrev_type\", \"$oldrev_type\")'\"" + s << " > /dev/null 2>&1" if is_production + s << "\ndone\n" + f.write(s) + end + hook_file = File.join(path, 'hooks', 'post-receive') - FileUtils.cp(File.join(::Rails.root.to_s, 'lib', 'post-receive-hook'), hook_file) - #File.chmod(0775, hook_file) # need? + FileUtils.cp(hook, hook_file) + FileUtils.rm_rf(hook) + rescue Exception # FIXME end end diff --git a/app/models/project_to_repository.rb b/app/models/project_to_repository.rb index 7bf5adba5..611bb0bbe 100644 --- a/app/models/project_to_repository.rb +++ b/app/models/project_to_repository.rb @@ -6,7 +6,7 @@ class ProjectToRepository < ActiveRecord::Base delegate :path, :to => :project after_create lambda { project.xml_rpc_create(repository) }, :unless => lambda {Thread.current[:skip]} - after_destroy lambda { project.xml_rpc_destroy(repository) } + after_destroy lambda { project.xml_rpc_destroy(repository) }, :unless => lambda {Thread.current[:skip]} # after_rollback lambda { project.xml_rpc_destroy(repository) rescue true if new_record? } validate :one_project_in_platform_repositories diff --git a/app/models/relation.rb b/app/models/relation.rb index 59c31d29d..6847b097b 100644 --- a/app/models/relation.rb +++ b/app/models/relation.rb @@ -22,7 +22,8 @@ class Relation < ActiveRecord::Base end protected - def add_default_role - self.role = ROLES.first if role.nil? || role.empty? - end + + def add_default_role + self.role = ROLES.first if role.nil? || role.empty? + end end diff --git a/app/models/repository.rb b/app/models/repository.rb index 379d3deac..7684ee005 100644 --- a/app/models/repository.rb +++ b/app/models/repository.rb @@ -1,37 +1,39 @@ # -*- encoding : utf-8 -*- class Repository < ActiveRecord::Base belongs_to :platform - belongs_to :owner, :polymorphic => true - has_many :projects, :through => :project_to_repositories #, :dependent => :destroy - has_many :project_to_repositories, :validate => true, :dependent => :destroy + has_many :project_to_repositories, :dependent => :destroy, :validate => true + has_many :projects, :through => :project_to_repositories - has_many :relations, :as => :target, :dependent => :destroy - has_many :objects, :as => :target, :class_name => 'Relation', :dependent => :destroy - has_many :members, :through => :objects, :source => :object, :source_type => 'User' - has_many :groups, :through => :objects, :source => :object, :source_type => 'Group' - - validates :description, :uniqueness => {:scope => :platform_id}, :presence => true - validates :name, :uniqueness => {:scope => :platform_id, :case_sensitive => false}, :presence => true, :format => { :with => /^[a-z0-9_\-]+$/ } - # validates :platform_id, :presence => true # if you uncomment this platform clone will not work + validates :description, :presence => true + validates :name, :uniqueness => {:scope => :platform_id, :case_sensitive => false}, :presence => true, :format => {:with => /^[a-z0-9_\-]+$/} scope :recent, order("name ASC") before_create :xml_rpc_create, :unless => lambda {Thread.current[:skip]} - before_destroy :xml_rpc_destroy - after_create :add_admin_relations + before_destroy :xml_rpc_destroy, :unless => lambda {Thread.current[:skip]} - attr_accessible :description, :name #, :platform_id + attr_accessible :description, :name - def full_clone(attrs) # owner + def base_clone(attrs = {}) clone.tap do |c| # dup - c.attributes = attrs + c.platform_id = nil + attrs.each {|k,v| c.send("#{k}=", v)} c.updated_at = nil; c.created_at = nil # :id = nil - c.projects = projects end end - include Modules::Models::Owner + def clone_relations(from) + with_skip do + from.projects.find_each {|p| self.projects << p} + end + end + + def full_clone(attrs = {}) + base_clone(attrs).tap do |c| + with_skip {c.save} and c.delay.clone_relations(self) + end + end class << self def build_stub(platform) @@ -43,31 +45,21 @@ class Repository < ActiveRecord::Base protected - def xml_rpc_create - result = BuildServer.create_repo name, platform.name - if result == BuildServer::SUCCESS - return true - else - raise "Failed to create repository #{name} inside platform #{platform.name} with code #{result}." - end + def xml_rpc_create + result = BuildServer.create_repo name, platform.name + if result == BuildServer::SUCCESS + return true + else + raise "Failed to create repository #{name} inside platform #{platform.name} with code #{result}." end + end - def xml_rpc_destroy - result = BuildServer.delete_repo name, platform.name - if result == BuildServer::SUCCESS - return true - else - raise "Failed to delete repository #{name} inside platform #{platform.name} with code #{result}." - end - end - - def add_admin_relations - platform.relations.where(:role => 'admin').each do |rel| - if !relations.exists?(:role => 'admin', :object_type => rel.object_type, :object_id => rel.object_id) && rel.object != owner - r = relations.build(:role => 'admin', :object_type => rel.object_type) - r.object_id = rel.object_id - r.save - end - end + def xml_rpc_destroy + result = BuildServer.delete_repo name, platform.name + if result == BuildServer::SUCCESS + return true + else + raise "Failed to delete repository #{name} inside platform #{platform.name} with code #{result}." end + end end diff --git a/app/models/user.rb b/app/models/user.rb index 96c63dfb9..387807b95 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -11,22 +11,19 @@ class User < ActiveRecord::Base has_many :authentications, :dependent => :destroy has_many :build_lists, :dependent => :destroy + has_many :subscribes, :foreign_key => :user_id, :dependent => :destroy + has_many :comments, :dependent => :destroy has_many :relations, :as => :object, :dependent => :destroy has_many :targets, :as => :object, :class_name => 'Relation' - has_many :own_projects, :as => :owner, :class_name => 'Project', :dependent => :destroy - has_many :own_groups, :foreign_key => :owner_id, :class_name => 'Group' - has_many :own_platforms, :as => :owner, :class_name => 'Platform', :dependent => :destroy - has_many :own_repositories, :as => :owner, :class_name => 'Repository', :dependent => :destroy - - has_many :groups, :through => :targets, :source => :target, :source_type => 'Group', :autosave => true has_many :projects, :through => :targets, :source => :target, :source_type => 'Project', :autosave => true + has_many :groups, :through => :targets, :source => :target, :source_type => 'Group', :autosave => true has_many :platforms, :through => :targets, :source => :target, :source_type => 'Platform', :autosave => true - has_many :repositories, :through => :targets, :source => :target, :source_type => 'Repository', :autosave => true - has_many :subscribes, :foreign_key => :user_id, :dependent => :destroy - has_many :comments, :dependent => :destroy + has_many :own_projects, :as => :owner, :class_name => 'Project', :dependent => :destroy + has_many :own_groups, :foreign_key => :owner_id, :class_name => 'Group', :dependent => :destroy + has_many :own_platforms, :as => :owner, :class_name => 'Platform', :dependent => :destroy include Modules::Models::PersonalRepository diff --git a/app/views/comments/_list.html.haml b/app/views/comments/_list.html.haml index 25e6e13ee..c2aa719bb 100644 --- a/app/views/comments/_list.html.haml +++ b/app/views/comments/_list.html.haml @@ -20,7 +20,8 @@ - edit_path = edit_project_commit_comment_path(project, commentable, comment) - delete_path = project_commit_comment_path(project, commentable, comment) = link_to t("layout.edit"), edit_path if can? :update, comment - = link_to image_tag("web-app-theme/icons/cross.png", :alt => t("layout.delete")) + " " + t("layout.delete"), delete_path, :method => "delete", :class => "button", :confirm => t("layout.comments.confirm_delete") if can? :delete, comment + =# link_to image_tag("web-app-theme/icons/cross.png", :alt => t("layout.delete")) + " " + t("layout.delete"), delete_path, :method => "delete", :class => "button", :confirm => t("layout.comments.confirm_delete") if can? :delete, comment + = link_to t("layout.delete"), delete_path, :method => "delete", :confirm => t("layout.comments.confirm_delete") if can? :delete, comment .block .content diff --git a/app/views/personal_repositories/projects_list.html.haml b/app/views/personal_repositories/projects_list.html.haml index 4766fcb0b..2f3d8c3c0 100644 --- a/app/views/personal_repositories/projects_list.html.haml +++ b/app/views/personal_repositories/projects_list.html.haml @@ -20,21 +20,11 @@ = t("activerecord.attributes.repository.platform") \: = link_to @repository.platform.name, url_for(@repository.platform) - %p - %b - = t("activerecord.attributes.repository.owner") - \: - = link_to @repository.owner.name, url_for(@repository.owner) %p %b = t("activerecord.attributes.platform.visibility") \: = @repository.platform.visibility - %p - %b - = t("activerecord.attributes.repository.platform") - \: - = link_to @repository.platform.name, platform_path(@platform) .wat-cf = link_to image_tag("web-app-theme/icons/cross.png", :alt => t("layout.delete")) + " " + t("layout.delete"), @repository_path, :method => "delete", :class => "button", :confirm => t("layout.repositories.confirm_delete") diff --git a/app/views/personal_repositories/show.html.haml b/app/views/personal_repositories/show.html.haml index f8f346094..c40d3a1d5 100644 --- a/app/views/personal_repositories/show.html.haml +++ b/app/views/personal_repositories/show.html.haml @@ -6,12 +6,6 @@ %li= link_to t("layout.personal_repositories.private_users"), platform_private_users_path(@repository.platform) if @repository.platform.hidden? .content .inner - %p - %b - = t("activerecord.attributes.repository.owner") - \: - = link_to @repository.owner.name, url_for(@repository.owner) - = render 'shared/urpmi_list', :urpmi_commands => @urpmi_commands .wat-cf =# link_to image_tag("web-app-theme/icons/cross.png", :alt => t("layout.delete")) + " " + t("layout.delete"), @repository_path, :method => "delete", :class => "button", :confirm => t("layout.repositories.confirm_delete") diff --git a/app/views/platforms/clone.html.haml b/app/views/platforms/clone.html.haml index 045e2956a..01eb9b7be 100644 --- a/app/views/platforms/clone.html.haml +++ b/app/views/platforms/clone.html.haml @@ -8,7 +8,7 @@ %h2.title = t("layout.platforms.clone_header") .inner - = form_for @cloned, :url => clone_platform_path(@platform), :html => { :class => :form } do |f| + = form_for @cloned, :url => make_clone_platform_path(@platform), :html => { :class => :form } do |f| .group = f.label :name, :class => :label = f.text_field :name, :class => 'text_field' diff --git a/app/views/product_build_lists/_product_build_list.html.haml b/app/views/product_build_lists/_product_build_list.html.haml index bf8fe072c..d1464dc3a 100644 --- a/app/views/product_build_lists/_product_build_list.html.haml +++ b/app/views/product_build_lists/_product_build_list.html.haml @@ -1,5 +1,6 @@ %tr{:class => cycle("odd", "even")} %td= product_build_list.id %td= link_to product_build_list.product.name, [product_build_list.product.platform, product_build_list.product] + %td= link_to nil, product_build_list.container_path %td= product_build_list.human_status %td= product_build_list.notified_at \ No newline at end of file diff --git a/app/views/products/show.html.haml b/app/views/products/show.html.haml index f20fdb222..3372317e6 100644 --- a/app/views/products/show.html.haml +++ b/app/views/products/show.html.haml @@ -26,11 +26,13 @@ = t("layout.#{@product.system_wide?}_") .wat-cf - = link_to image_tag("web-app-theme/icons/application_edit.png", :alt => t("layout.edit")) + " " + t("layout.edit"), edit_platform_product_path(@platform, @product), :class => "button" - = link_to image_tag("web-app-theme/icons/cross.png", :alt => t("layout.delete")) + " " + t("layout.delete"), platform_product_path(@platform, @product), :method => "delete", :class => "button", :confirm => t("layout.products.confirm_delete") + - if can? :update, @product + = link_to image_tag("web-app-theme/icons/application_edit.png", :alt => t("layout.edit")) + " " + t("layout.edit"), edit_platform_product_path(@platform, @product), :class => "button" + - if can? :destroy, @product + = link_to image_tag("web-app-theme/icons/cross.png", :alt => t("layout.delete")) + " " + t("layout.delete"), platform_product_path(@platform, @product), :method => "delete", :class => "button", :confirm => t("layout.products.confirm_delete") - if @product.can_clone? = link_to t("layout.products.clone"), clone_platform_product_path(@platform, @product), :class => "button" - - if @product.can_build? + - if can?(:create, @product => ProductBuildList) = link_to t("layout.products.build"), platform_product_product_build_lists_path(@platform, @product), :class => "button", :method => 'post', :confirm => t("layout.confirm") .block @@ -40,6 +42,7 @@ %tr %th.first= t("activerecord.attributes.product_build_list.id") %th= t("activerecord.attributes.product_build_list.product") + %th= t("activerecord.attributes.product_build_list.container_path") %th= t("activerecord.attributes.product_build_list.status") %th.last= t("activerecord.attributes.product_build_list.notified_at") = render @product.product_build_lists.default_order diff --git a/app/views/register_requests/index.html.haml b/app/views/register_requests/index.html.haml index a860887aa..9df74cd1b 100644 --- a/app/views/register_requests/index.html.haml +++ b/app/views/register_requests/index.html.haml @@ -5,6 +5,10 @@ %li= link_to t("layout.users.new"), new_user_path %li.active= link_to t("layout.users.register_requests"), register_requests_path .content + %div{:style => 'float: right; margin: 20px'} + = link_to t("layout.register_request.approved"), register_requests_path(:scope => :approved) + \| + = link_to t("layout.register_request.rejected"), register_requests_path(:scope => :rejected) %h2.title = t("layout.register_request.list_header") .inner @@ -23,7 +27,8 @@ %tr{:class => cycle("odd", "even")} %td= check_box_tag 'request_ids[]', request.id %td= request.name - %td= request.email + - @user = User.find_by_email(request.email) if request.approved + %td= link_to_if @user, request.email, @user %td= request.interest %td= request.more %td= request.created_at diff --git a/app/views/repositories/projects_list.html.haml b/app/views/repositories/projects_list.html.haml index af5a9a1a9..d9ca336d8 100644 --- a/app/views/repositories/projects_list.html.haml +++ b/app/views/repositories/projects_list.html.haml @@ -21,11 +21,6 @@ = t("activerecord.attributes.repository.platform") \: = link_to @repository.platform.description, url_for(@repository.platform) - %p - %b - = t("activerecord.attributes.repository.owner") - \: - = link_to @repository.owner.uname, url_for(@repository.owner) .wat-cf = link_to image_tag("web-app-theme/icons/cross.png", :alt => t("layout.delete")) + " " + t("layout.delete"), @repository_path, :method => "delete", :class => "button", :confirm => t("layout.repositories.confirm_delete") diff --git a/app/views/repositories/show.html.haml b/app/views/repositories/show.html.haml index 72ab6577a..7e23d2b0d 100644 --- a/app/views/repositories/show.html.haml +++ b/app/views/repositories/show.html.haml @@ -21,11 +21,6 @@ = t("activerecord.attributes.repository.platform") \: = link_to @repository.platform.description, url_for(@repository.platform) - %p - %b - = t("activerecord.attributes.repository.owner") - \: - = link_to @repository.owner.try(:name), url_for(@repository.owner) .wat-cf = link_to image_tag("web-app-theme/icons/cross.png", :alt => t("layout.delete")) + " " + t("layout.delete"), @repository_path, :method => "delete", :class => "button", :confirm => t("layout.repositories.confirm_delete") if can? :destroy, @repository diff --git a/app/views/user_mailer/issue_assign_notification.en.haml b/app/views/user_mailer/issue_assign_notification.en.haml index 83c33e8ac..bc52f31d2 100644 --- a/app/views/user_mailer/issue_assign_notification.en.haml +++ b/app/views/user_mailer/issue_assign_notification.en.haml @@ -1,7 +1,7 @@ %p== Hello, #{@user.name}. -%p You have been assigned to issue #{ link_to @issue.title, [@issue.project, @issue] } +%p You have been assigned to issue #{ link_to @issue.title, project_issue_url(@issue.project, @issue) } %p== Support team «ROSA Build System» diff --git a/app/views/user_mailer/issue_assign_notification.ru.haml b/app/views/user_mailer/issue_assign_notification.ru.haml index a6615d3eb..db96619f7 100644 --- a/app/views/user_mailer/issue_assign_notification.ru.haml +++ b/app/views/user_mailer/issue_assign_notification.ru.haml @@ -1,7 +1,7 @@ %p== Здравствуйте, #{@user.name}. -%p Вам была назначена задача #{ link_to @issue.title, [@issue.project, @issue] } +%p Вам была назначена задача #{ link_to @issue.title, project_issue_url(@issue.project, @issue) } %p== Команда поддержки «ROSA Build System» diff --git a/app/views/user_mailer/new_comment_notification.en.haml b/app/views/user_mailer/new_comment_notification.en.haml index 2c7fb66cb..99c1a4bfe 100644 --- a/app/views/user_mailer/new_comment_notification.en.haml +++ b/app/views/user_mailer/new_comment_notification.en.haml @@ -1,14 +1,14 @@ %p== Hello, #{@user.name}. - if @comment.commentable.class == Issue - - link = link_to @comment.commentable.title, [@comment.commentable.project, @comment.commentable] + - link = link_to @comment.commentable.title, project_issue_url(@comment.commentable.project, @comment.commentable) - object = 'issue' - elsif @comment.commentable.class == Grit::Commit - - link = link_to @comment.commentable.message, commit_path(@comment.project, @comment.commentable_id) + - link = link_to @comment.commentable.message, commit_url(@comment.project, @comment.commentable_id) - object = 'commit' -%p #{ link_to @comment.user.uname, user_path(@comment.user)} added new comment to #{object} #{link}. +%p #{ link_to @comment.user.uname, user_url(@comment.user)} added new comment to #{object} #{link}. %p "#{ @comment.body }" -%p== Support team «ROSA Build System» \ No newline at end of file +%p== Support team «ROSA Build System» diff --git a/app/views/user_mailer/new_comment_notification.ru.haml b/app/views/user_mailer/new_comment_notification.ru.haml index d1c0734dd..1dcab28a8 100644 --- a/app/views/user_mailer/new_comment_notification.ru.haml +++ b/app/views/user_mailer/new_comment_notification.ru.haml @@ -1,12 +1,12 @@ %p== Здравствуйте, #{@user.name}. - if @comment.commentable.class == Issue - - link = link_to @comment.commentable.title, [@comment.commentable.project, @comment.commentable] + - link = link_to @comment.commentable.title, project_issue_url(@comment.commentable.project, @comment.commentable) - object = 'задаче' - elsif @comment.commentable.class == Grit::Commit - - link = link_to @comment.commentable.message, commit_path(@comment.project, @comment.commentable_id) + - link = link_to @comment.commentable.message, commit_url(@comment.project, @comment.commentable_id) - object = 'коммиту' -%p #{ link_to @comment.user.uname, user_path(@comment.user)} добавил комментарий к #{object} #{link}. +%p #{ link_to @comment.user.uname, user_url(@comment.user)} добавил комментарий к #{object} #{link}. %p "#{ @comment.body }" diff --git a/app/views/user_mailer/new_comment_reply_notification.en.haml b/app/views/user_mailer/new_comment_reply_notification.en.haml index 9324062f2..b2838b2e0 100644 --- a/app/views/user_mailer/new_comment_reply_notification.en.haml +++ b/app/views/user_mailer/new_comment_reply_notification.en.haml @@ -1,7 +1,7 @@ %p== Hello, #{@user.name}. - -%p Your comment into issue #{ link_to @comment.commentable.title, [@comment.commentable.project, @comment.commentable] } has been answered. +- #TODO hmm... this need to be refactored. +%p Your comment into issue #{ link_to @comment.commentable.title, project_issue_url(@comment.commentable.project, @comment.commentable) } has been answered. %p "#{ @comment.body }" diff --git a/app/views/user_mailer/new_issue_notification.en.haml b/app/views/user_mailer/new_issue_notification.en.haml index f814fa617..7ddda0017 100644 --- a/app/views/user_mailer/new_issue_notification.en.haml +++ b/app/views/user_mailer/new_issue_notification.en.haml @@ -1,7 +1,7 @@ %p== Hello, #{@user.name}. -%p To project #{ link_to @issue.project.name, project_path(@issue.project) } has been added an issue #{ link_to @issue.title, [@issue.project, @issue] } +%p To project #{ link_to @issue.project.name, project_url(@issue.project) } has been added an issue #{ link_to @issue.title, project_issue_url(@issue.project, @issue) } %p== Support team «ROSA Build System» diff --git a/app/views/user_mailer/new_issue_notification.ru.haml b/app/views/user_mailer/new_issue_notification.ru.haml index 3a2604cfb..4255c06c2 100644 --- a/app/views/user_mailer/new_issue_notification.ru.haml +++ b/app/views/user_mailer/new_issue_notification.ru.haml @@ -1,7 +1,7 @@ %p== Здравствуйте, #{@user.name}. -%p К проекту #{ link_to @issue.project.name, project_path(@issue.project) } была добавлена задача #{ link_to @issue.title, [@issue.project, @issue] } +%p К проекту #{ link_to @issue.project.name, project_url(@issue.project) } была добавлена задача #{ link_to @issue.title, project_issue_url(@issue.project, @issue) } %p== Команда поддержки «ROSA Build System» diff --git a/app/views/wiki/_compare.html.haml b/app/views/wiki/_compare.html.haml index 48f2da74c..3496a8f33 100644 --- a/app/views/wiki/_compare.html.haml +++ b/app/views/wiki/_compare.html.haml @@ -2,7 +2,7 @@ = link_to t("wiki.revert_page#{action_name == 'revert' ? '' : 's'}"), '#', :class => "gollum-revert-button button width100" - if action_name != 'revert' - = form_tag revert_path(@project, @versions[0][0..6], @versions[1][0..6], @name), :name => "gollum-revert", :id => "gollum-revert-form" do + = form_tag revert_path(@project, @versions.first[0..6], (@versions.size == 1) ? 'prev' : @versions.last[0..6], @name), :name => "gollum-revert", :id => "gollum-revert-form" do = revert_button if can? :write, @project %br @@ -20,4 +20,4 @@ %br %br -= link_to t("wiki.back_to_top"), '#wiki' \ No newline at end of file += link_to t("wiki.back_to_top"), '#wiki' diff --git a/app/views/wiki/_diff_data.html.haml b/app/views/wiki/_diff_data.html.haml index e0a5442c5..d0d09811b 100644 --- a/app/views/wiki/_diff_data.html.haml +++ b/app/views/wiki/_diff_data.html.haml @@ -1,4 +1,4 @@ .blob_header -  .size= h(diff.deleted_file ? diff.a_path : diff.b_path) -.clear + .size= h(diff.deleted_file ? diff.a_path : diff.b_path).encode_to_default + .clear .diff_data.highlight= render_diff(diff) \ No newline at end of file diff --git a/lib/post-receive-hook b/bin/post-receive-hook.partial old mode 100755 new mode 100644 similarity index 51% rename from lib/post-receive-hook rename to bin/post-receive-hook.partial index b577daa5b..b1e39a205 --- a/lib/post-receive-hook +++ b/bin/post-receive-hook.partial @@ -9,7 +9,4 @@ owner=`basename \`dirname $pwd\`` while read oldrev newrev ref do newrev_type=$(git cat-file -t $newrev 2> /dev/null) - oldrev_type=$(git cat-file -t "$oldrev" 2> /dev/null) - - /bin/bash -l -c "cd /srv/rosa_build/current && bundle exec rails runner 'Project.delay.process_hook(\"$owner\", \"$reponame\", \"$newrev\", \"$oldrev\", \"$ref\", \"$newrev_type\", \"$oldrev_type\")'" -done \ No newline at end of file + oldrev_type=$(git cat-file -t "$oldrev" 2> /dev/null) \ No newline at end of file diff --git a/config/deploy.rb b/config/deploy.rb index 589fdc7dd..00a72abc9 100644 --- a/config/deploy.rb +++ b/config/deploy.rb @@ -63,8 +63,9 @@ namespace :deploy do end after "deploy:update_code", "deploy:symlink_all", "deploy:migrate" -after "deploy:restart","bluepill:stop", "delayed_job:restart", "deploy:cleanup", "bluepill:start" after "deploy:setup", "deploy:symlink_pids" +after "deploy:restart", "bluepill:start" # "bluepill:processes:restart_dj" # "bluepill:restart" +after "deploy:restart", "deploy:cleanup" require 'cape' namespace :rake_tasks do diff --git a/config/environments/production.rb b/config/environments/production.rb index 79767a16e..2d894a54a 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -37,7 +37,7 @@ Rosa::Application.configure do # Disable delivery errors, bad email addresses will be ignored # config.action_mailer.raise_delivery_errors = false - config.action_mailer.default_url_options = { :host => 'rosa-build.rosalab.ru' } + config.action_mailer.default_url_options = { :host => 'abf.rosalinux.ru' } # Enable threaded mode # config.threadsafe! diff --git a/config/locales/en.yml b/config/locales/en.yml index 5c52ce065..b7fddcfcc 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -61,7 +61,7 @@ en: downloads: title: Downloads statistic - message: Automatically updated every 5 minutes + message: Automatically updated every 24 hours refresh_btn: Refresh auto_build_lists: @@ -422,7 +422,7 @@ en: list_header: Event log repositories: - empty: Empty repository + empty: "Repository is empty. You need to wait some time if you have forked project or imported package" source: Source commits: Commits commit_diff_too_big: Sorry, commit too big! @@ -813,6 +813,7 @@ en: product_build_list: id: Id product: Product + container_path: Container status: Status notified_at: Notified at diff --git a/config/locales/ru.yml b/config/locales/ru.yml index a03816d66..ecbddb43d 100644 --- a/config/locales/ru.yml +++ b/config/locales/ru.yml @@ -61,7 +61,7 @@ ru: downloads: title: Статистика закачек пакетов - message: Обновляется автоматически каждые 5 минут + message: Обновляется автоматически каждые 24 часа refresh_btn: Обновить auto_build_lists: @@ -289,7 +289,7 @@ ru: git: repositories: - empty: Пустой репозиторий + empty: "Репозиторий пуст. Если вы клонировали(Fork) проект или импортировали пакет, данные скоро появятся" source: Source commits: Commits commit_diff_too_big: Извините, коммит слишком большой! @@ -675,6 +675,7 @@ ru: product_build_list: id: Id product: Продукт + container_path: Контейнер status: Статус notified_at: Информация получена diff --git a/config/production.pill b/config/production.pill index ff49759fc..3199e382a 100644 --- a/config/production.pill +++ b/config/production.pill @@ -11,6 +11,7 @@ Bluepill.application(app_name) do |app| process.start_command = "/usr/bin/env RAILS_ENV=production script/delayed_job start" process.stop_command = "/usr/bin/env RAILS_ENV=production script/delayed_job stop" + process.restart_command = "/usr/bin/env RAILS_ENV=production script/delayed_job restart" process.pid_file = File.join(app.working_dir, 'tmp', 'pids', 'delayed_job.pid') end diff --git a/config/routes.rb b/config/routes.rb index 85c55624c..166ac6f35 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -72,7 +72,7 @@ Rosa::Application.routes.draw do post 'freeze' post 'unfreeze' get 'clone' - post 'clone' + post 'make_clone' post 'build_all' end diff --git a/config/schedule.rb b/config/schedule.rb index f966ecc1d..f1d6faa22 100644 --- a/config/schedule.rb +++ b/config/schedule.rb @@ -7,7 +7,7 @@ # runner "Download.parse_and_remove_nginx_log" #end -every 5.minutes do +every 1.day, :at => '5:00' do #rake "sudo_test:projects" runner "Download.rotate_nginx_log" runner "Download.parse_and_remove_nginx_log" diff --git a/db/migrate/20120131141651_write_git_hook_to_projects.rb b/db/migrate/20120131141651_write_git_hook_to_projects.rb deleted file mode 100644 index d8dded706..000000000 --- a/db/migrate/20120131141651_write_git_hook_to_projects.rb +++ /dev/null @@ -1,13 +0,0 @@ -class WriteGitHookToProjects < ActiveRecord::Migration - def self.up - origin_hook = File.join(::Rails.root.to_s, 'lib', 'post-receive-hook') - Project.all.each do |project| - hook_file = File.join(project.path, 'hooks', 'post-receive') - FileUtils.cp(origin_hook, hook_file) - end - end - - def self.down - Project.all.each { |project| FileUtils.rm_rf File.join(project.path, 'hooks', 'post-receive')} - end -end diff --git a/db/migrate/20120206194328_remove_orphan_platforms.rb b/db/migrate/20120206194328_remove_orphan_platforms.rb deleted file mode 100644 index aa922710a..000000000 --- a/db/migrate/20120206194328_remove_orphan_platforms.rb +++ /dev/null @@ -1,8 +0,0 @@ -class RemoveOrphanPlatforms < ActiveRecord::Migration - def self.up - Platform.all.each {|x| x.destroy unless x.owner.present?} - end - - def self.down - end -end diff --git a/db/migrate/20120220185458_remove_repositories_owner.rb b/db/migrate/20120220185458_remove_repositories_owner.rb new file mode 100644 index 000000000..88c85a855 --- /dev/null +++ b/db/migrate/20120220185458_remove_repositories_owner.rb @@ -0,0 +1,12 @@ +class RemoveRepositoriesOwner < ActiveRecord::Migration + def self.up + remove_column :repositories, :owner_id + remove_column :repositories, :owner_type + Relation.delete_all(:target_type => 'Repository') + end + + def self.down + add_column :repositories, :owner_id, :integer + add_column :repositories, :owner_type, :string + end +end diff --git a/db/schema.rb b/db/schema.rb index b8434e5bb..04049bb98 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,11 @@ # # It's strongly recommended to check this file into your version control system. +<<<<<<< HEAD ActiveRecord::Schema.define(:version => 20120214021626) do +======= +ActiveRecord::Schema.define(:version => 20120220185458) do +>>>>>>> master create_table "arches", :force => true do |t| t.string "name", :null => false @@ -295,8 +299,6 @@ ActiveRecord::Schema.define(:version => 20120214021626) do t.datetime "created_at" t.datetime "updated_at" t.string "name", :null => false - t.integer "owner_id" - t.string "owner_type" end create_table "rpms", :force => true do |t| diff --git a/lib/build_server.rb b/lib/build_server.rb index feb066b19..9aa2be76e 100644 --- a/lib/build_server.rb +++ b/lib/build_server.rb @@ -28,28 +28,32 @@ class BuildServer self.client.call('add_platform', name, platforms_root_folder, repos, distrib_type) end - def self.delete_platform name self.client.call('delete_platform', name) + rescue Timeout::Error => e # TODO remove this when core will be ready + 0 end - def self.clone_platform new_name, old_name, new_root_folder self.client.call('clone_platform', new_name, old_name, new_root_folder) + rescue Timeout::Error => e # TODO remove this when core will be ready + 0 end - def self.create_repo name, platform_name self.client.call('create_repository', name, platform_name) end - def self.delete_repo name, platform_name self.client.call('delete_repository', name, platform_name) + rescue Timeout::Error => e # TODO remove this when core will be ready + 0 end def self.clone_repo new_name, old_name, new_platform_name self.client.call('clone_repo', new_name, old_name, new_platform_name) + rescue Timeout::Error => e # TODO remove this when core will be ready + 0 end diff --git a/lib/ext/core/object.rb b/lib/ext/core/object.rb new file mode 100644 index 000000000..d2856a51c --- /dev/null +++ b/lib/ext/core/object.rb @@ -0,0 +1,10 @@ +class Object + def with_skip + begin + Thread.current[:skip] = true + yield + ensure + Thread.current[:skip] = false + end + end +end diff --git a/lib/gollum/wiki.rb b/lib/gollum/wiki.rb index 14e8ae614..70ef08e46 100644 --- a/lib/gollum/wiki.rb +++ b/lib/gollum/wiki.rb @@ -87,6 +87,11 @@ module Gollum end alias_method_chain :revert_page, :committer + def revert_commit_with_committer(sha1, sha2 = nil, commit = {}) + revert_page_with_committer(nil, sha1, sha2, commit) + end + alias_method_chain :revert_commit, :committer + private def force_grit_encoding(str) diff --git a/lib/modules/models/personal_repository.rb b/lib/modules/models/personal_repository.rb index 8ee4fd3d8..5b903ecae 100644 --- a/lib/modules/models/personal_repository.rb +++ b/lib/modules/models/personal_repository.rb @@ -16,11 +16,10 @@ module Modules pl.description = "#{self.uname}_personal" pl.platform_type = 'personal' pl.distrib_type = APP_CONFIG['distr_types'].first - pl.visibility = 'hidden' + pl.visibility = 'open' pl.save! rep = pl.repositories.build - rep.owner = pl.owner rep.name = 'main' rep.description = 'main' rep.save! diff --git a/lib/modules/models/rsync_stub.rb b/lib/modules/models/rsync_stub.rb index bbf101d76..7865c232f 100644 --- a/lib/modules/models/rsync_stub.rb +++ b/lib/modules/models/rsync_stub.rb @@ -5,6 +5,10 @@ module Modules extend ActiveSupport::Concern included do + def create_directory + true + end + def mount_directory_for_rsync true end diff --git a/lib/recipes/bluepill.rb b/lib/recipes/bluepill.rb index a84ff7ecb..969728664 100644 --- a/lib/recipes/bluepill.rb +++ b/lib/recipes/bluepill.rb @@ -3,29 +3,46 @@ Capistrano::Configuration.instance(:must_exist).load do namespace :bluepill do set(:bluepill_binary) {"bundle exec bluepill --no-privileged"} - desc "Load bluepill configuration and start it" + namespace :processes do + desc "Start processes that bluepill is monitoring" + task :start, :roles => [:app] do + run "cd #{fetch :current_path} && #{try_sudo} #{bluepill_binary} #{fetch :application} start" + end + + desc "Stop processes that bluepill is monitoring" + task :stop, :roles => [:app], :on_error => :continue do + run "cd #{fetch :current_path} && #{try_sudo} #{bluepill_binary} #{fetch :application} stop" + end + + desc "Restart processes that bluepill is monitoring" + task :restart, :roles => [:app] do + run "cd #{fetch :current_path} && #{try_sudo} #{bluepill_binary} #{fetch :application} restart" + end + + desc "Prints bluepills monitored processes statuses" + task :status, :roles => [:app] do + run "cd #{fetch :current_path} && #{try_sudo} #{bluepill_binary} #{fetch :application} status" + end + + desc "Restart DJ process" + task :restart_dj, :roles => [:app] do + run "cd #{fetch :current_path} && #{try_sudo} #{bluepill_binary} #{fetch :application} restart delayed_job" + end + end + + desc "Start a bluepill process and load a config" task :start, :roles => [:app] do run "cd #{fetch :current_path} && #{try_sudo} APP_NAME=#{fetch :application} #{bluepill_binary} load config/production.pill" end - desc "Stop processes that bluepill is monitoring" - task :stop, :roles => [:app], :on_error => :continue do - run "cd #{fetch :current_path} && #{try_sudo} #{bluepill_binary} #{fetch :application} stop" - end - - task :restart, :roles => [:app] do - # run "cd #{fetch :current_path} && #{try_sudo} #{bluepill_binary} #{fetch :application} restart" - stop; quit; start - end - - desc "Stop processes that bluepill is monitoring and quit bluepill" - task :quit, :roles => [:app] do + desc "Quit bluepill" + task :stop, :roles => [:app] do run "cd #{fetch :current_path} && #{try_sudo} #{bluepill_binary} #{fetch :application} quit" end - desc "Prints bluepills monitored processes statuses" - task :status, :roles => [:app] do - run "cd #{fetch :current_path} && #{try_sudo} #{bluepill_binary} #{fetch :application} status" + desc "Completely restart bluepill and monitored services" + task :restart, :roles => [:app] do + processes.stop; stop; start end end end diff --git a/lib/tasks/add_branch.rake b/lib/tasks/add_branch.rake new file mode 100644 index 000000000..1a7b96bd5 --- /dev/null +++ b/lib/tasks/add_branch.rake @@ -0,0 +1,22 @@ +require 'highline/import' + +desc "Add branch for platform projects" +task :add_branch => :environment do + src_branch = ENV['SRC_BRANCH'] || 'import_mandriva2011' + dst_branch = ENV['DST_BRANCH'] || 'rosa2012lts' + + say "START add branch #{dst_branch} from #{src_branch}" + Platform.find_by_name(dst_branch).repositories.each do |r| + say "=== Process #{r.name} repo" + r.projects.find_each do |p| + say "===== Process #{p.name} project" + tmp_path = Rails.root.join('tmp', p.name) + system("git clone #{p.path} #{tmp_path}") + system("cd #{tmp_path} && git checkout remotes/origin/#{src_branch}") or system("cd #{tmp_path} && git checkout master") + system("cd #{tmp_path} && git checkout -b #{dst_branch}") + system("cd #{tmp_path} && git push origin HEAD") + FileUtils.rm_rf tmp_path + end + end + say 'DONE' +end diff --git a/lib/tasks/hook.rake b/lib/tasks/hook.rake new file mode 100644 index 000000000..d41bbafdb --- /dev/null +++ b/lib/tasks/hook.rake @@ -0,0 +1,39 @@ +namespace :hook do + desc "Inserting hook to all repos" + task :install => :environment do + is_production = ENV['RAILS_ENV'] == 'production' + say "Generate temporary file..." + hook = File.join(::Rails.root.to_s, 'tmp', "post-receive-hook") + FileUtils.cp(File.join(::Rails.root.to_s, 'bin', "post-receive-hook.partial"), hook) + File.open(hook, 'a') do |f| + s = "\n /bin/bash -l -c \"cd #{is_production ? '/srv/rosa_build/current' : Rails.root.to_s} && #{is_production ? 'RAILS_ENV=production' : ''} bundle exec rails runner 'Project.delay.process_hook(\"$owner\", \"$reponame\", \"$newrev\", \"$oldrev\", \"$ref\", \"$newrev_type\", \"$oldrev_type\")'\"" + s << " > /dev/null 2>&1" if is_production + s << "\ndone\n" + f.write(s) + end + + say "Install process.." + count = 0 + projects = ENV['project_id'] ? Project.where(:id => eval(ENV['project_id'])) : Project + projects.where('created_at >= ?', Time.now.ago(ENV['period'] ? eval(ENV['period']) : 100.years)).each do |project| + hook_file = File.join(project.path, 'hooks', 'post-receive') + FileUtils.cp(hook, hook_file) + count = count + 1 + end + say "Writing to #{count.to_s} repo(s)" + say "Removing temporary file" + FileUtils.rm_rf(hook) + end + + desc "remove git hook from all repos" + task :remove => :environment do + say "process.." + count = 0 + projects = ENV['project_id'] ? Project.where(:id => eval(ENV['project_id'])) : Project + projects.where('created_at >= ?', Time.now.ago(ENV['period'] ? eval(ENV['period']) : 100.years)).each do |project| + FileUtils.rm_rf File.join(project.path, 'hooks', 'post-receive') + count = count + 1 + end + say "Done! Removing from #{count.to_s} repo(s)" + end +end diff --git a/lib/tasks/import.rake b/lib/tasks/import.rake index b59a7112e..1649e395a 100644 --- a/lib/tasks/import.rake +++ b/lib/tasks/import.rake @@ -47,7 +47,7 @@ namespace :import do source = "rsync://mirror.yandex.ru/mandriva/#{release}/SRPMS/#{repository}/" destination = ENV['DESTINATION'] || File.join(APP_CONFIG['root_path'], 'mirror.yandex.ru', 'mandriva', release, 'SRPMS', repository) say "START rsync projects (*.src.rpm) from '#{source}' to '#{destination}'" - if system "rsync -rtv --delete --exclude='backports/*' --exclude='testing/*' #{source} #{destination}" # --include='*.src.rpm' + if system "rsync -rtv --exclude='backports/*' --exclude='testing/*' #{source} #{destination}" # --delete --include='*.src.rpm' say 'Rsync ok!' else say 'Rsync failed!' diff --git a/spec/controllers/collaborators_controller_spec.rb b/spec/controllers/collaborators_controller_spec.rb index c7dcaa4b5..858bd3c05 100644 --- a/spec/controllers/collaborators_controller_spec.rb +++ b/spec/controllers/collaborators_controller_spec.rb @@ -37,6 +37,7 @@ end describe CollaboratorsController do before(:each) do + stub_rsync_methods @project = Factory(:project) @another_user = Factory(:user) @update_params = {:user => {:read => {@another_user.id => '1'}}} diff --git a/spec/controllers/groups_controller_spec.rb b/spec/controllers/groups_controller_spec.rb index 2ccf820b3..4238babf8 100644 --- a/spec/controllers/groups_controller_spec.rb +++ b/spec/controllers/groups_controller_spec.rb @@ -3,6 +3,7 @@ require 'spec_helper' describe GroupsController do before(:each) do + stub_rsync_methods @group = Factory(:group) @another_user = Factory(:user) @create_params = {:group => {:name => 'grp1', :uname => 'un_grp1'}} diff --git a/spec/controllers/members_controller_spec.rb b/spec/controllers/members_controller_spec.rb index 512bbc73c..ab8ab5fbe 100644 --- a/spec/controllers/members_controller_spec.rb +++ b/spec/controllers/members_controller_spec.rb @@ -3,6 +3,7 @@ require 'spec_helper' describe MembersController do before(:each) do + stub_rsync_methods @group = Factory(:group) @user = @group.owner set_session_for @user diff --git a/spec/controllers/personal_repositories_controller_spec.rb b/spec/controllers/personal_repositories_controller_spec.rb index 50ff6f03f..6e020d61e 100644 --- a/spec/controllers/personal_repositories_controller_spec.rb +++ b/spec/controllers/personal_repositories_controller_spec.rb @@ -92,9 +92,6 @@ describe PersonalRepositoriesController do @project.update_attribute(:owner, @user) - @repository.update_attribute(:owner, @user) - @repository.relations.create!(:object_type => 'User', :object_id => @user.id, :role => 'admin') - @repository.platform.update_attribute(:owner, @user) @repository.platform.relations.create!(:object_type => 'User', :object_id => @user.id, :role => 'admin') end @@ -108,7 +105,7 @@ describe PersonalRepositoriesController do before(:each) do @user = Factory(:user) set_session_for(@user) - @repository.relations.create!(:object_type => 'User', :object_id => @user.id, :role => 'reader') + @repository.platform.relations.create!(:object_type => 'User', :object_id => @user.id, :role => 'reader') end it_should_behave_like 'personal repository viewer' diff --git a/spec/controllers/repositories_controller_spec.rb b/spec/controllers/repositories_controller_spec.rb index 935de2e40..422fb5128 100644 --- a/spec/controllers/repositories_controller_spec.rb +++ b/spec/controllers/repositories_controller_spec.rb @@ -79,8 +79,8 @@ describe RepositoriesController do before(:each) do @user = Factory(:user) set_session_for(@user) - @repository.update_attribute(:owner, @user) - @repository.relations.create!(:object_type => 'User', :object_id => @user.id, :role => 'admin') + @repository.platform.update_attribute(:owner, @user) + @repository.platform.relations.create!(:object_type => 'User', :object_id => @user.id, :role => 'admin') end it_should_behave_like 'repository user with owner rights' @@ -90,7 +90,7 @@ describe RepositoriesController do before(:each) do @user = Factory(:user) set_session_for(@user) - @repository.relations.create!(:object_type => 'User', :object_id => @user.id, :role => 'reader') + @repository.platform.relations.create!(:object_type => 'User', :object_id => @user.id, :role => 'reader') end it_should_behave_like 'repository user with reader rights' diff --git a/spec/factories/repository_factory.rb b/spec/factories/repository_factory.rb index 2188bc17e..4af755b28 100644 --- a/spec/factories/repository_factory.rb +++ b/spec/factories/repository_factory.rb @@ -3,18 +3,12 @@ Factory.define(:repository) do |p| p.description { Factory.next(:string) } p.name { Factory.next(:unixname) } p.association :platform, :factory => :platform - p.association :owner, :factory => :user end -Factory.define(:personal_repository, :class => Repository) do |p| - p.description { Factory.next(:string) } - p.name { Factory.next(:unixname) } - p.association :platform, :factory => :platform - p.association :owner, :factory => :user - - p.after_create { |rep| - rep.platform.platform_type = 'personal' - rep.platform.visibility = 'hidden' - rep.platform.save! +Factory.define(:personal_repository, :parent => :repository) do |p| + p.after_create {|r| + r.platform.platform_type = 'personal' + r.platform.visibility = 'hidden' + r.platform.save! } end diff --git a/spec/models/cancan_spec.rb b/spec/models/cancan_spec.rb index 597d5dd38..248a502d6 100644 --- a/spec/models/cancan_spec.rb +++ b/spec/models/cancan_spec.rb @@ -278,24 +278,19 @@ describe CanCan do context 'with owner rights' do before(:each) do - @repository.update_attribute(:owner, @user) + @repository.platform.update_attribute(:owner, @user) end - [:read, :update, :destroy, :add_project, :remove_project, :change_visibility, :settings].each do |action| + [:read, :create, :update, :destroy, :add_project, :remove_project, :change_visibility, :settings].each do |action| it "should be able to #{action} repository" do @ability.should be_able_to(action, @repository) end end - - it do - @repository.platform.update_attribute(:owner, @user) - @ability.should be_able_to(:create, @repository) - end end context 'with read rights' do before(:each) do - @repository.relations.create!(:object_id => @user.id, :object_type => 'User', :role => 'reader') + @repository.platform.relations.create!(:object_id => @user.id, :object_type => 'User', :role => 'reader') end it "should be able to read repository" do diff --git a/spec/models/comment_for_commit_spec.rb b/spec/models/comment_for_commit_spec.rb index aa16193a2..d2b6a61da 100644 --- a/spec/models/comment_for_commit_spec.rb +++ b/spec/models/comment_for_commit_spec.rb @@ -21,6 +21,7 @@ def set_comments_data_for_commit end describe Comment do + before { stub_rsync_methods } context 'for global admin user' do before(:each) do @user = Factory(:admin) diff --git a/spec/models/comment_spec.rb b/spec/models/comment_spec.rb index b44f85684..d692beb19 100644 --- a/spec/models/comment_spec.rb +++ b/spec/models/comment_spec.rb @@ -15,6 +15,7 @@ def set_commentable_data end describe Comment do + before { stub_rsync_methods } context 'for global admin user' do before(:each) do @user = Factory(:admin) diff --git a/spec/models/repository_spec.rb b/spec/models/repository_spec.rb index 9056e45c7..c742a5671 100644 --- a/spec/models/repository_spec.rb +++ b/spec/models/repository_spec.rb @@ -10,14 +10,9 @@ describe Repository do @params = {:name => 'tst_platform', :description => 'test platform'} end - it 'it should increase Relations.count by 1' do - rep = Repository.new(@params) - rep.platform = @platform - rep.owner = @platform.owner - rep.save! - Relation.by_object(rep.owner).by_target(rep).count.should eql(1) -# (@platform.owner.repositories.where(:platform_id => @platform.id).count == 1).should be_true + it 'it should increase Repository.count by 1' do + rep = Repository.create(@params) {|r| r.platform = @platform} + @platform.repositories.count.should eql(1) end end - #pending "add some examples to (or delete) #{__FILE__}" end diff --git a/spec/models/subscribe_spec.rb b/spec/models/subscribe_spec.rb index eff91b9a8..40ccddd3c 100644 --- a/spec/models/subscribe_spec.rb +++ b/spec/models/subscribe_spec.rb @@ -12,6 +12,7 @@ def set_testable_data end describe Subscribe do + before { stub_rsync_methods } context 'for global admin user' do before(:each) do @user = Factory(:admin)