From 44de11d009b42011bb0a73cf09a74c6ed1f6614f Mon Sep 17 00:00:00 2001 From: "konstantin.grabar" Date: Mon, 28 May 2012 21:47:53 +0400 Subject: [PATCH 01/61] [refs #505] Add events, states and other base state machine logic --- Gemfile | 1 + Gemfile.lock | 1 + app/models/build_list.rb | 73 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 75 insertions(+) diff --git a/Gemfile b/Gemfile index f4bcc710b..1691f9efd 100644 --- a/Gemfile +++ b/Gemfile @@ -17,6 +17,7 @@ gem 'paperclip', '~> 3.0.2' gem 'delayed_job_active_record', '~> 0.3.2' gem 'russian', '~> 0.6.0' gem 'highline', '~> 1.6.11' +gem 'state_machine' gem 'jbuilder' diff --git a/Gemfile.lock b/Gemfile.lock index 4b3b34f2f..fda927bb5 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -364,6 +364,7 @@ DEPENDENCIES sass-rails (~> 3.2.5) shotgun shoulda + state_machine therubyracer (~> 0.10.1) therubyrhino (~> 1.73.1) trinidad (~> 1.0.2) diff --git a/app/models/build_list.rb b/app/models/build_list.rb index 3cee985fb..f34843d9e 100644 --- a/app/models/build_list.rb +++ b/app/models/build_list.rb @@ -100,6 +100,79 @@ class BuildList < ActiveRecord::Base after_create :place_build after_destroy :delete_container + state_machine :status, :initial => :waiting_for_response do + + event :wait_assembly do + transition :waiting_for_response => :build_pending + end + + event :wait_platform do + transition :waiting_for_response => :platform_pending + end + + event :lose_platform do + transition :waiting_for_response => :platform_not_found + end + + event :lose_project do + transition :waiting_for_response => :project_not_found + end + + event :lose_project_version do + transition :waiting_for_response => :project_version_not_found + end + + event :start do + transition [ + :build_pending, + :platform_pending + ] => :build_started + end + + event :cancel do + transition [ + :build_pending, + :platform_pending + ] => :build_canceled, :if => lambda { |build_list| build_list.can_cancel? } + end + + event :finish_build do + transition [ + :build_started, + :build_canceled + ] => :success + end + + event :fail_build do + transition :build_started => :build_error + end + + event :publish do + transition [ + :success, + :failed_publish + ] => :build_publish, :if => lambda { |build_list| build_list.can_publish? } # TODO: Remove can_publish? + # we do not need this after state machine + end + + event :reject_publish do + transition :success => :rejected_publish, :if => lambda { |build_list| build_list.can_reject_publish? } + end + + event :finish_publish do + transition :build_publish => :build_published + end + + event :fail_publish do + transition :build_publish => :failed_publish + end + + HUMAN_STATUSES.each do |code,name| + state name, :value => code + end + + end + def self.human_status(status) I18n.t("layout.build_lists.statuses.#{HUMAN_STATUSES[status]}") end From 3d3e1094838934bf99212acf6ec9899230d6c16c Mon Sep 17 00:00:00 2001 From: "konstantin.grabar" Date: Tue, 29 May 2012 21:28:11 +0400 Subject: [PATCH 02/61] [refs #505] Add check ability methods and update some events --- app/models/build_list.rb | 77 ++++++++++++++++++++++------------------ 1 file changed, 43 insertions(+), 34 deletions(-) diff --git a/app/models/build_list.rb b/app/models/build_list.rb index f34843d9e..76bf8f0dd 100644 --- a/app/models/build_list.rb +++ b/app/models/build_list.rb @@ -133,7 +133,7 @@ class BuildList < ActiveRecord::Base transition [ :build_pending, :platform_pending - ] => :build_canceled, :if => lambda { |build_list| build_list.can_cancel? } + ] => :build_canceled, :if => :can_cancel? end event :finish_build do @@ -151,12 +151,15 @@ class BuildList < ActiveRecord::Base transition [ :success, :failed_publish - ] => :build_publish, :if => lambda { |build_list| build_list.can_publish? } # TODO: Remove can_publish? - # we do not need this after state machine + ] => :build_publish, :if => :can_publish? + transition [ + :success, + :failed_publish + ] => :build_publish, :if => :can_fail_publish? end event :reject_publish do - transition :success => :rejected_publish, :if => lambda { |build_list| build_list.can_reject_publish? } + transition :success => :rejected_publish, :if => :can_reject_publish? end event :finish_publish do @@ -173,6 +176,26 @@ class BuildList < ActiveRecord::Base end + #TODO: Share this checking on product owner. + def can_cancel? + has_canceled = BuildServer.delete_build_list bs_id + status == BUILD_PENDING && bs_id && has_canceled == 0 + end + + def can_publish? + status == BuildServer::SUCCESS or status == FAILED_PUBLISH + end + + def can_fail_publish? + has_published = BuildServer.publish_container bs_id + can_publish? && has_published != 0 + end + + def can_reject_publish? + can_publish? and save_to_platform.released + end + + def self.human_status(status) I18n.t("layout.build_lists.statuses.#{HUMAN_STATUSES[status]}") end @@ -199,37 +222,24 @@ class BuildList < ActiveRecord::Base end end - def publish - return false unless can_publish? - has_published = BuildServer.publish_container bs_id - update_attribute(:status, has_published == 0 ? BUILD_PUBLISH : FAILED_PUBLISH) - return has_published == 0 - end + #def publish + # return false unless can_publish? + # has_published = BuildServer.publish_container bs_id + # update_attribute(:status, has_published == 0 ? BUILD_PUBLISH : FAILED_PUBLISH) + # return has_published == 0 + #end - def can_publish? - status == BuildServer::SUCCESS or status == FAILED_PUBLISH - end + #def reject_publish + # return false unless can_reject_publish? + # update_attribute(:status, REJECTED_PUBLISH) + #end - def reject_publish - return false unless can_reject_publish? - update_attribute(:status, REJECTED_PUBLISH) - end - - def can_reject_publish? - can_publish? and save_to_platform.released - end - - def cancel - return false unless can_cancel? - has_canceled = BuildServer.delete_build_list bs_id - update_attribute(:status, BUILD_CANCELED) if has_canceled == 0 - return has_canceled == 0 - end - - #TODO: Share this checking on product owner. - def can_cancel? - status == BUILD_PENDING && bs_id - end + #def cancel + # return false unless can_cancel? + # has_canceled = BuildServer.delete_build_list bs_id + # update_attribute(:status, BUILD_CANCELED) if has_canceled == 0 + # return has_canceled == 0 + #end def event_log_message {:project => project.name, :version => project_version, :arch => arch.name}.inspect @@ -266,7 +276,6 @@ class BuildList < ActiveRecord::Base save end - def delete_container if can_cancel? BuildServer.delete_build_list bs_id From 05e117ac527b6e2fc358721b5514a2a49e5ba23e Mon Sep 17 00:00:00 2001 From: "konstantin.grabar" Date: Wed, 30 May 2012 16:42:30 +0400 Subject: [PATCH 03/61] [refs #505] state machine refactor --- app/models/build_list.rb | 47 ++++++++++++++++------------------------ 1 file changed, 19 insertions(+), 28 deletions(-) diff --git a/app/models/build_list.rb b/app/models/build_list.rb index 76bf8f0dd..9e1f3dabe 100644 --- a/app/models/build_list.rb +++ b/app/models/build_list.rb @@ -123,24 +123,18 @@ class BuildList < ActiveRecord::Base end event :start do - transition [ - :build_pending, - :platform_pending - ] => :build_started + transition [:build_pending, :platform_pending] => :build_started end event :cancel do - transition [ - :build_pending, - :platform_pending - ] => :build_canceled, :if => :can_cancel? + transition [:build_pending, :platform_pending] => :build_canceled, :if => lambda { |build_list| + has_canceled = BuildServer.delete_build_list build_list.bs_id + build_list.can_cancel? && has_canceled == 0 + } end event :finish_build do - transition [ - :build_started, - :build_canceled - ] => :success + transition [:build_started, :build_canceled] => :success end event :fail_build do @@ -148,14 +142,14 @@ class BuildList < ActiveRecord::Base end event :publish do - transition [ - :success, - :failed_publish - ] => :build_publish, :if => :can_publish? - transition [ - :success, - :failed_publish - ] => :build_publish, :if => :can_fail_publish? + transition [:success, :failed_publish] => :build_publish, :if => lambda { |build_list| + has_published = BuildServer.publish_container build_list.bs_id + build_list.can_publish? && has_published == 0 + } + transition [:success, :failed_publish] => :failed_publish, :if => lambda { |build_list| + has_published = BuildServer.publish_container build_list.bs_id + build_list.can_publish? && has_published != 0 + } end event :reject_publish do @@ -167,7 +161,10 @@ class BuildList < ActiveRecord::Base end event :fail_publish do - transition :build_publish => :failed_publish + transition :build_publish => :failed_publish, :if => lambda { |build_list| + has_published = BuildServer.publish_container build_list.bs_id + build_list.can_publish? && has_published != 0 + } end HUMAN_STATUSES.each do |code,name| @@ -178,19 +175,13 @@ class BuildList < ActiveRecord::Base #TODO: Share this checking on product owner. def can_cancel? - has_canceled = BuildServer.delete_build_list bs_id - status == BUILD_PENDING && bs_id && has_canceled == 0 + status == BUILD_PENDING && bs_id end def can_publish? status == BuildServer::SUCCESS or status == FAILED_PUBLISH end - def can_fail_publish? - has_published = BuildServer.publish_container bs_id - can_publish? && has_published != 0 - end - def can_reject_publish? can_publish? and save_to_platform.released end From a7d70c3474ca1eb107005eff51e84e90eb18f698 Mon Sep 17 00:00:00 2001 From: "konstantin.grabar" Date: Thu, 31 May 2012 18:35:37 +0400 Subject: [PATCH 04/61] [refs #505] Fix state machine workflow --- app/models/build_list.rb | 32 +++----------------------------- 1 file changed, 3 insertions(+), 29 deletions(-) diff --git a/app/models/build_list.rb b/app/models/build_list.rb index 9e1f3dabe..b95e92498 100644 --- a/app/models/build_list.rb +++ b/app/models/build_list.rb @@ -144,12 +144,9 @@ class BuildList < ActiveRecord::Base event :publish do transition [:success, :failed_publish] => :build_publish, :if => lambda { |build_list| has_published = BuildServer.publish_container build_list.bs_id - build_list.can_publish? && has_published == 0 - } - transition [:success, :failed_publish] => :failed_publish, :if => lambda { |build_list| - has_published = BuildServer.publish_container build_list.bs_id - build_list.can_publish? && has_published != 0 + has_published == 0 } + transition [:success, :failed_publish] => :failed_publish end event :reject_publish do @@ -163,7 +160,7 @@ class BuildList < ActiveRecord::Base event :fail_publish do transition :build_publish => :failed_publish, :if => lambda { |build_list| has_published = BuildServer.publish_container build_list.bs_id - build_list.can_publish? && has_published != 0 + has_published != 0 } end @@ -178,10 +175,6 @@ class BuildList < ActiveRecord::Base status == BUILD_PENDING && bs_id end - def can_publish? - status == BuildServer::SUCCESS or status == FAILED_PUBLISH - end - def can_reject_publish? can_publish? and save_to_platform.released end @@ -213,25 +206,6 @@ class BuildList < ActiveRecord::Base end end - #def publish - # return false unless can_publish? - # has_published = BuildServer.publish_container bs_id - # update_attribute(:status, has_published == 0 ? BUILD_PUBLISH : FAILED_PUBLISH) - # return has_published == 0 - #end - - #def reject_publish - # return false unless can_reject_publish? - # update_attribute(:status, REJECTED_PUBLISH) - #end - - #def cancel - # return false unless can_cancel? - # has_canceled = BuildServer.delete_build_list bs_id - # update_attribute(:status, BUILD_CANCELED) if has_canceled == 0 - # return has_canceled == 0 - #end - def event_log_message {:project => project.name, :version => project_version, :arch => arch.name}.inspect end From f188a83eca427663f80731f8339158f3be13ca73 Mon Sep 17 00:00:00 2001 From: "konstantin.grabar" Date: Fri, 1 Jun 2012 14:58:17 +0400 Subject: [PATCH 05/61] [refs #505] Add place_build event --- app/models/build_list.rb | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/app/models/build_list.rb b/app/models/build_list.rb index b95e92498..382527a6e 100644 --- a/app/models/build_list.rb +++ b/app/models/build_list.rb @@ -102,6 +102,23 @@ class BuildList < ActiveRecord::Base state_machine :status, :initial => :waiting_for_response do + event :place_build do + transition :waiting_for_response => :build_pending, :if => lambda { |build_list| + build_list.add_to_queue == BUILD_PENDING + } + [ + BuildServer::PLATFORM_PENDING, + BuildServer::PLATFORM_NOT_FOUND, + BuildServer::PROJECT_NOT_FOUND, + BuildServer::PROJECT_VERSION_NOT_FOUND, + BuildServer::PROJECT_VERSION_NOT_FOUND + ].each do |code| + transition :waiting_for_response => HUMAN_STATUSES[code], :if => lambda { |build_list| + build_list.add_to_queue == code + } + end + end + event :wait_assembly do transition :waiting_for_response => :build_pending end @@ -180,6 +197,11 @@ class BuildList < ActiveRecord::Base end + def add_to_queue + #XML-RPC params: project_name, project_version, plname, arch, bplname, update_type, build_requires, id_web, include_repos, priority + @status ||= BuildServer.add_build_list project.name, project_version, save_to_platform.name, arch.name, (save_to_platform_id == build_for_platform_id ? '' : build_for_platform.name), update_type, build_requires, id, include_repos, priority + end + def self.human_status(status) I18n.t("layout.build_lists.statuses.#{HUMAN_STATUSES[status]}") end @@ -234,13 +256,6 @@ class BuildList < ActiveRecord::Base return true end - def place_build - #XML-RPC params: project_name, project_version, plname, arch, bplname, update_type, build_requires, id_web, include_repos, priority - self.status = BuildServer.add_build_list project.name, project_version, save_to_platform.name, arch.name, (save_to_platform_id == build_for_platform_id ? '' : build_for_platform.name), update_type, build_requires, id, include_repos, priority - self.status = BUILD_PENDING if self.status == 0 - save - end - def delete_container if can_cancel? BuildServer.delete_build_list bs_id From 2eff4d11607ffeb2c4a356640b01a06b883f0b24 Mon Sep 17 00:00:00 2001 From: "konstantin.grabar" Date: Fri, 1 Jun 2012 15:06:59 +0400 Subject: [PATCH 06/61] [refs #505] Remove unnessacary set_default_status method --- app/models/build_list.rb | 6 ------ 1 file changed, 6 deletions(-) diff --git a/app/models/build_list.rb b/app/models/build_list.rb index 382527a6e..bd42df38d 100644 --- a/app/models/build_list.rb +++ b/app/models/build_list.rb @@ -96,7 +96,6 @@ class BuildList < ActiveRecord::Base serialize :additional_repos serialize :include_repos - before_create :set_default_status after_create :place_build after_destroy :delete_container @@ -251,11 +250,6 @@ class BuildList < ActiveRecord::Base protected - def set_default_status - self.status = WAITING_FOR_RESPONSE unless self.status.present? - return true - end - def delete_container if can_cancel? BuildServer.delete_build_list bs_id From d084cd23298a60af977c560fd90994f7119ccd8a Mon Sep 17 00:00:00 2001 From: "konstantin.grabar" Date: Fri, 1 Jun 2012 18:42:46 +0400 Subject: [PATCH 07/61] [refs #505] Remove duplicate constant --- app/models/build_list.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/app/models/build_list.rb b/app/models/build_list.rb index bd42df38d..37f3de48b 100644 --- a/app/models/build_list.rb +++ b/app/models/build_list.rb @@ -109,7 +109,6 @@ class BuildList < ActiveRecord::Base BuildServer::PLATFORM_PENDING, BuildServer::PLATFORM_NOT_FOUND, BuildServer::PROJECT_NOT_FOUND, - BuildServer::PROJECT_VERSION_NOT_FOUND, BuildServer::PROJECT_VERSION_NOT_FOUND ].each do |code| transition :waiting_for_response => HUMAN_STATUSES[code], :if => lambda { |build_list| From 81978773520447f99b5ae0a8270d3ba3a7daca59 Mon Sep 17 00:00:00 2001 From: "konstantin.grabar" Date: Fri, 1 Jun 2012 18:53:14 +0400 Subject: [PATCH 08/61] [refs #505] Small has_published check changes --- app/models/build_list.rb | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/app/models/build_list.rb b/app/models/build_list.rb index 37f3de48b..4597f0116 100644 --- a/app/models/build_list.rb +++ b/app/models/build_list.rb @@ -158,8 +158,7 @@ class BuildList < ActiveRecord::Base event :publish do transition [:success, :failed_publish] => :build_publish, :if => lambda { |build_list| - has_published = BuildServer.publish_container build_list.bs_id - has_published == 0 + BuildServer.publish_container(build_list.bs_id) == 0 } transition [:success, :failed_publish] => :failed_publish end @@ -174,8 +173,7 @@ class BuildList < ActiveRecord::Base event :fail_publish do transition :build_publish => :failed_publish, :if => lambda { |build_list| - has_published = BuildServer.publish_container build_list.bs_id - has_published != 0 + BuildServer.publish_container(build_list.bs_id) != 0 } end From a711773d47a58c5d62dab0f8a801876c4074c47f Mon Sep 17 00:00:00 2001 From: "konstantin.grabar" Date: Fri, 1 Jun 2012 19:02:51 +0400 Subject: [PATCH 09/61] [refs #505] Remove unused events --- app/models/build_list.rb | 20 -------------------- 1 file changed, 20 deletions(-) diff --git a/app/models/build_list.rb b/app/models/build_list.rb index 4597f0116..5308ba2e5 100644 --- a/app/models/build_list.rb +++ b/app/models/build_list.rb @@ -117,26 +117,6 @@ class BuildList < ActiveRecord::Base end end - event :wait_assembly do - transition :waiting_for_response => :build_pending - end - - event :wait_platform do - transition :waiting_for_response => :platform_pending - end - - event :lose_platform do - transition :waiting_for_response => :platform_not_found - end - - event :lose_project do - transition :waiting_for_response => :project_not_found - end - - event :lose_project_version do - transition :waiting_for_response => :project_version_not_found - end - event :start do transition [:build_pending, :platform_pending] => :build_started end From bd721aa3af95aa81d7acb3fffdbb2623c3a6fcc4 Mon Sep 17 00:00:00 2001 From: "konstantin.grabar" Date: Tue, 5 Jun 2012 14:30:38 +0400 Subject: [PATCH 10/61] [refs #505] Remove unsused events --- app/models/build_list.rb | 22 ---------------------- 1 file changed, 22 deletions(-) diff --git a/app/models/build_list.rb b/app/models/build_list.rb index 5308ba2e5..44fb292db 100644 --- a/app/models/build_list.rb +++ b/app/models/build_list.rb @@ -117,10 +117,6 @@ class BuildList < ActiveRecord::Base end end - event :start do - transition [:build_pending, :platform_pending] => :build_started - end - event :cancel do transition [:build_pending, :platform_pending] => :build_canceled, :if => lambda { |build_list| has_canceled = BuildServer.delete_build_list build_list.bs_id @@ -128,14 +124,6 @@ class BuildList < ActiveRecord::Base } end - event :finish_build do - transition [:build_started, :build_canceled] => :success - end - - event :fail_build do - transition :build_started => :build_error - end - event :publish do transition [:success, :failed_publish] => :build_publish, :if => lambda { |build_list| BuildServer.publish_container(build_list.bs_id) == 0 @@ -147,16 +135,6 @@ class BuildList < ActiveRecord::Base transition :success => :rejected_publish, :if => :can_reject_publish? end - event :finish_publish do - transition :build_publish => :build_published - end - - event :fail_publish do - transition :build_publish => :failed_publish, :if => lambda { |build_list| - BuildServer.publish_container(build_list.bs_id) != 0 - } - end - HUMAN_STATUSES.each do |code,name| state name, :value => code end From 122b50564d3e63c154e20fc457024aa260d2cba6 Mon Sep 17 00:00:00 2001 From: "konstantin.grabar" Date: Tue, 5 Jun 2012 16:19:54 +0400 Subject: [PATCH 11/61] [refs #505] Small refactor for place_build event --- app/models/build_list.rb | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/app/models/build_list.rb b/app/models/build_list.rb index 44fb292db..593a4954e 100644 --- a/app/models/build_list.rb +++ b/app/models/build_list.rb @@ -106,13 +106,14 @@ class BuildList < ActiveRecord::Base build_list.add_to_queue == BUILD_PENDING } [ - BuildServer::PLATFORM_PENDING, - BuildServer::PLATFORM_NOT_FOUND, - BuildServer::PROJECT_NOT_FOUND, - BuildServer::PROJECT_VERSION_NOT_FOUND + 'BuildList::BUILD_PENDING', + 'BuildServer::PLATFORM_PENDING', + 'BuildServer::PLATFORM_NOT_FOUND', + 'BuildServer::PROJECT_NOT_FOUND', + 'BuildServer::PROJECT_VERSION_NOT_FOUND' ].each do |code| - transition :waiting_for_response => HUMAN_STATUSES[code], :if => lambda { |build_list| - build_list.add_to_queue == code + transition :waiting_for_response => code.demodulize.downcase.to_sym, :if => lambda { |build_list| + build_list.add_to_queue == code.constantize } end end From 9b3da14f83e74d47d817b24c7587c4bbb7f6addf Mon Sep 17 00:00:00 2001 From: "konstantin.grabar" Date: Wed, 13 Jun 2012 21:24:50 +0400 Subject: [PATCH 12/61] [refs #505] Add more events and replace hand made status change --- .../projects/build_lists_controller.rb | 8 +++---- app/models/build_list.rb | 24 +++++++++++++++++++ 2 files changed, 28 insertions(+), 4 deletions(-) diff --git a/app/controllers/projects/build_lists_controller.rb b/app/controllers/projects/build_lists_controller.rb index 4c8980e64..d4db6e215 100644 --- a/app/controllers/projects/build_lists_controller.rb +++ b/app/controllers/projects/build_lists_controller.rb @@ -93,11 +93,11 @@ class Projects::BuildListsController < Projects::BaseController def publish_build if params[:status].to_i == 0 # ok - @build_list.status = BuildList::BUILD_PUBLISHED + @build_list.published @build_list.package_version = "#{params[:version]}-#{params[:release]}" system("cd #{@build_list.project.git_repository.path} && git tag #{@build_list.package_version} #{@build_list.commit_hash}") # TODO REDO through grit else - @build_list.status = BuildList::FAILED_PUBLISH + @build_list.failed_publish end @build_list.save @@ -118,14 +118,14 @@ class Projects::BuildListsController < Projects::BaseController end def pre_build - @build_list.status = BuildServer::BUILD_STARTED + @build_list.start @build_list.save render :nothing => true, :status => 200 end def post_build - @build_list.status = params[:status] + params[:status] == BuildServer::SUCCESS ? @build_list.success : @build_list.error @build_list.container_path = params[:container_path] @build_list.save diff --git a/app/models/build_list.rb b/app/models/build_list.rb index 593a4954e..422b3b49f 100644 --- a/app/models/build_list.rb +++ b/app/models/build_list.rb @@ -118,6 +118,14 @@ class BuildList < ActiveRecord::Base end end + event :start do + transition [ :build_pending, + :platform_pending, + :platform_not_found, + :project_not_found, + :project_version_not_found ] => :build_started + end + event :cancel do transition [:build_pending, :platform_pending] => :build_canceled, :if => lambda { |build_list| has_canceled = BuildServer.delete_build_list build_list.bs_id @@ -125,6 +133,14 @@ class BuildList < ActiveRecord::Base } end + event :published do + transition [:build_publish, :rejected_publish] => :build_published + end + + event :fail_publish do + transition [:build_publish, :rejected_publish] => :failed_publish + end + event :publish do transition [:success, :failed_publish] => :build_publish, :if => lambda { |build_list| BuildServer.publish_container(build_list.bs_id) == 0 @@ -136,6 +152,14 @@ class BuildList < ActiveRecord::Base transition :success => :rejected_publish, :if => :can_reject_publish? end + event :success do + transition [:build_started, :build_canceled] => :success + end + + event :error do + transition [:build_started, :build_canceled] => :build_error + end + HUMAN_STATUSES.each do |code,name| state name, :value => code end From 17815ddab24766ca2b31d4573497c631dee940ac Mon Sep 17 00:00:00 2001 From: "konstantin.grabar" Date: Wed, 13 Jun 2012 22:33:23 +0400 Subject: [PATCH 13/61] [refs #505] Change start event name and move some logic to set_version_and_tag method --- app/controllers/projects/build_lists_controller.rb | 7 ++----- app/models/build_list.rb | 8 +++++++- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/app/controllers/projects/build_lists_controller.rb b/app/controllers/projects/build_lists_controller.rb index d4db6e215..fcf979822 100644 --- a/app/controllers/projects/build_lists_controller.rb +++ b/app/controllers/projects/build_lists_controller.rb @@ -94,12 +94,10 @@ class Projects::BuildListsController < Projects::BaseController def publish_build if params[:status].to_i == 0 # ok @build_list.published - @build_list.package_version = "#{params[:version]}-#{params[:release]}" - system("cd #{@build_list.project.git_repository.path} && git tag #{@build_list.package_version} #{@build_list.commit_hash}") # TODO REDO through grit + @build_list.set_version_and_tag params[:version], params[:release] else @build_list.failed_publish end - @build_list.save render :nothing => true, :status => 200 end @@ -118,8 +116,7 @@ class Projects::BuildListsController < Projects::BaseController end def pre_build - @build_list.start - @build_list.save + @build_list.start_build render :nothing => true, :status => 200 end diff --git a/app/models/build_list.rb b/app/models/build_list.rb index 422b3b49f..78b236d93 100644 --- a/app/models/build_list.rb +++ b/app/models/build_list.rb @@ -118,7 +118,7 @@ class BuildList < ActiveRecord::Base end end - event :start do + event :start_build do transition [ :build_pending, :platform_pending, :platform_not_found, @@ -181,6 +181,12 @@ class BuildList < ActiveRecord::Base @status ||= BuildServer.add_build_list project.name, project_version, save_to_platform.name, arch.name, (save_to_platform_id == build_for_platform_id ? '' : build_for_platform.name), update_type, build_requires, id, include_repos, priority end + def set_version_and_tag(version, release) + self.package_version = "#{version}-#{release}" + system("cd #{self.project.git_repository.path} && git tag #{self.package_version} #{self.commit_hash}") # TODO REDO through grit + save + end + def self.human_status(status) I18n.t("layout.build_lists.statuses.#{HUMAN_STATUSES[status]}") end From 5acc13e9a69e2dcd4c61a582390292d347b97aaa Mon Sep 17 00:00:00 2001 From: "konstantin.grabar" Date: Thu, 14 Jun 2012 17:36:40 +0400 Subject: [PATCH 14/61] [ref #505] Refactor set_version_and_tag. Rename success and error events --- app/controllers/projects/build_lists_controller.rb | 3 +-- app/models/build_list.rb | 11 +++++++---- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/app/controllers/projects/build_lists_controller.rb b/app/controllers/projects/build_lists_controller.rb index b039daef5..1ac234c24 100644 --- a/app/controllers/projects/build_lists_controller.rb +++ b/app/controllers/projects/build_lists_controller.rb @@ -95,7 +95,6 @@ class Projects::BuildListsController < Projects::BaseController def publish_build if params[:status].to_i == 0 # ok @build_list.published - @build_list.set_version_and_tag params[:version], params[:release] else @build_list.failed_publish end @@ -123,7 +122,7 @@ class Projects::BuildListsController < Projects::BaseController end def post_build - params[:status] == BuildServer::SUCCESS ? @build_list.success : @build_list.error + params[:status] == BuildServer::SUCCESS ? @build_list.build_success : @build_list.build_error @build_list.container_path = params[:container_path] @build_list.save diff --git a/app/models/build_list.rb b/app/models/build_list.rb index 96d1cb018..a13ec28f7 100644 --- a/app/models/build_list.rb +++ b/app/models/build_list.rb @@ -105,6 +105,8 @@ class BuildList < ActiveRecord::Base state_machine :status, :initial => :waiting_for_response do + after_transition :on => :published, :do => :set_version_and_tag + event :place_build do transition :waiting_for_response => :build_pending, :if => lambda { |build_list| build_list.add_to_queue == BUILD_PENDING @@ -156,11 +158,11 @@ class BuildList < ActiveRecord::Base transition :success => :rejected_publish, :if => :can_reject_publish? end - event :success do + event :build_success do transition [:build_started, :build_canceled] => :success end - event :error do + event :build_error do transition [:build_started, :build_canceled] => :build_error end @@ -185,8 +187,9 @@ class BuildList < ActiveRecord::Base @status ||= BuildServer.add_build_list project.name, project_version, save_to_platform.name, arch.name, (save_to_platform_id == build_for_platform_id ? '' : build_for_platform.name), update_type, build_requires, id, include_repos, priority end - def set_version_and_tag(version, release) - self.package_version = "#{version}-#{release}" + def set_version_and_tag + pkg = self.packages.where(:package_type => 'source', :project_id => self.project_id).first + self.package_version = "#{pkg.platform.name}-#{pkg.version}-#{pkg.release}" system("cd #{self.project.git_repository.path} && git tag #{self.package_version} #{self.commit_hash}") # TODO REDO through grit save end From 5e7342fbd7add3c01fbd70d4a4c967ffef3ee32b Mon Sep 17 00:00:00 2001 From: "konstantin.grabar" Date: Fri, 15 Jun 2012 12:47:40 +0400 Subject: [PATCH 15/61] [refs #505] Comment DJ stub. Fix event name call --- app/controllers/projects/build_lists_controller.rb | 2 +- spec/spec_helper.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/controllers/projects/build_lists_controller.rb b/app/controllers/projects/build_lists_controller.rb index 1ac234c24..d302bdfc8 100644 --- a/app/controllers/projects/build_lists_controller.rb +++ b/app/controllers/projects/build_lists_controller.rb @@ -96,7 +96,7 @@ class Projects::BuildListsController < Projects::BaseController if params[:status].to_i == 0 # ok @build_list.published else - @build_list.failed_publish + @build_list.fail_publish end render :nothing => true, :status => 200 diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 7eab2ddcd..83eec9d2c 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -43,7 +43,7 @@ def test_git_commit(project) project.git_repository.repo.index.commit('Test commit') end -Delayed::Worker.delay_jobs = false # Execute all jobs realtime +#Delayed::Worker.delay_jobs = false # Execute all jobs realtime # Add testing root_path %x(rm -Rf #{Rails.root}/tmp/test_root) From 49ac16ae192a20433e94d4d6281e8d44368aa156 Mon Sep 17 00:00:00 2001 From: "konstantin.grabar" Date: Fri, 15 Jun 2012 14:14:32 +0400 Subject: [PATCH 16/61] [refs #505] Add changes to spec. Temporary broke tests to show errors --- .../projects/build_lists_controller_spec.rb | 32 ++++++++++++++++--- 1 file changed, 28 insertions(+), 4 deletions(-) diff --git a/spec/controllers/projects/build_lists_controller_spec.rb b/spec/controllers/projects/build_lists_controller_spec.rb index d941b5f02..45b999eb5 100644 --- a/spec/controllers/projects/build_lists_controller_spec.rb +++ b/spec/controllers/projects/build_lists_controller_spec.rb @@ -3,6 +3,10 @@ require 'spec_helper' describe Projects::BuildListsController do + before(:each) do + any_instance_of(BuildList, :set_version_and_tag => true) + end + shared_examples_for 'show build list' do it 'should be able to perform show action' do get :show, @show_params @@ -323,14 +327,18 @@ describe Projects::BuildListsController do end describe 'publish_build' do - before { test_git_commit(build_list.project); build_list.update_attribute :commit_hash, build_list.project.git_repository.commits('master').last.id } + before { test_git_commit(build_list.project); build_list.update_attribute :commit_hash, build_list.project.git_repository.commits('master').last.id; build_list.update_attribute(:status, BuildList::BUILD_PUBLISH); } def do_get(status) get :publish_build, :id => build_list.bs_id, :status => status, :version => '4.7.5.3', :release => '1' build_list.reload end - it { do_get(BuildServer::SUCCESS); response.should be_ok } + it do + build_list.update_attribute(:status, BuildServer::BUILD_STARTED) + do_get(BuildServer::SUCCESS) + response.should be_ok + end it 'should create correct git tag for correct commit' do do_get(BuildServer::SUCCESS) build_list.project.git_repository.tags.last.name.should == build_list.package_version @@ -390,6 +398,10 @@ describe Projects::BuildListsController do end describe 'pre_build' do + before do + build_list.update_attribute :status, BuildList::BUILD_PENDING + end + def do_get get :pre_build, :id => build_list.bs_id build_list.reload @@ -413,8 +425,20 @@ describe Projects::BuildListsController do it { lambda{ do_get(BuildServer::SUCCESS) }.should change(build_list, :updated_at) } context 'with auto_publish' do - it { lambda{ do_get(BuildServer::SUCCESS) }.should change(build_list, :status).to(BuildList::BUILD_PUBLISH) } - it { lambda{ do_get(BuildServer::ERROR) }.should change(build_list, :status).to(BuildServer::ERROR) } + it do + # TODO Comment or remove me: + build_list.update_attribute(:status, BuildServer::SUCCESS) + #build_list.status = BuildServer::SUCCESS + #build_list.save + lambda{ do_get(BuildServer::SUCCESS) }.should change(build_list, :status).to(BuildList::BUILD_PUBLISH) + end + it do + # TODO Comment or remove me: + build_list.update_attribute(:status, BuildServer::BUILD_STARTED) + #build_list.status = BuildServer::BUILD_STARTED + #build_list.save + lambda{ do_get(BuildServer::ERROR) }.should change(build_list, :status).to(BuildServer::ERROR) + end end context 'without auto_publish' do From 6db2fd3d102d074d6fa076e4afdc80c04cfd2e6b Mon Sep 17 00:00:00 2001 From: "konstantin.grabar" Date: Fri, 15 Jun 2012 17:05:55 +0400 Subject: [PATCH 17/61] [refs #505] Tried to fix strip error. --- app/models/build_list.rb | 24 +++++++++++++------ .../projects/build_lists_controller_spec.rb | 6 ++--- 2 files changed, 20 insertions(+), 10 deletions(-) diff --git a/app/models/build_list.rb b/app/models/build_list.rb index a13ec28f7..05a25b060 100644 --- a/app/models/build_list.rb +++ b/app/models/build_list.rb @@ -105,7 +105,9 @@ class BuildList < ActiveRecord::Base state_machine :status, :initial => :waiting_for_response do - after_transition :on => :published, :do => :set_version_and_tag + #after_transition :on => :published do |build_list, transition|#, :do => :set_version_and_tag + # 11 + #end event :place_build do transition :waiting_for_response => :build_pending, :if => lambda { |build_list| @@ -170,6 +172,13 @@ class BuildList < ActiveRecord::Base state name, :value => code end + #def set_version_and_tag + # #pkg = self.packages.where(:package_type => 'source', :project_id => self.project_id).first + # #self.package_version = "#{pkg.platform.name}-#{pkg.version}-#{pkg.release}" + # #system("cd #{self.project.git_repository.path} && git tag #{self.package_version} #{self.commit_hash}") # TODO REDO through grit + # #save + # #2 + 1 + #end end #TODO: Share this checking on product owner. @@ -187,12 +196,13 @@ class BuildList < ActiveRecord::Base @status ||= BuildServer.add_build_list project.name, project_version, save_to_platform.name, arch.name, (save_to_platform_id == build_for_platform_id ? '' : build_for_platform.name), update_type, build_requires, id, include_repos, priority end - def set_version_and_tag - pkg = self.packages.where(:package_type => 'source', :project_id => self.project_id).first - self.package_version = "#{pkg.platform.name}-#{pkg.version}-#{pkg.release}" - system("cd #{self.project.git_repository.path} && git tag #{self.package_version} #{self.commit_hash}") # TODO REDO through grit - save - end + #def set_version_and_tag + # #pkg = self.packages.where(:package_type => 'source', :project_id => self.project_id).first + # #self.package_version = "#{pkg.platform.name}-#{pkg.version}-#{pkg.release}" + # #system("cd #{self.project.git_repository.path} && git tag #{self.package_version} #{self.commit_hash}") # TODO REDO through grit + # #save + # 2 + 1 + #end def self.human_status(status) I18n.t("layout.build_lists.statuses.#{HUMAN_STATUSES[status]}") diff --git a/spec/controllers/projects/build_lists_controller_spec.rb b/spec/controllers/projects/build_lists_controller_spec.rb index 45b999eb5..6221b5b32 100644 --- a/spec/controllers/projects/build_lists_controller_spec.rb +++ b/spec/controllers/projects/build_lists_controller_spec.rb @@ -3,9 +3,9 @@ require 'spec_helper' describe Projects::BuildListsController do - before(:each) do - any_instance_of(BuildList, :set_version_and_tag => true) - end + #before(:each) do + # any_instance_of(BuildList, :set_version_and_tag => true) + #end shared_examples_for 'show build list' do it 'should be able to perform show action' do From ac7a3980cde182eb985c39a8320d57961cc6f97f Mon Sep 17 00:00:00 2001 From: "konstantin.grabar" Date: Fri, 15 Jun 2012 20:05:55 +0400 Subject: [PATCH 18/61] [refs #505] Pending some tests. Return set_version_and_tag. Fix post_build action --- .../projects/build_lists_controller.rb | 2 +- app/models/build_list.rb | 17 +++---- app/models/build_list_observer.rb | 4 +- lib/build_server.rb | 2 +- .../projects/build_lists_controller_spec.rb | 49 ++++++++++--------- 5 files changed, 38 insertions(+), 36 deletions(-) diff --git a/app/controllers/projects/build_lists_controller.rb b/app/controllers/projects/build_lists_controller.rb index d302bdfc8..27aa548a0 100644 --- a/app/controllers/projects/build_lists_controller.rb +++ b/app/controllers/projects/build_lists_controller.rb @@ -122,7 +122,7 @@ class Projects::BuildListsController < Projects::BaseController end def post_build - params[:status] == BuildServer::SUCCESS ? @build_list.build_success : @build_list.build_error + params[:status].to_i == BuildServer::SUCCESS ? @build_list.build_success : @build_list.build_error @build_list.container_path = params[:container_path] @build_list.save diff --git a/app/models/build_list.rb b/app/models/build_list.rb index 05a25b060..82ff59b1e 100644 --- a/app/models/build_list.rb +++ b/app/models/build_list.rb @@ -105,9 +105,7 @@ class BuildList < ActiveRecord::Base state_machine :status, :initial => :waiting_for_response do - #after_transition :on => :published do |build_list, transition|#, :do => :set_version_and_tag - # 11 - #end + after_transition :on => :published, :do => :set_version_and_tag event :place_build do transition :waiting_for_response => :build_pending, :if => lambda { |build_list| @@ -172,13 +170,12 @@ class BuildList < ActiveRecord::Base state name, :value => code end - #def set_version_and_tag - # #pkg = self.packages.where(:package_type => 'source', :project_id => self.project_id).first - # #self.package_version = "#{pkg.platform.name}-#{pkg.version}-#{pkg.release}" - # #system("cd #{self.project.git_repository.path} && git tag #{self.package_version} #{self.commit_hash}") # TODO REDO through grit - # #save - # #2 + 1 - #end + def set_version_and_tag + pkg = self.packages.where(:package_type => 'source', :project_id => self.project_id).first + self.package_version = "#{pkg.platform.name}-#{pkg.version}-#{pkg.release}" + system("cd #{self.project.git_repository.path} && git tag #{self.package_version} #{self.commit_hash}") # TODO REDO through grit + save + end end #TODO: Share this checking on product owner. diff --git a/app/models/build_list_observer.rb b/app/models/build_list_observer.rb index 50ef167cd..bc54e088d 100644 --- a/app/models/build_list_observer.rb +++ b/app/models/build_list_observer.rb @@ -7,13 +7,13 @@ class BuildListObserver < ActiveRecord::Observer if [BuildServer::BUILD_ERROR, BuildServer::SUCCESS].include? record.status # stores time interval beetwin build start and finish in seconds record.duration = record.current_duration - + if record.status == BuildServer::SUCCESS # Update project average build time build_count = record.project.build_count new_av_time = ( record.project.average_build_time * build_count + record.duration ) / ( build_count + 1 ) record.project.update_attributes({ :average_build_time => new_av_time, :build_count => build_count + 1 }, :without_protection => true) - end + end end end end diff --git a/lib/build_server.rb b/lib/build_server.rb index c09e89794..a1214af13 100644 --- a/lib/build_server.rb +++ b/lib/build_server.rb @@ -11,7 +11,7 @@ class BuildServer PROJECT_NOT_FOUND = 3 PROJECT_VERSION_NOT_FOUND = 4 PROJECT_SOURCE_ERROR = 6 - + DEPENDENCY_TEST_FAILED = 21 BINARY_TEST_FAILED = 22 diff --git a/spec/controllers/projects/build_lists_controller_spec.rb b/spec/controllers/projects/build_lists_controller_spec.rb index 6221b5b32..61d92d71c 100644 --- a/spec/controllers/projects/build_lists_controller_spec.rb +++ b/spec/controllers/projects/build_lists_controller_spec.rb @@ -3,9 +3,9 @@ require 'spec_helper' describe Projects::BuildListsController do - #before(:each) do - # any_instance_of(BuildList, :set_version_and_tag => true) - #end + before(:each) do + any_instance_of(BuildList, :set_version_and_tag => true) + end shared_examples_for 'show build list' do it 'should be able to perform show action' do @@ -334,17 +334,18 @@ describe Projects::BuildListsController do build_list.reload end - it do + it(:passes) { build_list.update_attribute(:status, BuildServer::BUILD_STARTED) do_get(BuildServer::SUCCESS) response.should be_ok - end - it 'should create correct git tag for correct commit' do + } + # TODO: Remove pending after set_version_and_tag unstub: + pending 'should create correct git tag for correct commit' do do_get(BuildServer::SUCCESS) build_list.project.git_repository.tags.last.name.should == build_list.package_version build_list.project.git_repository.commits(build_list.package_version).last.id.should == build_list.commit_hash end - it { lambda{ do_get(BuildServer::SUCCESS) }.should change(build_list, :status).to(BuildList::BUILD_PUBLISHED) } + pending { lambda{ do_get(BuildServer::SUCCESS) }.should change(build_list, :status).to(BuildList::BUILD_PUBLISHED) } it { lambda{ do_get(BuildServer::SUCCESS) }.should change(build_list, :package_version).to('4.7.5.3-1') } it { lambda{ do_get(BuildServer::ERROR) }.should change(build_list, :status).to(BuildList::FAILED_PUBLISH) } it { lambda{ do_get(BuildServer::ERROR) }.should_not change(build_list, :package_version) } @@ -425,27 +426,31 @@ describe Projects::BuildListsController do it { lambda{ do_get(BuildServer::SUCCESS) }.should change(build_list, :updated_at) } context 'with auto_publish' do - it do - # TODO Comment or remove me: - build_list.update_attribute(:status, BuildServer::SUCCESS) - #build_list.status = BuildServer::SUCCESS - #build_list.save - lambda{ do_get(BuildServer::SUCCESS) }.should change(build_list, :status).to(BuildList::BUILD_PUBLISH) - end - it do - # TODO Comment or remove me: + it(:passes) { + build_list.update_attribute(:started_at, (Time.now - 1.day)) build_list.update_attribute(:status, BuildServer::BUILD_STARTED) - #build_list.status = BuildServer::BUILD_STARTED - #build_list.save - lambda{ do_get(BuildServer::ERROR) }.should change(build_list, :status).to(BuildServer::ERROR) - end + lambda{ do_get(BuildServer::SUCCESS) }.should change(build_list, :status).to(BuildServer::SUCCESS) + } + it(:passes) { + build_list.update_attribute(:started_at, (Time.now - 1.day)) + build_list.update_attribute(:status, BuildServer::BUILD_STARTED) + lambda{ do_get(BuildServer::BUILD_ERROR) }.should change(build_list, :status).to(BuildServer::BUILD_ERROR) + } end context 'without auto_publish' do before { build_list.update_attribute(:auto_publish, false) } - it { lambda{ do_get(BuildServer::SUCCESS) }.should change(build_list, :status).to(BuildServer::SUCCESS) } - it { lambda{ do_get(BuildServer::ERROR) }.should change(build_list, :status).to(BuildServer::ERROR) } + it(:passes) { + build_list.update_attribute(:started_at, (Time.now - 1.day)) + build_list.update_attribute(:status, BuildServer::BUILD_STARTED) + lambda{ do_get(BuildServer::SUCCESS) }.should change(build_list, :status).to(BuildServer::SUCCESS) + } + it(:passes) { + build_list.update_attribute(:started_at, (Time.now - 1.day)) + build_list.update_attribute(:status, BuildServer::BUILD_STARTED) + lambda{ do_get(BuildServer::BUILD_ERROR) }.should change(build_list, :status).to(BuildServer::BUILD_ERROR) + } end end From 8ce6c26cc430db5278aed6dcc7345ff81bd14193 Mon Sep 17 00:00:00 2001 From: "konstantin.grabar" Date: Mon, 18 Jun 2012 20:19:09 +0400 Subject: [PATCH 19/61] [refs #505] Fix state machine tests --- app/models/build_list.rb | 20 ++++++------------- .../projects/build_lists_controller_spec.rb | 18 +++++++++-------- spec/factories/build_lists.rb | 11 ++++++++++ 3 files changed, 27 insertions(+), 22 deletions(-) diff --git a/app/models/build_list.rb b/app/models/build_list.rb index 82ff59b1e..7571671f0 100644 --- a/app/models/build_list.rb +++ b/app/models/build_list.rb @@ -169,13 +169,13 @@ class BuildList < ActiveRecord::Base HUMAN_STATUSES.each do |code,name| state name, :value => code end + end - def set_version_and_tag - pkg = self.packages.where(:package_type => 'source', :project_id => self.project_id).first - self.package_version = "#{pkg.platform.name}-#{pkg.version}-#{pkg.release}" - system("cd #{self.project.git_repository.path} && git tag #{self.package_version} #{self.commit_hash}") # TODO REDO through grit - save - end + def set_version_and_tag + pkg = self.packages.where(:package_type => 'source', :project_id => self.project_id).first + self.package_version = "#{pkg.platform.name}-#{pkg.version}-#{pkg.release}" + system("cd #{self.project.git_repository.path} && git tag #{self.package_version} #{self.commit_hash}") # TODO REDO through grit + save end #TODO: Share this checking on product owner. @@ -193,14 +193,6 @@ class BuildList < ActiveRecord::Base @status ||= BuildServer.add_build_list project.name, project_version, save_to_platform.name, arch.name, (save_to_platform_id == build_for_platform_id ? '' : build_for_platform.name), update_type, build_requires, id, include_repos, priority end - #def set_version_and_tag - # #pkg = self.packages.where(:package_type => 'source', :project_id => self.project_id).first - # #self.package_version = "#{pkg.platform.name}-#{pkg.version}-#{pkg.release}" - # #system("cd #{self.project.git_repository.path} && git tag #{self.package_version} #{self.commit_hash}") # TODO REDO through grit - # #save - # 2 + 1 - #end - def self.human_status(status) I18n.t("layout.build_lists.statuses.#{HUMAN_STATUSES[status]}") end diff --git a/spec/controllers/projects/build_lists_controller_spec.rb b/spec/controllers/projects/build_lists_controller_spec.rb index 61d92d71c..a8806dfbe 100644 --- a/spec/controllers/projects/build_lists_controller_spec.rb +++ b/spec/controllers/projects/build_lists_controller_spec.rb @@ -3,10 +3,6 @@ require 'spec_helper' describe Projects::BuildListsController do - before(:each) do - any_instance_of(BuildList, :set_version_and_tag => true) - end - shared_examples_for 'show build list' do it 'should be able to perform show action' do get :show, @show_params @@ -321,13 +317,19 @@ describe Projects::BuildListsController do context 'callbacks' do let(:build_list) { FactoryGirl.create(:build_list_core) } + let(:build_list_package) { FactoryGirl.create(:build_list_package, :build_list_id => build_list.id, :platform_id => build_list.project.repositories.first.platform_id, :project_id => build_list.project_id, :version => "4.7.5.3", :release => 1) } before(:each) do mock(controller).authenticate_build_service! {true} end describe 'publish_build' do - before { test_git_commit(build_list.project); build_list.update_attribute :commit_hash, build_list.project.git_repository.commits('master').last.id; build_list.update_attribute(:status, BuildList::BUILD_PUBLISH); } + before { + test_git_commit(build_list.project) + build_list.update_attribute :commit_hash, build_list.project.git_repository.commits('master').last.id + build_list.update_attribute(:status, BuildList::BUILD_PUBLISH) + build_list_package + } def do_get(status) get :publish_build, :id => build_list.bs_id, :status => status, :version => '4.7.5.3', :release => '1' @@ -340,13 +342,13 @@ describe Projects::BuildListsController do response.should be_ok } # TODO: Remove pending after set_version_and_tag unstub: - pending 'should create correct git tag for correct commit' do + it 'should create correct git tag for correct commit' do do_get(BuildServer::SUCCESS) build_list.project.git_repository.tags.last.name.should == build_list.package_version build_list.project.git_repository.commits(build_list.package_version).last.id.should == build_list.commit_hash end - pending { lambda{ do_get(BuildServer::SUCCESS) }.should change(build_list, :status).to(BuildList::BUILD_PUBLISHED) } - it { lambda{ do_get(BuildServer::SUCCESS) }.should change(build_list, :package_version).to('4.7.5.3-1') } + it(:passes) { lambda{ do_get(BuildServer::SUCCESS) }.should change(build_list, :status).to(BuildList::BUILD_PUBLISHED) } + it(:passes) { lambda{ do_get(BuildServer::SUCCESS) }.should change(build_list, :package_version).to("#{ build_list_package.platform.name }-4.7.5.3-1") } it { lambda{ do_get(BuildServer::ERROR) }.should change(build_list, :status).to(BuildList::FAILED_PUBLISH) } it { lambda{ do_get(BuildServer::ERROR) }.should_not change(build_list, :package_version) } it { lambda{ do_get(BuildServer::ERROR) }.should change(build_list, :updated_at) } diff --git a/spec/factories/build_lists.rb b/spec/factories/build_lists.rb index 88dda9c27..0271f50ea 100644 --- a/spec/factories/build_lists.rb +++ b/spec/factories/build_lists.rb @@ -16,4 +16,15 @@ FactoryGirl.define do factory :build_list_core, :parent => :build_list do bs_id { FactoryGirl.generate(:integer) } end + + factory :build_list_package, :class => BuildList::Package do + association :build_list + association :project + association :platform + fullname "test_package" + name "test_package" + version "3.1.12" + release 6 + package_type "source" + end end From 8e88c32147eec8c31866879bcdc4b00c23e4cd8e Mon Sep 17 00:00:00 2001 From: "konstantin.grabar" Date: Tue, 19 Jun 2012 14:23:03 +0400 Subject: [PATCH 20/61] [refs #505] Fix tests after merge. Remove ResqueAsyncMethods include --- app/models/build_list.rb | 2 -- spec/controllers/projects/build_lists_controller_spec.rb | 5 +++-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/app/models/build_list.rb b/app/models/build_list.rb index 7571671f0..2a77e870a 100644 --- a/app/models/build_list.rb +++ b/app/models/build_list.rb @@ -99,8 +99,6 @@ class BuildList < ActiveRecord::Base after_create :place_build after_destroy :delete_container - include Modules::Models::ResqueAsyncMethods - @queue = :clone_and_build state_machine :status, :initial => :waiting_for_response do diff --git a/spec/controllers/projects/build_lists_controller_spec.rb b/spec/controllers/projects/build_lists_controller_spec.rb index a8806dfbe..bdf798469 100644 --- a/spec/controllers/projects/build_lists_controller_spec.rb +++ b/spec/controllers/projects/build_lists_controller_spec.rb @@ -26,7 +26,7 @@ describe Projects::BuildListsController do response.should redirect_to(forbidden_url) end end - + shared_examples_for 'create build list' do before {test_git_commit(@project)} @@ -431,7 +431,8 @@ describe Projects::BuildListsController do it(:passes) { build_list.update_attribute(:started_at, (Time.now - 1.day)) build_list.update_attribute(:status, BuildServer::BUILD_STARTED) - lambda{ do_get(BuildServer::SUCCESS) }.should change(build_list, :status).to(BuildServer::SUCCESS) + build_list.reload + lambda{ do_get(BuildServer::SUCCESS) }.should change(build_list, :status).to(BuildList::BUILD_PUBLISH) } it(:passes) { build_list.update_attribute(:started_at, (Time.now - 1.day)) From 904cfca5c9596a7a9422de048b8c602517fa50f6 Mon Sep 17 00:00:00 2001 From: "konstantin.grabar" Date: Tue, 19 Jun 2012 18:52:29 +0400 Subject: [PATCH 21/61] [refs #529] Fix branch set for repository with dot in name --- app/assets/javascripts/extra/build_list.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/assets/javascripts/extra/build_list.js b/app/assets/javascripts/extra/build_list.js index 8dccd6d86..654fc0d04 100644 --- a/app/assets/javascripts/extra/build_list.js +++ b/app/assets/javascripts/extra/build_list.js @@ -71,7 +71,7 @@ function setBranchSelected() { var pl_id = $('#build_list_save_to_platform_id').val(); // Checks if selected platform is main or not: if ( $('.all_platforms').find('input[type="checkbox"][value=' + pl_id + '].build_bpl_ids').size() > 0 ) { - var pl_name = $('#build_list_save_to_platform_id option[value="' + pl_id + '"]').text().match(/([\w-]+)\/[\w-]+/)[1]; + var pl_name = $('#build_list_save_to_platform_id option[value="' + pl_id + '"]').text().match(/([\w-.]+)\/[\w-.]+/)[1]; var branch_pl_opt = $('#build_list_project_version option[value="latest_' + pl_name + '"]'); // If there is branch we need - set it selected: if ( branch_pl_opt.size() > 0 ) { From 264273c6c01a9dc1956dc73b353d33ef3dcb8556 Mon Sep 17 00:00:00 2001 From: "konstantin.grabar" Date: Tue, 19 Jun 2012 19:45:38 +0400 Subject: [PATCH 22/61] [refs #505] Remove comment. Add lost method into build_list model --- app/models/build_list.rb | 2 ++ spec/controllers/projects/build_lists_controller_spec.rb | 1 - 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/app/models/build_list.rb b/app/models/build_list.rb index 2a77e870a..223137dc8 100644 --- a/app/models/build_list.rb +++ b/app/models/build_list.rb @@ -169,6 +169,8 @@ class BuildList < ActiveRecord::Base end end + later :publish, :loner => true, :queue => :clone_build + def set_version_and_tag pkg = self.packages.where(:package_type => 'source', :project_id => self.project_id).first self.package_version = "#{pkg.platform.name}-#{pkg.version}-#{pkg.release}" diff --git a/spec/controllers/projects/build_lists_controller_spec.rb b/spec/controllers/projects/build_lists_controller_spec.rb index bdf798469..b35890892 100644 --- a/spec/controllers/projects/build_lists_controller_spec.rb +++ b/spec/controllers/projects/build_lists_controller_spec.rb @@ -341,7 +341,6 @@ describe Projects::BuildListsController do do_get(BuildServer::SUCCESS) response.should be_ok } - # TODO: Remove pending after set_version_and_tag unstub: it 'should create correct git tag for correct commit' do do_get(BuildServer::SUCCESS) build_list.project.git_repository.tags.last.name.should == build_list.package_version From cb4e9b14b1b3a996d91dbd8720ed7190a2bd8be4 Mon Sep 17 00:00:00 2001 From: "konstantin.grabar" Date: Tue, 19 Jun 2012 21:24:11 +0400 Subject: [PATCH 23/61] [refs #505] Fix events logic and can_cancel method --- app/models/build_list.rb | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/app/models/build_list.rb b/app/models/build_list.rb index 223137dc8..dbc17e1b2 100644 --- a/app/models/build_list.rb +++ b/app/models/build_list.rb @@ -107,7 +107,7 @@ class BuildList < ActiveRecord::Base event :place_build do transition :waiting_for_response => :build_pending, :if => lambda { |build_list| - build_list.add_to_queue == BUILD_PENDING + build_list.add_to_queue == BuildServer::SUCCESS } [ 'BuildList::BUILD_PENDING', @@ -132,8 +132,7 @@ class BuildList < ActiveRecord::Base event :cancel do transition [:build_pending, :platform_pending] => :build_canceled, :if => lambda { |build_list| - has_canceled = BuildServer.delete_build_list build_list.bs_id - build_list.can_cancel? && has_canceled == 0 + build_list.can_cancel? && BuildServer.delete_build_list(build_list.bs_id) == BuildServer::SUCCESS } end @@ -147,7 +146,7 @@ class BuildList < ActiveRecord::Base event :publish do transition [:success, :failed_publish] => :build_publish, :if => lambda { |build_list| - BuildServer.publish_container(build_list.bs_id) == 0 + BuildServer.publish_container(build_list.bs_id) == BuildServer::SUCCESS } transition [:success, :failed_publish] => :failed_publish end @@ -180,7 +179,7 @@ class BuildList < ActiveRecord::Base #TODO: Share this checking on product owner. def can_cancel? - status == BUILD_PENDING && bs_id + [BUILD_PENDING, BuildServer::PLATFORM_PENDING].include? status && bs_id end def can_reject_publish? From e794ce6330c7da179f73189022e1ce68c3d0cb11 Mon Sep 17 00:00:00 2001 From: Pavel Chipiga Date: Wed, 20 Jun 2012 02:20:25 +0300 Subject: [PATCH 24/61] Remove loner parameter to avoid queue ignore. Fix git hook process - do not require 7th param. Remove write_hook from queue. Refs #510 --- app/models/build_list.rb | 2 +- app/models/git_hook.rb | 2 +- app/models/platform.rb | 2 +- app/models/project.rb | 11 +++++------ 4 files changed, 8 insertions(+), 9 deletions(-) diff --git a/app/models/build_list.rb b/app/models/build_list.rb index dbc17e1b2..03d1d3125 100644 --- a/app/models/build_list.rb +++ b/app/models/build_list.rb @@ -168,7 +168,7 @@ class BuildList < ActiveRecord::Base end end - later :publish, :loner => true, :queue => :clone_build + later :publish, :queue => :clone_build def set_version_and_tag pkg = self.packages.where(:package_type => 'source', :project_id => self.project_id).first diff --git a/app/models/git_hook.rb b/app/models/git_hook.rb index ed9639902..cb7037619 100644 --- a/app/models/git_hook.rb +++ b/app/models/git_hook.rb @@ -5,7 +5,7 @@ class GitHook include Resque::Plugins::Status - def initialize(owner_uname, repo, newrev, oldrev, ref, newrev_type, oldrev_type) + def initialize(owner_uname, repo, newrev, oldrev, ref, newrev_type, oldrev_type = nil) @repo, @newrev, @oldrev, @refname, @newrev_type, @oldrev_type = repo, newrev, oldrev, ref, newrev_type, oldrev_type if @owner = User.where(:uname => owner_uname).first || Group.where(:uname => owner_uname).first! @project = @owner.own_projects.where(:name => repo).first! diff --git a/app/models/platform.rb b/app/models/platform.rb index 580def2c8..c617c724a 100644 --- a/app/models/platform.rb +++ b/app/models/platform.rb @@ -184,7 +184,7 @@ class Platform < ActiveRecord::Base def destroy with_skip {super} # avoid cascade XML RPC requests end - later :destroy, :loner => true, :queue => :clone_build + later :destroy, :queue => :clone_build protected diff --git a/app/models/project.rb b/app/models/project.rb index e6c40ddb5..c51c133ca 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -41,7 +41,7 @@ class Project < ActiveRecord::Base after_create :attach_to_personal_repository after_create :create_git_repo - after_create {|p| p.fork_git_repo unless is_root?} # later with resque + after_create {|p| p.fork_git_repo unless p.is_root?} after_save :create_wiki after_destroy :destroy_git_repo @@ -247,15 +247,15 @@ class Project < ActiveRecord::Base def create_git_repo if is_root? Grit::Repo.init_bare(path) - write_hook # later with resque + write_hook end end def fork_git_repo dummy = Grit::Repo.new(path) rescue parent.git_repository.repo.fork_bare(path) - now_write_hook + write_hook end - later :fork_git_repo, :loner => true, :queue => :fork_import + later :fork_git_repo, :queue => :fork_import def destroy_git_repo FileUtils.rm_rf path @@ -267,7 +267,7 @@ class Project < ActiveRecord::Base self.srpm = nil; save # clear srpm end end - later :import_attached_srpm, :loner => true, :queue => :fork_import + later :import_attached_srpm, :queue => :fork_import def create_wiki if has_wiki && !FileTest.exist?(wiki_path) @@ -300,5 +300,4 @@ class Project < ActiveRecord::Base rescue Exception # FIXME end - later :write_hook, :loner => true, :queue => :hook end From 270dbf2e9bac69bb983d4af3c2b72354444810b0 Mon Sep 17 00:00:00 2001 From: "konstantin.grabar" Date: Wed, 20 Jun 2012 17:21:32 +0400 Subject: [PATCH 25/61] [refs #525] Add erase repository functional --- app/controllers/platforms/repositories_controller.rb | 6 ++++++ app/models/ability.rb | 4 ++-- app/models/repository.rb | 4 ++++ app/views/platforms/repositories/show.html.haml | 4 +++- config/locales/models/repository.en.yml | 3 +++ config/locales/models/repository.ru.yml | 3 +++ config/routes.rb | 1 + 7 files changed, 22 insertions(+), 3 deletions(-) diff --git a/app/controllers/platforms/repositories_controller.rb b/app/controllers/platforms/repositories_controller.rb index d37caf8c6..f2d5fb6fd 100644 --- a/app/controllers/platforms/repositories_controller.rb +++ b/app/controllers/platforms/repositories_controller.rb @@ -54,6 +54,12 @@ class Platforms::RepositoriesController < Platforms::BaseController end end + def erase + @repository.erase + flash[:success] = t('flash.repository.erase') + redirect_to platform_repository_path(@platform, @repository) + end + def projects_list owner_subquery = " diff --git a/app/models/ability.rb b/app/models/ability.rb index 743572488..498b83caa 100644 --- a/app/models/ability.rb +++ b/app/models/ability.rb @@ -90,7 +90,7 @@ class Ability can [:read, :projects_list], Repository, :platform => {:owner_type => 'User', :owner_id => user.id} can [:read, :projects_list], Repository, :platform => {:owner_type => 'Group', :owner_id => user.group_ids} can([:read, :projects_list], 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([:create, :update, :projects_list, :add_project, :remove_project, :erase], Repository) {|repository| local_admin? repository.platform} can([:change_visibility, :settings, :destroy], Repository) {|repository| owner? repository.platform} can :read, Product, :platform => {:visibility => 'open'} @@ -119,7 +119,7 @@ class Ability # Shared cannot rights for all users (registered, admin) cannot :destroy, Platform, :platform_type => 'personal' - cannot [:create, :destroy, :add_project, :remove_project], Repository, :platform => {:platform_type => 'personal'} + cannot [:create, :destroy, :add_project, :remove_project, :erase], Repository, :platform => {:platform_type => 'personal'} cannot :destroy, Issue cannot [:members, :add_member, :remove_member, :remove_members], Platform, :platform_type => 'personal' diff --git a/app/models/repository.rb b/app/models/repository.rb index 57c741790..99b483042 100644 --- a/app/models/repository.rb +++ b/app/models/repository.rb @@ -16,6 +16,10 @@ class Repository < ActiveRecord::Base attr_accessible :name, :description attr_readonly :name, :platform_id + def erase + system("rm -Rf #{ APP_CONFIG['root_path'] }/platforms/#{ self.platform.name }/repository/*") + end + def base_clone(attrs = {}) dup.tap do |c| c.platform_id = nil diff --git a/app/views/platforms/repositories/show.html.haml b/app/views/platforms/repositories/show.html.haml index dedcb69e6..86f91d236 100644 --- a/app/views/platforms/repositories/show.html.haml +++ b/app/views/platforms/repositories/show.html.haml @@ -11,5 +11,7 @@ %h3.fix= t("layout.projects.list_header") - if can? :add_project, @repository = link_to t("layout.projects.add"), add_project_platform_repository_path(@platform, @repository), :class => 'button' +- if can? :erase, @repository + = link_to t("layout.repositories.erase"), erase_platform_repository_path(@platform, @repository), :class => 'button', :confirm => t('layout.repositories.erase_confirm') -= render 'proj_list' \ No newline at end of file += render 'proj_list' diff --git a/config/locales/models/repository.en.yml b/config/locales/models/repository.en.yml index 2b6f40dd5..82dcc3135 100644 --- a/config/locales/models/repository.en.yml +++ b/config/locales/models/repository.en.yml @@ -14,6 +14,8 @@ en: back_to_the_list: ⇐ List of repositories confirm_delete: Are you sure you want to delete this repository? current_repository_header: Current repository + erase: Erase + erase_confirm: Are you sure you want to erase this repository? personal_repositories: settings_header: Settings @@ -32,6 +34,7 @@ en: project_not_added: Project adding error. A project with such name already exists in this repository. Remove the old project first project_removed: Project deleted project_not_removed: Unable to delete project from repository + erase: Repository successfully erased! activerecord: models: diff --git a/config/locales/models/repository.ru.yml b/config/locales/models/repository.ru.yml index b6c1922c5..5557a74ce 100644 --- a/config/locales/models/repository.ru.yml +++ b/config/locales/models/repository.ru.yml @@ -14,6 +14,8 @@ ru: back_to_the_list: ⇐ К списку репозиториев confirm_delete: Вы уверены, что хотите удалить этот репозиторий? current_repository_header: Текущий репозиторий + erase: Очистить + erase_confirm: Уверены, что хотите очистить репозиторий? personal_repositories: settings_header: Настройки @@ -32,6 +34,7 @@ ru: project_not_added: Не удалось добавить проект. В этом репозитории уже есть проект с таким именем. Сначала нужно удалить старый проект project_removed: Проект удален из репозитория project_not_removed: Не удалось удалить проект из репозитория + erase: Репозиторий успешно очищен! activerecord: models: diff --git a/config/routes.rb b/config/routes.rb index 569a0f939..e50c8100f 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -58,6 +58,7 @@ Rosa::Application.routes.draw do resources :repositories do member do get :add_project + get :erase delete :remove_project get :projects_list end From ad7d3795e62265c394facf63bf6c37d3b6d5a371 Mon Sep 17 00:00:00 2001 From: "konstantin.grabar" Date: Wed, 20 Jun 2012 19:08:21 +0400 Subject: [PATCH 26/61] Replace after_create on after_commit for build_list --- app/models/build_list.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/build_list.rb b/app/models/build_list.rb index 03d1d3125..8daf300ac 100644 --- a/app/models/build_list.rb +++ b/app/models/build_list.rb @@ -96,7 +96,7 @@ class BuildList < ActiveRecord::Base serialize :additional_repos serialize :include_repos - after_create :place_build + after_commit :place_build after_destroy :delete_container @queue = :clone_and_build From 3cc2f0fe62705ccaf785ae55834d4e65ef8630f4 Mon Sep 17 00:00:00 2001 From: Pavel Chipiga Date: Wed, 20 Jun 2012 19:38:49 +0300 Subject: [PATCH 27/61] Rollback stop_wokers scenario. Refs #510 --- lib/recipes/resque.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/recipes/resque.rb b/lib/recipes/resque.rb index 7f42fd653..b17ce5da1 100644 --- a/lib/recipes/resque.rb +++ b/lib/recipes/resque.rb @@ -20,8 +20,8 @@ Capistrano::Configuration.instance(:must_exist).load do end def stop_workers - #run "kill -QUIT `ps aux | grep resque | grep -v grep | awk '{ print $2 }'`" - run "kill -QUIT `ps aux | grep resque | grep -v grep | awk '{ print $2 }'` > /dev/null 2>&1 &" + run "kill -QUIT `ps aux | grep resque | grep -v grep | awk '{ print $2 }'`" + # run "kill -QUIT `ps aux | grep resque | grep -v grep | awk '{ print $2 }'` > /dev/null 2>&1 &" end def start_workers From 4b9a04e3f73a58cad833a500e3c4c8d0c22c7996 Mon Sep 17 00:00:00 2001 From: "konstantin.grabar" Date: Wed, 20 Jun 2012 20:40:50 +0400 Subject: [PATCH 28/61] [refs #525] Set erase route to post --- app/views/platforms/repositories/show.html.haml | 2 +- config/routes.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/views/platforms/repositories/show.html.haml b/app/views/platforms/repositories/show.html.haml index 86f91d236..ffc4f9bc4 100644 --- a/app/views/platforms/repositories/show.html.haml +++ b/app/views/platforms/repositories/show.html.haml @@ -12,6 +12,6 @@ - if can? :add_project, @repository = link_to t("layout.projects.add"), add_project_platform_repository_path(@platform, @repository), :class => 'button' - if can? :erase, @repository - = link_to t("layout.repositories.erase"), erase_platform_repository_path(@platform, @repository), :class => 'button', :confirm => t('layout.repositories.erase_confirm') + = link_to t("layout.repositories.erase"), erase_platform_repository_path(@platform, @repository), :class => 'button', :confirm => t('layout.repositories.erase_confirm'), :method => :post = render 'proj_list' diff --git a/config/routes.rb b/config/routes.rb index e50c8100f..0beeb7144 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -58,7 +58,7 @@ Rosa::Application.routes.draw do resources :repositories do member do get :add_project - get :erase + post :erase delete :remove_project get :projects_list end From 4d91ea1d6ec0f65dbc738a9c000197f7e3a29b8e Mon Sep 17 00:00:00 2001 From: Alexander Machehin Date: Wed, 20 Jun 2012 00:24:35 +0600 Subject: [PATCH 29/61] [refs #531] fixed user roles --- app/models/ability.rb | 9 +- app/models/user.rb | 19 +++ .../projects/projects/_project.html.haml | 2 +- .../projects/projects/_project.json.jbuilder | 2 +- .../projects/projects_controller_spec.rb | 120 ++++++++++++++++-- .../shared_examples/projects_controller.rb | 21 ++- 6 files changed, 156 insertions(+), 17 deletions(-) diff --git a/app/models/ability.rb b/app/models/ability.rb index 498b83caa..439959391 100644 --- a/app/models/ability.rb +++ b/app/models/ability.rb @@ -147,8 +147,13 @@ class Ability end def relation_exists_for(target, roles) - target.relations.exists?(:actor_id => @user.id, :actor_type => 'User', :role => roles) or - target.relations.exists?(:actor_id => @user.group_ids, :actor_type => 'Group', :role => roles) + rel = target.relations + is_owner_group = target.owner.class == Group + groups = @user.groups + groups = groups.where('groups.id != ?', target.owner.id) if is_owner_group + rel.exists?(:actor_id => @user.id, :actor_type => 'User', :role => roles) or # user is member + (@user.groups.exists?(:id => target.owner.id, :relations =>{:role => roles}) and is_owner_group) or # user group is owner + rel.exists?(:actor_id => groups, :actor_type => 'Group', :role => roles) # user group is member end def local_reader?(target) diff --git a/app/models/user.rb b/app/models/user.rb index 19771bdd5..3498c44eb 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -129,4 +129,23 @@ class User < ActiveRecord::Base false end end + + def best_role target + rel = target.relations + is_owner_group = target.owner.class == Group + gr = self.groups + gr = gr.where('groups.id != ?', target.owner.id) if is_owner_group + roles = [] + if is_owner_group + owner_group = self.groups.where(:id => target.owner.id).first + roles += owner_group.actors.where(:actor_id => self) if owner_group # user group is owner + end + roles += rel.where(:actor_id => self.id, :actor_type => 'User') # user is member + roles += rel.where(:actor_id => gr, :actor_type => 'Group') # user group is member + roles = roles.map(&:role).uniq + return 'admin' if roles.include? 'admin' + return 'writer' if roles.include? 'writer' + return 'reader' if roles.include? 'reader' + raise "unknown user #{self.uname} roles #{roles}" + end end diff --git a/app/views/projects/projects/_project.html.haml b/app/views/projects/projects/_project.html.haml index 537a266b6..f5514643f 100644 --- a/app/views/projects/projects/_project.html.haml +++ b/app/views/projects/projects/_project.html.haml @@ -11,7 +11,7 @@ %td - c = participant_class(alone_member, project) %span{:class => c, :title => t("layout.relations.#{c}")} - = t("layout.collaborators.role_names.#{project.relations.by_user_through_groups(current_user).first.role}") + = t("layout.collaborators.role_names.#{current_user.best_role project}") %td.td5 - unless project.owner == current_user or !alone_member = link_to remove_user_project_path(project), :method => :delete, :confirm => t("layout.confirm") do diff --git a/app/views/projects/projects/_project.json.jbuilder b/app/views/projects/projects/_project.json.jbuilder index 92e639a63..4052c1171 100644 --- a/app/views/projects/projects/_project.json.jbuilder +++ b/app/views/projects/projects/_project.json.jbuilder @@ -5,7 +5,7 @@ json.project do |proj| proj.description project.description proj.link project_path(project) - proj.role t("layout.collaborators.role_names.#{project.relations.by_user_through_groups(current_user).first.role}").force_encoding(Encoding::UTF_8) + proj.role t("layout.collaborators.role_names.#{current_user.best_role project}").force_encoding(Encoding::UTF_8) proj.leave_link remove_user_project_path(project) unless project.owner == current_user or !alone_member? project proj.rights_class participant_class(alone_member?(project), project) diff --git a/spec/controllers/projects/projects_controller_spec.rb b/spec/controllers/projects/projects_controller_spec.rb index e16d3b55e..a94cced96 100644 --- a/spec/controllers/projects/projects_controller_spec.rb +++ b/spec/controllers/projects/projects_controller_spec.rb @@ -79,6 +79,7 @@ describe Projects::ProjectsController do end it_should_behave_like 'projects user with reader rights' + it_should_behave_like 'user without update rights' end context 'for writer user' do @@ -136,20 +137,115 @@ describe Projects::ProjectsController do response.should redirect_to(forbidden_path) end - it 'should not be able to edit project' do - description = @project.description - put :update, :project=>{:description =>"hack"}, :owner_name => @project.owner.uname, :project_name => @project.name - response.should redirect_to(forbidden_path) - Project.find(@project.id).description.should == description + it_should_behave_like 'user without update rights' + end + + context 'for group' do + before(:each) do + @group = FactoryGirl.create(:group) + @group_user = FactoryGirl.create(:user) + @project.relations.destroy_all + set_session_for(@group_user) end - it 'should not be able to edit project sections' do - has_wiki, has_issues = @project.has_wiki, @project.has_issues - post :sections, :project =>{:has_wiki => !has_wiki, :has_issues => !has_issues}, :owner_name => @project.owner.uname, :project_name => @project.name - response.should redirect_to(forbidden_path) - project = Project.find(@project.id) - project.has_wiki.should == has_wiki - project.has_issues.should == has_issues + context 'owner of the project' do + before(:each) do + @project.update_attribute :owner, @group + @project.relations.create :actor_id => @project.owner.id, :actor_type => @project.owner.class.to_s, :role => 'admin' + end + + context 'reader user' do + before(:each) do + @group.actors.create(:actor_id => @group_user.id, :actor_type => 'User', :role => 'reader') + end + + it_should_behave_like 'projects user with reader rights' + it_should_behave_like 'user without update rights' + + it 'should has reader role to group project' do + @group_user.best_role(@project).should eql('reader') # Need this? + end + + context 'user should has best role' do + before(:each) do + @project.relations.create :actor_id => @group_user.id, :actor_type => @group_user.class.to_s, :role => 'admin' + end + it_should_behave_like 'projects user with admin rights' + end + end + + context 'admin user' do + before(:each) do + @group.actors.create(:actor_id => @group_user.id, :actor_type => 'User', :role => 'admin') + end + + it_should_behave_like 'projects user with admin rights' + it_should_behave_like 'projects user with reader rights' + end + end + + context 'member of the project' do + context 'with admin rights' do + before(:each) do + @project.relations.create :actor_id => @group.id, :actor_type => @group.class.to_s, :role => 'admin' + end + + context 'reader user' do + before(:each) do + @group.actors.create(:actor_id => @group_user.id, :actor_type => 'User', :role => 'reader') + end + + it_should_behave_like 'projects user with reader rights' + it_should_behave_like 'projects user with admin rights' + + context 'user should has best role' do + before(:each) do + @project.relations.create :actor_id => @group_user.id, :actor_type => @group_user.class.to_s, :role => 'reader' + end + it_should_behave_like 'projects user with admin rights' + end + end + + context 'admin user' do + before(:each) do + @group.actors.create(:actor_id => @group_user.id, :actor_type => 'User', :role => 'admin') + end + + it_should_behave_like 'projects user with admin rights' + it_should_behave_like 'projects user with reader rights' + end + end + + context 'with reader rights' do + before(:each) do + @project.relations.create :actor_id => @group.id, :actor_type => @group.class.to_s, :role => 'reader' + end + + context 'reader user' do + before(:each) do + @group.actors.create(:actor_id => @group_user.id, :actor_type => 'User', :role => 'reader') + end + + it_should_behave_like 'projects user with reader rights' + it_should_behave_like 'user without update rights' + + context 'user should has best role' do + before(:each) do + @project.relations.create :actor_id => @group_user.id, :actor_type => @group_user.class.to_s, :role => 'admin' + end + it_should_behave_like 'projects user with admin rights' + end + end + + context 'admin user' do + before(:each) do + @group.actors.create(:actor_id => @group_user.id, :actor_type => 'User', :role => 'admin') + end + + it_should_behave_like 'projects user with reader rights' + it_should_behave_like 'user without update rights' + end + end end end end diff --git a/spec/support/shared_examples/projects_controller.rb b/spec/support/shared_examples/projects_controller.rb index 0562f06d8..0e4b4aff2 100644 --- a/spec/support/shared_examples/projects_controller.rb +++ b/spec/support/shared_examples/projects_controller.rb @@ -1,11 +1,12 @@ # -*- encoding : utf-8 -*- shared_examples_for 'projects user with reader rights' do - it_should_behave_like 'user with rights to view projects' + include_examples 'user with rights to view projects' # nested shared_examples_for dont work it 'should be able to fork project' do post :fork, :owner_name => @project.owner.uname, :project_name => @project.name response.should redirect_to(project_path(Project.last)) end + end shared_examples_for 'projects user with admin rights' do @@ -21,3 +22,21 @@ shared_examples_for 'user with rights to view projects' do response.should render_template(:index) end end + +shared_examples_for 'user without update rights' do + it 'should not be able to edit project' do + description = @project.description + put :update, :project=>{:description =>"hack"}, :owner_name => @project.owner.uname, :project_name => @project.name + Project.find(@project.id).description.should == description + response.should redirect_to(forbidden_path) + end + + it 'should not be able to edit project sections' do + has_wiki, has_issues = @project.has_wiki, @project.has_issues + post :sections, :project =>{:has_wiki => !has_wiki, :has_issues => !has_issues}, :owner_name => @project.owner.uname, :project_name => @project.name + project = Project.find(@project.id) + project.has_wiki.should == has_wiki + project.has_issues.should == has_issues + response.should redirect_to(forbidden_path) + end +end From 3ebd36f6fe49501a7c74a9d3e692e6d9743b198a Mon Sep 17 00:00:00 2001 From: "konstantin.grabar" Date: Wed, 20 Jun 2012 22:02:42 +0400 Subject: [PATCH 30/61] [refs #525] Erase corrections and refactor --- app/controllers/platforms/platforms_controller.rb | 7 +++++++ app/controllers/platforms/repositories_controller.rb | 6 ------ app/models/ability.rb | 6 ++++-- app/models/platform.rb | 4 ++++ app/models/repository.rb | 4 ---- app/views/platforms/platforms/edit.html.haml | 5 +++++ app/views/platforms/repositories/show.html.haml | 2 -- config/locales/models/repository.en.yml | 1 + config/locales/models/repository.ru.yml | 1 + config/routes.rb | 2 +- 10 files changed, 23 insertions(+), 15 deletions(-) diff --git a/app/controllers/platforms/platforms_controller.rb b/app/controllers/platforms/platforms_controller.rb index 347704c40..3566060d9 100644 --- a/app/controllers/platforms/platforms_controller.rb +++ b/app/controllers/platforms/platforms_controller.rb @@ -143,4 +143,11 @@ class Platforms::PlatformsController < Platforms::BaseController def advisories @advisories = @platform.advisories.paginate(:page => params[:page]) end + + def erase + @platform.erase + flash[:success] = t('flash.repository.erase') + redirect_to edit_platform_path(@platform) + end + end diff --git a/app/controllers/platforms/repositories_controller.rb b/app/controllers/platforms/repositories_controller.rb index f2d5fb6fd..d37caf8c6 100644 --- a/app/controllers/platforms/repositories_controller.rb +++ b/app/controllers/platforms/repositories_controller.rb @@ -54,12 +54,6 @@ class Platforms::RepositoriesController < Platforms::BaseController end end - def erase - @repository.erase - flash[:success] = t('flash.repository.erase') - redirect_to platform_repository_path(@platform, @repository) - end - def projects_list owner_subquery = " diff --git a/app/models/ability.rb b/app/models/ability.rb index 498b83caa..2607a3b46 100644 --- a/app/models/ability.rb +++ b/app/models/ability.rb @@ -90,7 +90,8 @@ class Ability can [:read, :projects_list], Repository, :platform => {:owner_type => 'User', :owner_id => user.id} can [:read, :projects_list], Repository, :platform => {:owner_type => 'Group', :owner_id => user.group_ids} can([:read, :projects_list], Repository, read_relations_for('repositories', 'platforms')) {|repository| local_reader? repository.platform} - can([:create, :update, :projects_list, :add_project, :remove_project, :erase], Repository) {|repository| local_admin? repository.platform} + can([:create, :update, :projects_list, :add_project, :remove_project], Repository) {|repository| local_admin? repository.platform} + can(:erase, Platform) {|platform| local_admin?(platform) && platform.platform_type == 'personal'} can([:change_visibility, :settings, :destroy], Repository) {|repository| owner? repository.platform} can :read, Product, :platform => {:visibility => 'open'} @@ -119,7 +120,8 @@ class Ability # Shared cannot rights for all users (registered, admin) cannot :destroy, Platform, :platform_type => 'personal' - cannot [:create, :destroy, :add_project, :remove_project, :erase], Repository, :platform => {:platform_type => 'personal'} + cannot [:create, :destroy, :add_project, :remove_project], Repository, :platform => {:platform_type => 'personal'} + cannot :erase, Platform, :platform_type => 'main' cannot :destroy, Issue cannot [:members, :add_member, :remove_member, :remove_members], Platform, :platform_type => 'personal' diff --git a/app/models/platform.rb b/app/models/platform.rb index c617c724a..74cb81ded 100644 --- a/app/models/platform.rb +++ b/app/models/platform.rb @@ -48,6 +48,10 @@ class Platform < ActiveRecord::Base include Modules::Models::Owner + def erase + system("rm -Rf #{ APP_CONFIG['root_path'] }/platforms/#{ self.name }/repository/*") + end + def urpmi_list(host, pair = nil) blank_pair = {:login => 'login', :pass => 'password'} pair = blank_pair if pair.blank? diff --git a/app/models/repository.rb b/app/models/repository.rb index 99b483042..57c741790 100644 --- a/app/models/repository.rb +++ b/app/models/repository.rb @@ -16,10 +16,6 @@ class Repository < ActiveRecord::Base attr_accessible :name, :description attr_readonly :name, :platform_id - def erase - system("rm -Rf #{ APP_CONFIG['root_path'] }/platforms/#{ self.platform.name }/repository/*") - end - def base_clone(attrs = {}) dup.tap do |c| c.platform_id = nil diff --git a/app/views/platforms/platforms/edit.html.haml b/app/views/platforms/platforms/edit.html.haml index a397e71d1..56f6cb162 100644 --- a/app/views/platforms/platforms/edit.html.haml +++ b/app/views/platforms/platforms/edit.html.haml @@ -9,3 +9,8 @@ .hr .leftside= t("layout.platforms.delete_warning") .rightside= link_to t("layout.delete"), platform_path(@platform), :method => :delete, :confirm => t("layout.platforms.confirm_delete"), :class => 'button' +- if can? :erase, @platform + .hr + .leftside= t("layout.repositories.erase_warning") + .rightside= link_to t("layout.repositories.erase"), erase_platform_path(@platform), :class => 'button', :confirm => t('layout.repositories.erase_confirm'), :method => :post + .both diff --git a/app/views/platforms/repositories/show.html.haml b/app/views/platforms/repositories/show.html.haml index ffc4f9bc4..5540913de 100644 --- a/app/views/platforms/repositories/show.html.haml +++ b/app/views/platforms/repositories/show.html.haml @@ -11,7 +11,5 @@ %h3.fix= t("layout.projects.list_header") - if can? :add_project, @repository = link_to t("layout.projects.add"), add_project_platform_repository_path(@platform, @repository), :class => 'button' -- if can? :erase, @repository - = link_to t("layout.repositories.erase"), erase_platform_repository_path(@platform, @repository), :class => 'button', :confirm => t('layout.repositories.erase_confirm'), :method => :post = render 'proj_list' diff --git a/config/locales/models/repository.en.yml b/config/locales/models/repository.en.yml index 82dcc3135..81cf14472 100644 --- a/config/locales/models/repository.en.yml +++ b/config/locales/models/repository.en.yml @@ -16,6 +16,7 @@ en: current_repository_header: Current repository erase: Erase erase_confirm: Are you sure you want to erase this repository? + erase_warning: Warning! Erased repository can not be restored! personal_repositories: settings_header: Settings diff --git a/config/locales/models/repository.ru.yml b/config/locales/models/repository.ru.yml index 5557a74ce..fb9e7fe31 100644 --- a/config/locales/models/repository.ru.yml +++ b/config/locales/models/repository.ru.yml @@ -16,6 +16,7 @@ ru: current_repository_header: Текущий репозиторий erase: Очистить erase_confirm: Уверены, что хотите очистить репозиторий? + erase_warning: Внимание! Очищеный репозиторий не может быть восстановлен! personal_repositories: settings_header: Настройки diff --git a/config/routes.rb b/config/routes.rb index 0beeb7144..af396fa70 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -44,6 +44,7 @@ Rosa::Application.routes.draw do resources :platforms do resources :private_users, :except => [:show, :destroy, :update] member do + post :erase get :clone get :members post :remove_members @@ -58,7 +59,6 @@ Rosa::Application.routes.draw do resources :repositories do member do get :add_project - post :erase delete :remove_project get :projects_list end From 93ec9a135d0a76e1c48db49c757f68f66a70127e Mon Sep 17 00:00:00 2001 From: Alexander Machehin Date: Thu, 21 Jun 2012 00:10:27 +0600 Subject: [PATCH 31/61] [refs #531] some refactoring and model tests --- app/models/ability.rb | 7 +++---- app/models/user.rb | 22 ++++++++++++-------- spec/models/user_spec.rb | 45 +++++++++++++++++++++++++++++++++++++--- 3 files changed, 58 insertions(+), 16 deletions(-) diff --git a/app/models/ability.rb b/app/models/ability.rb index 439959391..46c62d3de 100644 --- a/app/models/ability.rb +++ b/app/models/ability.rb @@ -147,10 +147,9 @@ class Ability end def relation_exists_for(target, roles) - rel = target.relations - is_owner_group = target.owner.class == Group - groups = @user.groups - groups = groups.where('groups.id != ?', target.owner.id) if is_owner_group + rel, groups, = target.relations, groups = @user.groups + groups = groups.where('groups.id != ?', target.owner.id) if is_owner_group = target.owner.class == Group + rel.exists?(:actor_id => @user.id, :actor_type => 'User', :role => roles) or # user is member (@user.groups.exists?(:id => target.owner.id, :relations =>{:role => roles}) and is_owner_group) or # user group is owner rel.exists?(:actor_id => groups, :actor_type => 'Group', :role => roles) # user group is member diff --git a/app/models/user.rb b/app/models/user.rb index 3498c44eb..e92992902 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -130,22 +130,26 @@ class User < ActiveRecord::Base end end - def best_role target - rel = target.relations - is_owner_group = target.owner.class == Group - gr = self.groups - gr = gr.where('groups.id != ?', target.owner.id) if is_owner_group - roles = [] - if is_owner_group + def target_roles target + rel, gr, roles = target.relations, self.groups, [] + is_group_owner = target.owner.class == Group + + if is_group_owner + gr = gr.where('groups.id != ?', target.owner.id) owner_group = self.groups.where(:id => target.owner.id).first - roles += owner_group.actors.where(:actor_id => self) if owner_group # user group is owner + roles += owner_group.actors.where(:actor_id => self) if owner_group# user group is owner end roles += rel.where(:actor_id => self.id, :actor_type => 'User') # user is member roles += rel.where(:actor_id => gr, :actor_type => 'Group') # user group is member - roles = roles.map(&:role).uniq + roles.map(&:role).uniq + end + + def best_role target + roles = target_roles(target) return 'admin' if roles.include? 'admin' return 'writer' if roles.include? 'writer' return 'reader' if roles.include? 'reader' + return nil if roles.count == 0 raise "unknown user #{self.uname} roles #{roles}" end end diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index 28b7f9d0d..627daab23 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -1,6 +1,45 @@ # -*- encoding : utf-8 -*- require 'spec_helper' -#describe User do -# pending "add some examples to (or delete) #{__FILE__}" -#end +describe User do + before { stub_symlink_methods } + before(:each) do + @project = FactoryGirl.create(:project) + @group = FactoryGirl.create(:group) + @user = FactoryGirl.create(:user) + end + + context 'for own project' do + it 'should have admin role' do + @project.owner.best_role(@project).should == 'admin' + end + end + + context 'other user' do + it 'should have not right to project' do + other_user = FactoryGirl.create(:user) + puts "other user roles are #{other_user.target_roles(@project)}" + other_user.best_role(@project).should == nil + end + end + + context 'for group project' do + before(:each) do + @project.relations.destroy_all + @project.update_attribute :owner, @group + @project.relations.create :actor_id => @project.owner.id, :actor_type => @project.owner.class.to_s, :role => 'admin' + end + + context 'for group member' do + context 'with reader rights' do + before(:each) do + @group.actors.create(:actor_id => @user.id, :actor_type => 'User', :role => 'reader') + end + + it 'should have reader role to project' do + @user.best_role(@project).should == 'reader' + end + end + end + end +end From dfb1da97b414cf0df824da2f3070b2e2a39f6d6e Mon Sep 17 00:00:00 2001 From: "konstantin.grabar" Date: Wed, 20 Jun 2012 22:33:49 +0400 Subject: [PATCH 32/61] [refs #525] Fix locales --- config/locales/models/repository.en.yml | 2 +- config/locales/models/repository.ru.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/config/locales/models/repository.en.yml b/config/locales/models/repository.en.yml index 81cf14472..a16ee91b9 100644 --- a/config/locales/models/repository.en.yml +++ b/config/locales/models/repository.en.yml @@ -16,7 +16,7 @@ en: current_repository_header: Current repository erase: Erase erase_confirm: Are you sure you want to erase this repository? - erase_warning: Warning! Erased repository can not be restored! + erase_warning: Attention! Cleared packages cannot be restored! personal_repositories: settings_header: Settings diff --git a/config/locales/models/repository.ru.yml b/config/locales/models/repository.ru.yml index fb9e7fe31..592dafc43 100644 --- a/config/locales/models/repository.ru.yml +++ b/config/locales/models/repository.ru.yml @@ -16,7 +16,7 @@ ru: current_repository_header: Текущий репозиторий erase: Очистить erase_confirm: Уверены, что хотите очистить репозиторий? - erase_warning: Внимание! Очищеный репозиторий не может быть восстановлен! + erase_warning: Внимание! Очищенные пакеты не могут быть восстановлены! personal_repositories: settings_header: Настройки From 5e3241a1f52517ab9f41a6a16e6da31c652e511e Mon Sep 17 00:00:00 2001 From: "konstantin.grabar" Date: Thu, 21 Jun 2012 11:15:20 +0400 Subject: [PATCH 33/61] [refs #525] Rename erase to clear. Fix flash. Replace repository to platform in locales --- app/controllers/platforms/platforms_controller.rb | 6 +++--- app/models/platform.rb | 2 +- app/views/platforms/platforms/edit.html.haml | 6 +++--- config/locales/models/repository.en.yml | 8 ++++---- config/locales/models/repository.ru.yml | 8 ++++---- config/routes.rb | 2 +- 6 files changed, 16 insertions(+), 16 deletions(-) diff --git a/app/controllers/platforms/platforms_controller.rb b/app/controllers/platforms/platforms_controller.rb index 3566060d9..8aa24dd30 100644 --- a/app/controllers/platforms/platforms_controller.rb +++ b/app/controllers/platforms/platforms_controller.rb @@ -144,9 +144,9 @@ class Platforms::PlatformsController < Platforms::BaseController @advisories = @platform.advisories.paginate(:page => params[:page]) end - def erase - @platform.erase - flash[:success] = t('flash.repository.erase') + def clear + @platform.clear + flash[:notice] = t('flash.repository.clear') redirect_to edit_platform_path(@platform) end diff --git a/app/models/platform.rb b/app/models/platform.rb index 74cb81ded..95cc24ba2 100644 --- a/app/models/platform.rb +++ b/app/models/platform.rb @@ -48,7 +48,7 @@ class Platform < ActiveRecord::Base include Modules::Models::Owner - def erase + def clear system("rm -Rf #{ APP_CONFIG['root_path'] }/platforms/#{ self.name }/repository/*") end diff --git a/app/views/platforms/platforms/edit.html.haml b/app/views/platforms/platforms/edit.html.haml index 56f6cb162..18442734e 100644 --- a/app/views/platforms/platforms/edit.html.haml +++ b/app/views/platforms/platforms/edit.html.haml @@ -9,8 +9,8 @@ .hr .leftside= t("layout.platforms.delete_warning") .rightside= link_to t("layout.delete"), platform_path(@platform), :method => :delete, :confirm => t("layout.platforms.confirm_delete"), :class => 'button' -- if can? :erase, @platform +- if can? :clear, @platform .hr - .leftside= t("layout.repositories.erase_warning") - .rightside= link_to t("layout.repositories.erase"), erase_platform_path(@platform), :class => 'button', :confirm => t('layout.repositories.erase_confirm'), :method => :post + .leftside= t("layout.repositories.clear_warning") + .rightside= link_to t("layout.repositories.clear"), clear_platform_path(@platform), :class => 'button', :confirm => t('layout.repositories.clear_confirm'), :method => :post .both diff --git a/config/locales/models/repository.en.yml b/config/locales/models/repository.en.yml index a16ee91b9..7f8ad732b 100644 --- a/config/locales/models/repository.en.yml +++ b/config/locales/models/repository.en.yml @@ -14,9 +14,9 @@ en: back_to_the_list: ⇐ List of repositories confirm_delete: Are you sure you want to delete this repository? current_repository_header: Current repository - erase: Erase - erase_confirm: Are you sure you want to erase this repository? - erase_warning: Attention! Cleared packages cannot be restored! + clear: Clear + clear_confirm: Are you sure you want to clear this platform? + clear_warning: Attention! Cleared packages cannot be restored! personal_repositories: settings_header: Settings @@ -35,7 +35,7 @@ en: project_not_added: Project adding error. A project with such name already exists in this repository. Remove the old project first project_removed: Project deleted project_not_removed: Unable to delete project from repository - erase: Repository successfully erased! + clear: Platform successfully cleared! activerecord: models: diff --git a/config/locales/models/repository.ru.yml b/config/locales/models/repository.ru.yml index 592dafc43..b01307e1c 100644 --- a/config/locales/models/repository.ru.yml +++ b/config/locales/models/repository.ru.yml @@ -14,9 +14,9 @@ ru: back_to_the_list: ⇐ К списку репозиториев confirm_delete: Вы уверены, что хотите удалить этот репозиторий? current_repository_header: Текущий репозиторий - erase: Очистить - erase_confirm: Уверены, что хотите очистить репозиторий? - erase_warning: Внимание! Очищенные пакеты не могут быть восстановлены! + clear: Очистить + clear_confirm: Уверены, что хотите очистить платформу? + clear_warning: Внимание! Очищенные пакеты не могут быть восстановлены! personal_repositories: settings_header: Настройки @@ -35,7 +35,7 @@ ru: project_not_added: Не удалось добавить проект. В этом репозитории уже есть проект с таким именем. Сначала нужно удалить старый проект project_removed: Проект удален из репозитория project_not_removed: Не удалось удалить проект из репозитория - erase: Репозиторий успешно очищен! + clear: Платформа успешно очищена! activerecord: models: diff --git a/config/routes.rb b/config/routes.rb index af396fa70..e8297ffc5 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -44,7 +44,7 @@ Rosa::Application.routes.draw do resources :platforms do resources :private_users, :except => [:show, :destroy, :update] member do - post :erase + post :clear get :clone get :members post :remove_members From d73547d3bcb864c539cb097b1c24ca5aa26f671f Mon Sep 17 00:00:00 2001 From: "konstantin.grabar" Date: Thu, 21 Jun 2012 13:07:20 +0400 Subject: [PATCH 34/61] [refs #521] Remove unnecessary elements. Add some more links --- public/404.html | 23 +++++++---------------- public/500.html | 23 +++++++---------------- 2 files changed, 14 insertions(+), 32 deletions(-) diff --git a/public/404.html b/public/404.html index 1b6717f14..a8ce47791 100644 --- a/public/404.html +++ b/public/404.html @@ -13,23 +13,14 @@ @@ -41,7 +32,7 @@ - +
@@ -51,12 +42,12 @@
- +
- +

Error 404

Page not found

@@ -66,9 +57,9 @@ Or use the search.

- +
- +
diff --git a/public/500.html b/public/500.html index f4a948b0a..b94599412 100644 --- a/public/500.html +++ b/public/500.html @@ -13,23 +13,14 @@ @@ -41,7 +32,7 @@ - +
@@ -51,12 +42,12 @@
- +
- +

Error 500

Something went wrong.
We've been notified about this issue
@@ -68,9 +59,9 @@ Or use the search.

- +

- +
From d2f4135065ce5b5f18c52a8633fdad87d33ca472 Mon Sep 17 00:00:00 2001 From: Alexander Machehin Date: Thu, 21 Jun 2012 15:49:39 +0600 Subject: [PATCH 35/61] [refs #531] refactoring --- app/models/ability.rb | 15 +++------------ app/models/user.rb | 19 +++++++++++-------- 2 files changed, 14 insertions(+), 20 deletions(-) diff --git a/app/models/ability.rb b/app/models/ability.rb index 46c62d3de..a0c5f9e1f 100644 --- a/app/models/ability.rb +++ b/app/models/ability.rb @@ -146,25 +146,16 @@ class Ability relations.actor_type = 'Group' AND relations.actor_id IN (?)))", parent.classify, @user, @user.group_ids] end - def relation_exists_for(target, roles) - rel, groups, = target.relations, groups = @user.groups - groups = groups.where('groups.id != ?', target.owner.id) if is_owner_group = target.owner.class == Group - - rel.exists?(:actor_id => @user.id, :actor_type => 'User', :role => roles) or # user is member - (@user.groups.exists?(:id => target.owner.id, :relations =>{:role => roles}) and is_owner_group) or # user group is owner - rel.exists?(:actor_id => groups, :actor_type => 'Group', :role => roles) # user group is member - end - def local_reader?(target) - relation_exists_for(target, %w{reader writer admin}) or owner?(target) + %w{reader writer admin}.include? @user.best_role(target) end def local_writer?(target) - relation_exists_for(target, %w{writer admin}) or owner?(target) + %w{writer admin}.include? @user.best_role(target) end def local_admin?(target) - relation_exists_for(target, 'admin') or owner?(target) + @user.best_role(target) == 'admin' end def owner?(target) diff --git a/app/models/user.rb b/app/models/user.rb index e92992902..e9abc6f36 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -130,6 +130,17 @@ class User < ActiveRecord::Base end end + def best_role target + roles = target_roles(target) + return 'admin' if roles.include? 'admin' + return 'writer' if roles.include? 'writer' + return 'reader' if roles.include? 'reader' + return nil if roles.count == 0 + raise "unknown user #{self.uname} roles #{roles}" + end + + protected + def target_roles target rel, gr, roles = target.relations, self.groups, [] is_group_owner = target.owner.class == Group @@ -144,12 +155,4 @@ class User < ActiveRecord::Base roles.map(&:role).uniq end - def best_role target - roles = target_roles(target) - return 'admin' if roles.include? 'admin' - return 'writer' if roles.include? 'writer' - return 'reader' if roles.include? 'reader' - return nil if roles.count == 0 - raise "unknown user #{self.uname} roles #{roles}" - end end From a033e3192e8c564636cc0f5a852c54e41ca813e1 Mon Sep 17 00:00:00 2001 From: Alexander Machehin Date: Thu, 21 Jun 2012 16:35:02 +0600 Subject: [PATCH 36/61] [refs #531] fixed tests --- spec/controllers/projects/build_lists_controller_spec.rb | 2 +- spec/controllers/projects/comments_controller_spec.rb | 2 ++ spec/models/cancan_spec.rb | 1 + 3 files changed, 4 insertions(+), 1 deletion(-) diff --git a/spec/controllers/projects/build_lists_controller_spec.rb b/spec/controllers/projects/build_lists_controller_spec.rb index b35890892..1431004eb 100644 --- a/spec/controllers/projects/build_lists_controller_spec.rb +++ b/spec/controllers/projects/build_lists_controller_spec.rb @@ -177,7 +177,7 @@ describe Projects::BuildListsController do before(:each) do @owner_group = FactoryGirl.create(:group) @owner_user = FactoryGirl.create(:user) - @owner_group.actors.create :role => 'reader', :actor_id => @owner_user.id, :actor_type => 'User' + @owner_group.actors.create :role => 'admin', :actor_id => @owner_user.id, :actor_type => 'User' @member_group = FactoryGirl.create(:group) @member_user = FactoryGirl.create(:user) @member_group.actors.create :role => 'reader', :actor_id => @member_user.id, :actor_type => 'User' diff --git a/spec/controllers/projects/comments_controller_spec.rb b/spec/controllers/projects/comments_controller_spec.rb index c04b09c58..1e0501495 100644 --- a/spec/controllers/projects/comments_controller_spec.rb +++ b/spec/controllers/projects/comments_controller_spec.rb @@ -102,6 +102,8 @@ describe Projects::CommentsController do context 'for project owner user' do before(:each) do @project.update_attribute(:owner, @user) + @project.relations.destroy_all + @project.relations.create :actor_id => @project.owner.id, :actor_type => @project.owner.class.to_s, :role => 'admin' @create_params[:owner_name] = @user.uname; @update_params[:owner_name] = @user.uname end diff --git a/spec/models/cancan_spec.rb b/spec/models/cancan_spec.rb index c496fbbf9..467b1e275 100644 --- a/spec/models/cancan_spec.rb +++ b/spec/models/cancan_spec.rb @@ -208,6 +208,7 @@ describe CanCan do context 'with owner rights' do before(:each) do @project.update_attribute(:owner, @user) + @project.relations.create!(:actor_id => @user.id, :actor_type => 'User', :role => 'admin') @issue.project.reload end From 10efb2401acfc67c8c696f63af7c34942181357a Mon Sep 17 00:00:00 2001 From: "konstantin.grabar" Date: Thu, 21 Jun 2012 17:49:20 +0400 Subject: [PATCH 37/61] [refs #442] Fix auto_publish select --- app/controllers/platforms/platforms_controller.rb | 2 ++ app/views/platforms/platforms/build_all.html.haml | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/app/controllers/platforms/platforms_controller.rb b/app/controllers/platforms/platforms_controller.rb index 4f8192456..d91f48a1b 100644 --- a/app/controllers/platforms/platforms_controller.rb +++ b/app/controllers/platforms/platforms_controller.rb @@ -17,6 +17,7 @@ class Platforms::PlatformsController < Platforms::BaseController if mass_build.save redirect_to(mass_builds_platform_path(@platform), :notice => t("flash.platform.build_all_success")) else + @auto_publish_selected = params[:auto_publish].present? ? params[:auto_publish].present? : false @mass_builds = MassBuild.by_platform(@platform).order('created_at DESC').paginate(:page => params[:page], :per_page => 20) flash[:warning] = mass_build.errors.full_messages.join('. ') flash[:error] = t("flash.platform.build_all_error") @@ -25,6 +26,7 @@ class Platforms::PlatformsController < Platforms::BaseController def mass_builds @mass_builds = MassBuild.by_platform(@platform).order('created_at DESC').paginate(:page => params[:page], :per_page => 20) + @auto_publish_selected = true render :action => :build_all end diff --git a/app/views/platforms/platforms/build_all.html.haml b/app/views/platforms/platforms/build_all.html.haml index 5a204a00a..f5ed8478a 100644 --- a/app/views/platforms/platforms/build_all.html.haml +++ b/app/views/platforms/platforms/build_all.html.haml @@ -19,7 +19,7 @@ .both %h3= t("activerecord.attributes.build_list.preferences") .both.bottom_20 - = check_box_tag :auto_publish, true, params[:auto_publish].present? ? params[:auto_publish].present? : false, :id => 'auto_publish' + = check_box_tag :auto_publish, true, @auto_publish_selected, :id => 'auto_publish' = label_tag :auto_publish %br From d5a6b47be31277b4cfc012f9160153e69c858200 Mon Sep 17 00:00:00 2001 From: Alexander Machehin Date: Thu, 21 Jun 2012 20:19:44 +0600 Subject: [PATCH 38/61] [refs #531] user best role tests --- app/models/user.rb | 6 ++-- spec/models/user_spec.rb | 60 ++++++++++++++++++++++++++++++++++++---- 2 files changed, 57 insertions(+), 9 deletions(-) diff --git a/app/models/user.rb b/app/models/user.rb index e9abc6f36..ddf0fc3f1 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -143,12 +143,12 @@ class User < ActiveRecord::Base def target_roles target rel, gr, roles = target.relations, self.groups, [] - is_group_owner = target.owner.class == Group - if is_group_owner - gr = gr.where('groups.id != ?', target.owner.id) + if target.owner.class == Group owner_group = self.groups.where(:id => target.owner.id).first roles += owner_group.actors.where(:actor_id => self) if owner_group# user group is owner + + gr = gr.where('groups.id != ?', target.owner.id) # exclude target owner group from users group list end roles += rel.where(:actor_id => self.id, :actor_type => 'User') # user is member roles += rel.where(:actor_id => gr, :actor_type => 'Group') # user group is member diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index 627daab23..8e61b75c6 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -18,11 +18,30 @@ describe User do context 'other user' do it 'should have not right to project' do other_user = FactoryGirl.create(:user) - puts "other user roles are #{other_user.target_roles(@project)}" other_user.best_role(@project).should == nil end end + %w(reader writer admin).each do |group_role| + context "for group with #{group_role} role in project" do + before(:each) do + @project.relations.create :actor_id => @group.id, :actor_type => @group.class.to_s, :role => group_role + end + + %w(reader writer admin).each do |role| + context "for user with #{role} role in group" do + before(:each) do + @group.actors.create(:actor_id => @user.id, :actor_type => 'User', :role => role) + end + + it "should have #{group_role} role to project" do + @user.best_role(@project).should == group_role + end + end + end + end + end + context 'for group project' do before(:each) do @project.relations.destroy_all @@ -30,16 +49,45 @@ describe User do @project.relations.create :actor_id => @project.owner.id, :actor_type => @project.owner.class.to_s, :role => 'admin' end - context 'for group member' do - context 'with reader rights' do + %w(reader writer admin).each do |role| + context "for user with #{role} role in group" do before(:each) do - @group.actors.create(:actor_id => @user.id, :actor_type => 'User', :role => 'reader') + @group.actors.create(:actor_id => @user.id, :actor_type => 'User', :role => role) end - it 'should have reader role to project' do - @user.best_role(@project).should == 'reader' + it "should have #{role} role to project" do + @user.best_role(@project).should == role end end end + + %w(reader writer admin).each do |role| + context "for user with #{role} role in project" do + before(:each) do + @project.relations.create(:actor_id => @user.id, :actor_type => 'User', :role => role) + end + + it "should have #{role} role to project" do + @user.best_role(@project).should == role + end + end + end + + context "for user with reader role in group and writer role in project" do + it "should have writer best role to project" do + @group.actors.create(:actor_id => @user.id, :actor_type => 'User', :role => 'reader') + @project.relations.create(:actor_id => @user.id, :actor_type => 'User', :role => 'writer') + @user.best_role(@project).should == 'writer' + end + end + + context "for user with admin role in group and reader role in project" do + it "should have admin best role to project" do + @group.actors.create(:actor_id => @user.id, :actor_type => 'User', :role => 'admin') + @project.relations.create(:actor_id => @user.id, :actor_type => 'User', :role => 'reader') + @user.best_role(@project).should == 'admin' + end + end end + end From 9a2dcda3d1825c516ac3de6c839d5d5fb12de146 Mon Sep 17 00:00:00 2001 From: Alexander Machehin Date: Fri, 22 Jun 2012 16:33:03 +0600 Subject: [PATCH 39/61] [refs #537] fixed build list publish transaction --- app/models/build_list.rb | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/app/models/build_list.rb b/app/models/build_list.rb index 8daf300ac..b46bd1eba 100644 --- a/app/models/build_list.rb +++ b/app/models/build_list.rb @@ -182,6 +182,10 @@ class BuildList < ActiveRecord::Base [BUILD_PENDING, BuildServer::PLATFORM_PENDING].include? status && bs_id end + def can_publish? + [BuildServer::SUCCESS, FAILED_PUBLISH].include? status + end + def can_reject_publish? can_publish? and save_to_platform.released end From f3bd3bbd7f8d4b044d87cf5b0307a3a78f7b5c36 Mon Sep 17 00:00:00 2001 From: "konstantin.grabar" Date: Fri, 22 Jun 2012 19:10:44 +0400 Subject: [PATCH 40/61] [refs #442] Add mass build counters ant their update. Add failed builds report generate --- .../platforms/platforms_controller.rb | 5 +++ app/models/build_list.rb | 10 +++++- app/models/mass_build.rb | 9 +++++ ...20622092725_add_counters_to_mass_builds.rb | 9 +++++ db/schema.rb | 36 ++++++++++--------- 5 files changed, 52 insertions(+), 17 deletions(-) create mode 100644 db/migrate/20120622092725_add_counters_to_mass_builds.rb diff --git a/app/controllers/platforms/platforms_controller.rb b/app/controllers/platforms/platforms_controller.rb index d9f9d8415..b31fdedbd 100644 --- a/app/controllers/platforms/platforms_controller.rb +++ b/app/controllers/platforms/platforms_controller.rb @@ -31,6 +31,11 @@ class Platforms::PlatformsController < Platforms::BaseController render :action => :build_all end + def get_failed_builds_list + @mass_build = MassBuild.find params[:mass_build_id] + send_file @mass_build.generate_failed_builds_list, :filename => "mass_build_#{@mass_build.id}" + end + def index @platforms = @platforms.accessible_by(current_ability, :related).paginate(:page => params[:page], :per_page => 20) end diff --git a/app/models/build_list.rb b/app/models/build_list.rb index 8daf300ac..895cadaf5 100644 --- a/app/models/build_list.rb +++ b/app/models/build_list.rb @@ -6,7 +6,7 @@ class BuildList < ActiveRecord::Base belongs_to :build_for_platform, :class_name => 'Platform' belongs_to :user belongs_to :advisory - belongs_to :mass_build + belongs_to :mass_build, :counter_cache => true has_many :items, :class_name => "BuildList::Item", :dependent => :destroy has_many :packages, :class_name => "BuildList::Package", :dependent => :destroy @@ -103,6 +103,14 @@ class BuildList < ActiveRecord::Base state_machine :status, :initial => :waiting_for_response do + around_transition do |build_list, transition, block| + if build_list.mass_build + MassBuild.decrement_counter "#{BuildList::HUMAN_STATUSES[build_list.status].to_s}_count", build_list.mass_build_id + block.call + MassBuild.increment_counter "#{BuildList::HUMAN_STATUSES[build_list.status].to_s}_count", build_list.mass_build_id + end + end + after_transition :on => :published, :do => :set_version_and_tag event :place_build do diff --git a/app/models/mass_build.rb b/app/models/mass_build.rb index 1c2f5c3ad..37e950bb0 100644 --- a/app/models/mass_build.rb +++ b/app/models/mass_build.rb @@ -32,4 +32,13 @@ class MassBuild < ActiveRecord::Base :auto_publish => self.auto_publish ) # later with resque end + + def generate_failed_builds_list + report = "" + BuildList.where(:status => BuildServer::BUILD_ERROR, :mass_build_id => self.id).each do |build_list| + report << "ID: #{build_list.id}; " + report << "PROJECT_NAME: #{build_list.project.name}\n" + end + report + end end diff --git a/db/migrate/20120622092725_add_counters_to_mass_builds.rb b/db/migrate/20120622092725_add_counters_to_mass_builds.rb new file mode 100644 index 000000000..a35cd61d2 --- /dev/null +++ b/db/migrate/20120622092725_add_counters_to_mass_builds.rb @@ -0,0 +1,9 @@ +class AddCountersToMassBuilds < ActiveRecord::Migration + def change + add_column :mass_builds, :build_lists_count, :integer, :default => 0 + add_column :mass_builds, :build_published_count, :integer, :default => 0 + add_column :mass_builds, :build_pending_count, :integer, :default => 0 + add_column :mass_builds, :build_started_count, :integer, :default => 0 + add_column :mass_builds, :build_publish_count, :integer, :default => 0 + end +end diff --git a/db/schema.rb b/db/schema.rb index b644b0e4c..ca0d5df26 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,14 +11,14 @@ # # It's strongly recommended to check this file into your version control system. -ActiveRecord::Schema.define(:version => 20120609163454) do +ActiveRecord::Schema.define(:version => 20120622092725) do create_table "activity_feeds", :force => true do |t| t.integer "user_id", :null => false t.string "kind" t.text "data" - t.datetime "created_at", :null => false - t.datetime "updated_at", :null => false + t.datetime "created_at" + t.datetime "updated_at" end create_table "advisories", :force => true do |t| @@ -199,11 +199,16 @@ ActiveRecord::Schema.define(:version => 20120609163454) do create_table "mass_builds", :force => true do |t| t.integer "platform_id" t.string "name" - t.datetime "created_at", :null => false - t.datetime "updated_at", :null => false + t.datetime "created_at", :null => false + t.datetime "updated_at", :null => false t.string "arch_names" t.integer "user_id" - t.boolean "auto_publish", :default => false, :null => false + t.boolean "auto_publish", :default => false, :null => false + t.integer "build_lists_count", :default => 0 + t.integer "build_published_count", :default => 0 + t.integer "build_pending_count", :default => 0 + t.integer "build_started_count", :default => 0 + t.integer "build_publish_count", :default => 0 end create_table "platforms", :force => true do |t| @@ -217,7 +222,7 @@ ActiveRecord::Schema.define(:version => 20120609163454) do t.string "owner_type" t.string "visibility", :default => "open", :null => false t.string "platform_type", :default => "main", :null => false - t.string "distrib_type", :null => false + t.string "distrib_type" end add_index "platforms", ["name"], :name => "index_platforms_on_name", :unique => true, :case_sensitive => false @@ -288,27 +293,25 @@ ActiveRecord::Schema.define(:version => 20120609163454) do t.text "description" t.string "ancestry" t.boolean "has_issues", :default => true + t.boolean "has_wiki", :default => false t.string "srpm_file_name" t.string "srpm_content_type" t.integer "srpm_file_size" t.datetime "srpm_updated_at" - t.boolean "has_wiki", :default => false t.string "default_branch", :default => "master" t.boolean "is_package", :default => true, :null => false t.integer "average_build_time", :default => 0, :null => false t.integer "build_count", :default => 0, :null => false end - add_index "projects", ["owner_id"], :name => "index_projects_on_name_and_owner_id_and_owner_type", :unique => true, :case_sensitive => false - create_table "register_requests", :force => true do |t| t.string "name" t.string "email" t.string "token" t.boolean "approved", :default => false t.boolean "rejected", :default => false - t.datetime "created_at" - t.datetime "updated_at" + t.datetime "created_at", :null => false + t.datetime "updated_at", :null => false t.string "interest" t.text "more" end @@ -362,6 +365,7 @@ ActiveRecord::Schema.define(:version => 20120609163454) do t.string "name" t.string "email", :default => "", :null => false t.string "encrypted_password", :limit => 128, :default => "", :null => false + t.string "password_salt", :default => "", :null => false t.string "reset_password_token" t.datetime "remember_created_at" t.datetime "created_at" @@ -369,8 +373,11 @@ ActiveRecord::Schema.define(:version => 20120609163454) do t.string "uname" t.string "role" t.string "language", :default => "en" - t.datetime "reset_password_sent_at" + t.string "confirmation_token" + t.datetime "confirmed_at" + t.datetime "confirmation_sent_at" t.integer "own_projects_count", :default => 0, :null => false + t.datetime "reset_password_sent_at" t.text "professional_experience" t.string "site" t.string "company" @@ -382,9 +389,6 @@ ActiveRecord::Schema.define(:version => 20120609163454) do t.integer "failed_attempts", :default => 0 t.string "unlock_token" t.datetime "locked_at" - t.string "confirmation_token" - t.datetime "confirmed_at" - t.datetime "confirmation_sent_at" t.string "authentication_token" t.integer "build_priority", :default => 50 end From baec8a101674bd29e44ef1482d5a4f3d47100440 Mon Sep 17 00:00:00 2001 From: "konstantin.grabar" Date: Mon, 25 Jun 2012 18:26:01 +0400 Subject: [PATCH 41/61] [refs #525] Fix clear action rights --- .../javascripts/lib/bootstrap-collapse.js | 157 ++++++++++++++++++ app/models/ability.rb | 4 +- 2 files changed, 159 insertions(+), 2 deletions(-) create mode 100644 app/assets/javascripts/lib/bootstrap-collapse.js diff --git a/app/assets/javascripts/lib/bootstrap-collapse.js b/app/assets/javascripts/lib/bootstrap-collapse.js new file mode 100644 index 000000000..fbc915b9f --- /dev/null +++ b/app/assets/javascripts/lib/bootstrap-collapse.js @@ -0,0 +1,157 @@ +/* ============================================================= + * bootstrap-collapse.js v2.0.4 + * http://twitter.github.com/bootstrap/javascript.html#collapse + * ============================================================= + * Copyright 2012 Twitter, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============================================================ */ + + +!function ($) { + + "use strict"; // jshint ;_; + + + /* COLLAPSE PUBLIC CLASS DEFINITION + * ================================ */ + + var Collapse = function (element, options) { + this.$element = $(element) + this.options = $.extend({}, $.fn.collapse.defaults, options) + + if (this.options.parent) { + this.$parent = $(this.options.parent) + } + + this.options.toggle && this.toggle() + } + + Collapse.prototype = { + + constructor: Collapse + + , dimension: function () { + var hasWidth = this.$element.hasClass('width') + return hasWidth ? 'width' : 'height' + } + + , show: function () { + var dimension + , scroll + , actives + , hasData + + if (this.transitioning) return + + dimension = this.dimension() + scroll = $.camelCase(['scroll', dimension].join('-')) + actives = this.$parent && this.$parent.find('> .accordion-group > .in') + + if (actives && actives.length) { + hasData = actives.data('collapse') + if (hasData && hasData.transitioning) return + actives.collapse('hide') + hasData || actives.data('collapse', null) + } + + this.$element[dimension](0) + this.transition('addClass', $.Event('show'), 'shown') + this.$element[dimension](this.$element[0][scroll]) + } + + , hide: function () { + var dimension + if (this.transitioning) return + dimension = this.dimension() + this.reset(this.$element[dimension]()) + this.transition('removeClass', $.Event('hide'), 'hidden') + this.$element[dimension](0) + } + + , reset: function (size) { + var dimension = this.dimension() + + this.$element + .removeClass('collapse') + [dimension](size || 'auto') + [0].offsetWidth + + this.$element[size !== null ? 'addClass' : 'removeClass']('collapse') + + return this + } + + , transition: function (method, startEvent, completeEvent) { + var that = this + , complete = function () { + if (startEvent.type == 'show') that.reset() + that.transitioning = 0 + that.$element.trigger(completeEvent) + } + + this.$element.trigger(startEvent) + + if (startEvent.isDefaultPrevented()) return + + this.transitioning = 1 + + this.$element[method]('in') + + $.support.transition && this.$element.hasClass('collapse') ? + this.$element.one($.support.transition.end, complete) : + complete() + } + + , toggle: function () { + this[this.$element.hasClass('in') ? 'hide' : 'show']() + } + + } + + + /* COLLAPSIBLE PLUGIN DEFINITION + * ============================== */ + + $.fn.collapse = function (option) { + return this.each(function () { + var $this = $(this) + , data = $this.data('collapse') + , options = typeof option == 'object' && option + if (!data) $this.data('collapse', (data = new Collapse(this, options))) + if (typeof option == 'string') data[option]() + }) + } + + $.fn.collapse.defaults = { + toggle: true + } + + $.fn.collapse.Constructor = Collapse + + + /* COLLAPSIBLE DATA-API + * ==================== */ + + $(function () { + $('body').on('click.collapse.data-api', '[data-toggle=collapse]', function ( e ) { + var $this = $(this), href + , target = $this.attr('data-target') + || e.preventDefault() + || (href = $this.attr('href')) && href.replace(/.*(?=#[^\s]+$)/, '') //strip for ie7 + , option = $(target).data('collapse') ? 'toggle' : $this.data() + $(target).collapse(option) + }) + }) + +}(window.jQuery); \ No newline at end of file diff --git a/app/models/ability.rb b/app/models/ability.rb index 2607a3b46..7ed503820 100644 --- a/app/models/ability.rb +++ b/app/models/ability.rb @@ -91,7 +91,7 @@ class Ability can [:read, :projects_list], Repository, :platform => {:owner_type => 'Group', :owner_id => user.group_ids} can([:read, :projects_list], 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(:erase, Platform) {|platform| local_admin?(platform) && platform.platform_type == 'personal'} + can(:clear, Platform) {|platform| local_admin?(platform) && platform.platform_type == 'personal'} can([:change_visibility, :settings, :destroy], Repository) {|repository| owner? repository.platform} can :read, Product, :platform => {:visibility => 'open'} @@ -121,7 +121,7 @@ class Ability # Shared cannot rights for all users (registered, admin) cannot :destroy, Platform, :platform_type => 'personal' cannot [:create, :destroy, :add_project, :remove_project], Repository, :platform => {:platform_type => 'personal'} - cannot :erase, Platform, :platform_type => 'main' + cannot :clear, Platform, :platform_type => 'main' cannot :destroy, Issue cannot [:members, :add_member, :remove_member, :remove_members], Platform, :platform_type => 'personal' From 9625e1bb4f68e74dd2bcbf09ad273d323de05fd8 Mon Sep 17 00:00:00 2001 From: Alexander Machehin Date: Mon, 25 Jun 2012 20:31:41 +0600 Subject: [PATCH 42/61] [refs #531] small refactoring --- app/models/user.rb | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/app/models/user.rb b/app/models/user.rb index ddf0fc3f1..7bbd42965 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -132,10 +132,8 @@ class User < ActiveRecord::Base def best_role target roles = target_roles(target) - return 'admin' if roles.include? 'admin' - return 'writer' if roles.include? 'writer' - return 'reader' if roles.include? 'reader' return nil if roles.count == 0 + %w(admin writer reader).each {|role| return role if roles.include?(role)} raise "unknown user #{self.uname} roles #{roles}" end From bdb97b88910a1f06073a40d223be442b73769fd4 Mon Sep 17 00:00:00 2001 From: "konstantin.grabar" Date: Mon, 25 Jun 2012 19:20:35 +0400 Subject: [PATCH 43/61] [refs #442] Add statistics data to mass builds. Small refactor for report --- app/assets/stylesheets/design/custom.scss | 5 +++ .../platforms/platforms/build_all.html.haml | 39 +++++++++++++++---- config/locales/models/build_list.en.yml | 1 + config/locales/models/build_list.ru.yml | 1 + config/locales/models/mass_build.en.yml | 1 + config/locales/models/mass_build.ru.yml | 1 + 6 files changed, 40 insertions(+), 8 deletions(-) diff --git a/app/assets/stylesheets/design/custom.scss b/app/assets/stylesheets/design/custom.scss index 4766fb536..5e9eba6d4 100644 --- a/app/assets/stylesheets/design/custom.scss +++ b/app/assets/stylesheets/design/custom.scss @@ -1080,3 +1080,8 @@ form.mass_build section.left { form.mass_build section.right { margin-right: 50px; } + +.collapse { + overflow: hidden; + padding-top: 10px; +} diff --git a/app/views/platforms/platforms/build_all.html.haml b/app/views/platforms/platforms/build_all.html.haml index f5ed8478a..4f1d4bd6b 100644 --- a/app/views/platforms/platforms/build_all.html.haml +++ b/app/views/platforms/platforms/build_all.html.haml @@ -30,16 +30,39 @@ %tr %th.lpadding16= t('activerecord.attributes.mass_build.id') %th.lpadding16= t('activerecord.attributes.mass_build.name') - %th.lpadding16= t('activerecord.attributes.mass_build.arch_names') - %th.lpadding16= t('activerecord.attributes.mass_build.user') - %th.lpadding16= t('activerecord.attributes.mass_build.auto_publish') - %th.lpadding16= t('activerecord.attributes.mass_build.created_at') + %th.lpadding16= t("layout.build_lists.all").camelize + %th.lpadding16= t("layout.build_lists.statuses.build_published").camelize + %th.lpadding16= t("layout.build_lists.statuses.build_pending").camelize + %th.lpadding16= t("layout.build_lists.statuses.build_started").camelize + %th.lpadding16= t("layout.build_lists.statuses.build_publish").camelize + %th.lpadding16= t("layout.mass_builds.extended_data") - @mass_builds.each do |mass_build| %tr %td= mass_build.id %td= link_to mass_build.name, build_lists_path(:filter => {:mass_build_id => mass_build.id}) - %td= mass_build.arch_names - %td= link_to mass_build.user.fullname, mass_build.user - %td= mass_build.auto_publish - %td= mass_build.created_at + %td= mass_build.build_lists_count + %td= mass_build.build_published_count + %td= mass_build.build_pending_count + %td= mass_build.build_started_count + %td= mass_build.build_publish_count + %td + %a{:href => '#', :'data-toggle' => "collapse", :'data-target' => "#collapse_#{ mass_build.id }"}= t("layout.mass_builds.extended_data") + .in.collapse{:id => "collapse_#{ mass_build.id }"} + = t('activerecord.attributes.mass_build.arch_names') + ": " + = mass_build.arch_names + .both + = t('activerecord.attributes.mass_build.user') + ": " + = link_to mass_build.user.fullname, mass_build.user + .both + = t('activerecord.attributes.mass_build.auto_publish') + ": " + = mass_build.auto_publish + .both + = t('activerecord.attributes.mass_build.created_at') + ": " + = mass_build.created_at + .both = will_paginate @mass_builds + += javascript_include_tag "lib/bootstrap-collapse" + +:javascript + $(".collapse").collapse(); diff --git a/config/locales/models/build_list.en.yml b/config/locales/models/build_list.en.yml index 33c24080e..9b8f0c912 100644 --- a/config/locales/models/build_list.en.yml +++ b/config/locales/models/build_list.en.yml @@ -45,6 +45,7 @@ en: layout: build_lists: + all: All filter_header: Filter current: Curent created_at_start: "Build to start on:" diff --git a/config/locales/models/build_list.ru.yml b/config/locales/models/build_list.ru.yml index 34b2dbdf8..41c4054e8 100644 --- a/config/locales/models/build_list.ru.yml +++ b/config/locales/models/build_list.ru.yml @@ -44,6 +44,7 @@ ru: layout: build_lists: + all: Все filter_header: Фильтр current: Текущие created_at_start: "Время постановки на сборку с:" diff --git a/config/locales/models/mass_build.en.yml b/config/locales/models/mass_build.en.yml index 9d60859d1..cd583015c 100644 --- a/config/locales/models/mass_build.en.yml +++ b/config/locales/models/mass_build.en.yml @@ -2,6 +2,7 @@ en: layout: mass_builds: repositories: Repositories + extended_data: Extended data activerecord: models: mass_build: Mass Build diff --git a/config/locales/models/mass_build.ru.yml b/config/locales/models/mass_build.ru.yml index 2954a4101..4f7e67d31 100644 --- a/config/locales/models/mass_build.ru.yml +++ b/config/locales/models/mass_build.ru.yml @@ -2,6 +2,7 @@ ru: layout: mass_builds: repositories: Репозитории + extended_data: Дополнительные данные activerecord: models: mass_build: Массовая Сборка From e7627b93f64839b9734d8d349a11e1b77b414ed9 Mon Sep 17 00:00:00 2001 From: Alexander Machehin Date: Tue, 26 Jun 2012 21:25:35 +0600 Subject: [PATCH 44/61] [refs #510] fixed resque recipe --- lib/recipes/resque.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/recipes/resque.rb b/lib/recipes/resque.rb index b17ce5da1..7f9242f0d 100644 --- a/lib/recipes/resque.rb +++ b/lib/recipes/resque.rb @@ -20,8 +20,8 @@ Capistrano::Configuration.instance(:must_exist).load do end def stop_workers - run "kill -QUIT `ps aux | grep resque | grep -v grep | awk '{ print $2 }'`" - # run "kill -QUIT `ps aux | grep resque | grep -v grep | awk '{ print $2 }'` > /dev/null 2>&1 &" + ps = 'ps aux | grep resque | grep -v grep' + run "#{ps} || echo 'Workers already stopped!' || kill -QUIT `#{ps} | awk '{ print $2 }'`" end def start_workers From 62556478dc3e3630b5f9535c7a86f8d20cdbccda Mon Sep 17 00:00:00 2001 From: Alexander Machehin Date: Wed, 27 Jun 2012 11:46:18 +0600 Subject: [PATCH 45/61] [refs #510] fixed recipe --- lib/recipes/resque.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/recipes/resque.rb b/lib/recipes/resque.rb index 7f9242f0d..a3524324d 100644 --- a/lib/recipes/resque.rb +++ b/lib/recipes/resque.rb @@ -21,7 +21,7 @@ Capistrano::Configuration.instance(:must_exist).load do def stop_workers ps = 'ps aux | grep resque | grep -v grep' - run "#{ps} || echo 'Workers already stopped!' || kill -QUIT `#{ps} | awk '{ print $2 }'`" + run "#{ps} && kill -QUIT `#{ps} | awk '{ print $2 }'` || echo 'Workers already stopped!'" end def start_workers From fc00f713b520892d070270e27a80a514729bdeb3 Mon Sep 17 00:00:00 2001 From: "konstantin.grabar" Date: Wed, 27 Jun 2012 13:48:54 +0400 Subject: [PATCH 46/61] [refs #442] Add counters update checking. Add build_error counter --- app/models/build_list.rb | 4 ++-- app/models/mass_build.rb | 9 +++++++++ app/views/platforms/platforms/build_all.html.haml | 2 ++ config/locales/models/mass_build.ru.yml | 2 +- db/migrate/20120622092725_add_counters_to_mass_builds.rb | 1 + 5 files changed, 15 insertions(+), 3 deletions(-) diff --git a/app/models/build_list.rb b/app/models/build_list.rb index 8d323cdf6..d3f4f487e 100644 --- a/app/models/build_list.rb +++ b/app/models/build_list.rb @@ -105,9 +105,9 @@ class BuildList < ActiveRecord::Base around_transition do |build_list, transition, block| if build_list.mass_build - MassBuild.decrement_counter "#{BuildList::HUMAN_STATUSES[build_list.status].to_s}_count", build_list.mass_build_id + MassBuild.decrement_counter "#{BuildList::HUMAN_STATUSES[build_list.status].to_s}_count", build_list.mass_build_id if MassBuild::COUNT_STATUSES.include?(build_list.status) block.call - MassBuild.increment_counter "#{BuildList::HUMAN_STATUSES[build_list.status].to_s}_count", build_list.mass_build_id + MassBuild.increment_counter "#{BuildList::HUMAN_STATUSES[build_list.status].to_s}_count", build_list.mass_build_id if MassBuild::COUNT_STATUSES.include?(build_list.status) end end diff --git a/app/models/mass_build.rb b/app/models/mass_build.rb index 37e950bb0..3c13d754a 100644 --- a/app/models/mass_build.rb +++ b/app/models/mass_build.rb @@ -12,6 +12,15 @@ class MassBuild < ActiveRecord::Base after_create :build_all + COUNT_STATUSES = [ + :build_lists, + :build_published, + :build_pending, + :build_started, + :build_publish, + :build_error + ] + def initialize(args = nil) super diff --git a/app/views/platforms/platforms/build_all.html.haml b/app/views/platforms/platforms/build_all.html.haml index 4f1d4bd6b..237de5dd5 100644 --- a/app/views/platforms/platforms/build_all.html.haml +++ b/app/views/platforms/platforms/build_all.html.haml @@ -35,6 +35,7 @@ %th.lpadding16= t("layout.build_lists.statuses.build_pending").camelize %th.lpadding16= t("layout.build_lists.statuses.build_started").camelize %th.lpadding16= t("layout.build_lists.statuses.build_publish").camelize + %th.lpadding16= t("layout.build_lists.statuses.build_error").camelize %th.lpadding16= t("layout.mass_builds.extended_data") - @mass_builds.each do |mass_build| %tr @@ -45,6 +46,7 @@ %td= mass_build.build_pending_count %td= mass_build.build_started_count %td= mass_build.build_publish_count + %td= mass_build.build_error_count %td %a{:href => '#', :'data-toggle' => "collapse", :'data-target' => "#collapse_#{ mass_build.id }"}= t("layout.mass_builds.extended_data") .in.collapse{:id => "collapse_#{ mass_build.id }"} diff --git a/config/locales/models/mass_build.ru.yml b/config/locales/models/mass_build.ru.yml index 4f7e67d31..a8c09b6dd 100644 --- a/config/locales/models/mass_build.ru.yml +++ b/config/locales/models/mass_build.ru.yml @@ -2,7 +2,7 @@ ru: layout: mass_builds: repositories: Репозитории - extended_data: Дополнительные данные + extended_data: Параметры задания activerecord: models: mass_build: Массовая Сборка diff --git a/db/migrate/20120622092725_add_counters_to_mass_builds.rb b/db/migrate/20120622092725_add_counters_to_mass_builds.rb index a35cd61d2..5b0ed2e73 100644 --- a/db/migrate/20120622092725_add_counters_to_mass_builds.rb +++ b/db/migrate/20120622092725_add_counters_to_mass_builds.rb @@ -5,5 +5,6 @@ class AddCountersToMassBuilds < ActiveRecord::Migration add_column :mass_builds, :build_pending_count, :integer, :default => 0 add_column :mass_builds, :build_started_count, :integer, :default => 0 add_column :mass_builds, :build_publish_count, :integer, :default => 0 + add_column :mass_builds, :build_error_count, :integer, :default => 0 end end From 1ac1e428941b75ccdafbc0521965540c8ab1f7ca Mon Sep 17 00:00:00 2001 From: Alexander Machehin Date: Wed, 27 Jun 2012 15:59:58 +0600 Subject: [PATCH 47/61] small fix to Russian translation --- config/locales/models/relation.ru.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/locales/models/relation.ru.yml b/config/locales/models/relation.ru.yml index 884c03692..51202e88e 100644 --- a/config/locales/models/relation.ru.yml +++ b/config/locales/models/relation.ru.yml @@ -3,5 +3,5 @@ ru: relations: user_owner: Я - владелец group_owner: Я состою в группе-владельце - user: Я участник + user: Я - участник group: Я состою в группе-участнике From b6d769ad66afcbd7872dfff20812f9870ebfd953 Mon Sep 17 00:00:00 2001 From: "konstantin.grabar" Date: Wed, 27 Jun 2012 18:06:59 +0400 Subject: [PATCH 48/61] [refs #442] Change mass builds table --- app/assets/stylesheets/design/custom.scss | 4 +++ .../platforms/platforms_controller.rb | 4 +-- .../platforms/platforms/build_all.html.haml | 36 ++++++++++++------- config/locales/models/mass_build.en.yml | 2 ++ config/locales/models/mass_build.ru.yml | 2 ++ config/routes.rb | 3 ++ db/schema.rb | 1 + 7 files changed, 37 insertions(+), 15 deletions(-) diff --git a/app/assets/stylesheets/design/custom.scss b/app/assets/stylesheets/design/custom.scss index 5e9eba6d4..29b395cf3 100644 --- a/app/assets/stylesheets/design/custom.scss +++ b/app/assets/stylesheets/design/custom.scss @@ -1085,3 +1085,7 @@ form.mass_build section.right { overflow: hidden; padding-top: 10px; } + +.min_width_120 { + min-width: 120px; +} diff --git a/app/controllers/platforms/platforms_controller.rb b/app/controllers/platforms/platforms_controller.rb index 2e4d3d329..e76800647 100644 --- a/app/controllers/platforms/platforms_controller.rb +++ b/app/controllers/platforms/platforms_controller.rb @@ -31,9 +31,9 @@ class Platforms::PlatformsController < Platforms::BaseController render :action => :build_all end - def get_failed_builds_list + def failed_builds_list @mass_build = MassBuild.find params[:mass_build_id] - send_file @mass_build.generate_failed_builds_list, :filename => "mass_build_#{@mass_build.id}" + render :text => @mass_build.generate_failed_builds_list end def index diff --git a/app/views/platforms/platforms/build_all.html.haml b/app/views/platforms/platforms/build_all.html.haml index 237de5dd5..d29d95dd1 100644 --- a/app/views/platforms/platforms/build_all.html.haml +++ b/app/views/platforms/platforms/build_all.html.haml @@ -30,25 +30,35 @@ %tr %th.lpadding16= t('activerecord.attributes.mass_build.id') %th.lpadding16= t('activerecord.attributes.mass_build.name') - %th.lpadding16= t("layout.build_lists.all").camelize - %th.lpadding16= t("layout.build_lists.statuses.build_published").camelize - %th.lpadding16= t("layout.build_lists.statuses.build_pending").camelize - %th.lpadding16= t("layout.build_lists.statuses.build_started").camelize - %th.lpadding16= t("layout.build_lists.statuses.build_publish").camelize - %th.lpadding16= t("layout.build_lists.statuses.build_error").camelize + %th.lpadding16= t("layout.mass_builds.statuses") + %th.lpadding16= t("layout.mass_builds.failed_builds_list") %th.lpadding16= t("layout.mass_builds.extended_data") - @mass_builds.each do |mass_build| %tr %td= mass_build.id %td= link_to mass_build.name, build_lists_path(:filter => {:mass_build_id => mass_build.id}) - %td= mass_build.build_lists_count - %td= mass_build.build_published_count - %td= mass_build.build_pending_count - %td= mass_build.build_started_count - %td= mass_build.build_publish_count - %td= mass_build.build_error_count + %td.min_width_120 + = t("layout.build_lists.all") + ": " + = mass_build.build_lists_count + .both + = t("layout.build_lists.statuses.build_published") + ": " + = mass_build.build_published_count + .both + = t("layout.build_lists.statuses.build_pending") + ": " + = mass_build.build_pending_count + .both + = t("layout.build_lists.statuses.build_started") + ": " + = mass_build.build_started_count + .both + = t("layout.build_lists.statuses.build_publish") + ": " + = mass_build.build_publish_count + .both + = t("layout.build_lists.statuses.build_error") + ": " + = mass_build.build_error_count + .both + %td= link_to t("layout.mass_builds.failed_builds_list"), failed_builds_list_platforms_path(:mass_build_id => mass_build.id), :target => "_blank" %td - %a{:href => '#', :'data-toggle' => "collapse", :'data-target' => "#collapse_#{ mass_build.id }"}= t("layout.mass_builds.extended_data") + %a{:href => "collapse_#{ mass_build.id }", :'data-toggle' => "collapse", :'data-target' => "#collapse_#{ mass_build.id }"}= t("layout.mass_builds.extended_data") .in.collapse{:id => "collapse_#{ mass_build.id }"} = t('activerecord.attributes.mass_build.arch_names') + ": " = mass_build.arch_names diff --git a/config/locales/models/mass_build.en.yml b/config/locales/models/mass_build.en.yml index cd583015c..508bc8507 100644 --- a/config/locales/models/mass_build.en.yml +++ b/config/locales/models/mass_build.en.yml @@ -3,6 +3,8 @@ en: mass_builds: repositories: Repositories extended_data: Extended data + failed_builds_list: Failed Builds List + statuses: Statuses activerecord: models: mass_build: Mass Build diff --git a/config/locales/models/mass_build.ru.yml b/config/locales/models/mass_build.ru.yml index a8c09b6dd..b5d0fee6f 100644 --- a/config/locales/models/mass_build.ru.yml +++ b/config/locales/models/mass_build.ru.yml @@ -3,6 +3,8 @@ ru: mass_builds: repositories: Репозитории extended_data: Параметры задания + failed_builds_list: Список ошибок сборок + statuses: Статусы activerecord: models: mass_build: Массовая Сборка diff --git a/config/routes.rb b/config/routes.rb index e8297ffc5..f6fec3ff7 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -55,6 +55,9 @@ Rosa::Application.routes.draw do get :mass_builds get :advisories end + collection do + get :failed_builds_list + end get :autocomplete_user_uname, :on => :collection resources :repositories do member do diff --git a/db/schema.rb b/db/schema.rb index ca0d5df26..06ac06651 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -209,6 +209,7 @@ ActiveRecord::Schema.define(:version => 20120622092725) do t.integer "build_pending_count", :default => 0 t.integer "build_started_count", :default => 0 t.integer "build_publish_count", :default => 0 + t.integer "build_error_count", :default => 0 end create_table "platforms", :force => true do |t| From 126f58ac8567121cb195142e23ed4fe88c5c53a4 Mon Sep 17 00:00:00 2001 From: Vladimir Sharshov Date: Wed, 27 Jun 2012 18:57:30 +0400 Subject: [PATCH 49/61] Fix publication for old version of build client --- app/models/build_list.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/models/build_list.rb b/app/models/build_list.rb index b46bd1eba..378aea363 100644 --- a/app/models/build_list.rb +++ b/app/models/build_list.rb @@ -172,6 +172,8 @@ class BuildList < ActiveRecord::Base def set_version_and_tag pkg = self.packages.where(:package_type => 'source', :project_id => self.project_id).first + # TODO: remove 'return' after deployment ABF kernel 2.0 + return if pkg.nil? # For old client that does not sends data about packages self.package_version = "#{pkg.platform.name}-#{pkg.version}-#{pkg.release}" system("cd #{self.project.git_repository.path} && git tag #{self.package_version} #{self.commit_hash}") # TODO REDO through grit save From 4187ef8873c611f66bd8b04a0640a960c781e913 Mon Sep 17 00:00:00 2001 From: "konstantin.grabar" Date: Wed, 27 Jun 2012 19:32:29 +0400 Subject: [PATCH 50/61] [refs #442] Add links for statuses --- app/views/platforms/platforms/build_all.html.haml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/app/views/platforms/platforms/build_all.html.haml b/app/views/platforms/platforms/build_all.html.haml index d29d95dd1..d486ac526 100644 --- a/app/views/platforms/platforms/build_all.html.haml +++ b/app/views/platforms/platforms/build_all.html.haml @@ -38,22 +38,22 @@ %td= mass_build.id %td= link_to mass_build.name, build_lists_path(:filter => {:mass_build_id => mass_build.id}) %td.min_width_120 - = t("layout.build_lists.all") + ": " + = link_to t("layout.build_lists.all") + ": ", build_lists_path = mass_build.build_lists_count .both - = t("layout.build_lists.statuses.build_published") + ": " + = link_to t("layout.build_lists.statuses.build_published") + ": ", build_lists_path(:filter => {:status => BuildList::BUILD_PUBLISHED, :mass_build_id => mass_build.id}) = mass_build.build_published_count .both - = t("layout.build_lists.statuses.build_pending") + ": " + = link_to t("layout.build_lists.statuses.build_pending") + ": ", build_lists_path(:filter => {:status => BuildList::BUILD_PENDING, :mass_build_id => mass_build.id}) = mass_build.build_pending_count .both - = t("layout.build_lists.statuses.build_started") + ": " + = link_to t("layout.build_lists.statuses.build_started") + ": ", build_lists_path(:filter => {:status => BuildServer::BUILD_STARTED, :mass_build_id => mass_build.id}) = mass_build.build_started_count .both - = t("layout.build_lists.statuses.build_publish") + ": " + = link_to t("layout.build_lists.statuses.build_publish") + ": ", build_lists_path(:filter => {:status => BuildList::BUILD_PUBLISH, :mass_build_id => mass_build.id}) = mass_build.build_publish_count .both - = t("layout.build_lists.statuses.build_error") + ": " + = link_to t("layout.build_lists.statuses.build_error") + ": ", build_lists_path(:filter => {:status => BuildServer::BUILD_ERROR, :mass_build_id => mass_build.id}) = mass_build.build_error_count .both %td= link_to t("layout.mass_builds.failed_builds_list"), failed_builds_list_platforms_path(:mass_build_id => mass_build.id), :target => "_blank" From 10aed58bdd847c9fbc861105f8bacba3ebe951eb Mon Sep 17 00:00:00 2001 From: "konstantin.grabar" Date: Thu, 28 Jun 2012 15:31:25 +0400 Subject: [PATCH 51/61] [refs #442] Small refactor. Remove bootstrap collapse --- app/assets/javascripts/application.js | 10 ++ .../javascripts/lib/bootstrap-collapse.js | 157 ------------------ app/assets/stylesheets/design/custom.scss | 4 +- .../platforms/platforms_controller.rb | 2 +- .../platforms/platforms/build_all.html.haml | 32 +--- config/locales/models/build_list.en.yml | 2 +- config/locales/models/build_list.ru.yml | 2 +- 7 files changed, 22 insertions(+), 187 deletions(-) delete mode 100644 app/assets/javascripts/lib/bootstrap-collapse.js diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js index 9d8340566..50a2a47c5 100644 --- a/app/assets/javascripts/application.js +++ b/app/assets/javascripts/application.js @@ -71,4 +71,14 @@ $(document).ready(function() { } }); + $(".toggle_btn").click(function() { + var target = $( $(this).attr('data-target') ); + //target.toggle(); + if ( target.css('visibility') == 'hidden' ) { + target.css('visibility', 'visible'); + } else { + target.css('visibility', 'hidden'); + } + return false; + }); }); diff --git a/app/assets/javascripts/lib/bootstrap-collapse.js b/app/assets/javascripts/lib/bootstrap-collapse.js deleted file mode 100644 index fbc915b9f..000000000 --- a/app/assets/javascripts/lib/bootstrap-collapse.js +++ /dev/null @@ -1,157 +0,0 @@ -/* ============================================================= - * bootstrap-collapse.js v2.0.4 - * http://twitter.github.com/bootstrap/javascript.html#collapse - * ============================================================= - * Copyright 2012 Twitter, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============================================================ */ - - -!function ($) { - - "use strict"; // jshint ;_; - - - /* COLLAPSE PUBLIC CLASS DEFINITION - * ================================ */ - - var Collapse = function (element, options) { - this.$element = $(element) - this.options = $.extend({}, $.fn.collapse.defaults, options) - - if (this.options.parent) { - this.$parent = $(this.options.parent) - } - - this.options.toggle && this.toggle() - } - - Collapse.prototype = { - - constructor: Collapse - - , dimension: function () { - var hasWidth = this.$element.hasClass('width') - return hasWidth ? 'width' : 'height' - } - - , show: function () { - var dimension - , scroll - , actives - , hasData - - if (this.transitioning) return - - dimension = this.dimension() - scroll = $.camelCase(['scroll', dimension].join('-')) - actives = this.$parent && this.$parent.find('> .accordion-group > .in') - - if (actives && actives.length) { - hasData = actives.data('collapse') - if (hasData && hasData.transitioning) return - actives.collapse('hide') - hasData || actives.data('collapse', null) - } - - this.$element[dimension](0) - this.transition('addClass', $.Event('show'), 'shown') - this.$element[dimension](this.$element[0][scroll]) - } - - , hide: function () { - var dimension - if (this.transitioning) return - dimension = this.dimension() - this.reset(this.$element[dimension]()) - this.transition('removeClass', $.Event('hide'), 'hidden') - this.$element[dimension](0) - } - - , reset: function (size) { - var dimension = this.dimension() - - this.$element - .removeClass('collapse') - [dimension](size || 'auto') - [0].offsetWidth - - this.$element[size !== null ? 'addClass' : 'removeClass']('collapse') - - return this - } - - , transition: function (method, startEvent, completeEvent) { - var that = this - , complete = function () { - if (startEvent.type == 'show') that.reset() - that.transitioning = 0 - that.$element.trigger(completeEvent) - } - - this.$element.trigger(startEvent) - - if (startEvent.isDefaultPrevented()) return - - this.transitioning = 1 - - this.$element[method]('in') - - $.support.transition && this.$element.hasClass('collapse') ? - this.$element.one($.support.transition.end, complete) : - complete() - } - - , toggle: function () { - this[this.$element.hasClass('in') ? 'hide' : 'show']() - } - - } - - - /* COLLAPSIBLE PLUGIN DEFINITION - * ============================== */ - - $.fn.collapse = function (option) { - return this.each(function () { - var $this = $(this) - , data = $this.data('collapse') - , options = typeof option == 'object' && option - if (!data) $this.data('collapse', (data = new Collapse(this, options))) - if (typeof option == 'string') data[option]() - }) - } - - $.fn.collapse.defaults = { - toggle: true - } - - $.fn.collapse.Constructor = Collapse - - - /* COLLAPSIBLE DATA-API - * ==================== */ - - $(function () { - $('body').on('click.collapse.data-api', '[data-toggle=collapse]', function ( e ) { - var $this = $(this), href - , target = $this.attr('data-target') - || e.preventDefault() - || (href = $this.attr('href')) && href.replace(/.*(?=#[^\s]+$)/, '') //strip for ie7 - , option = $(target).data('collapse') ? 'toggle' : $this.data() - $(target).collapse(option) - }) - }) - -}(window.jQuery); \ No newline at end of file diff --git a/app/assets/stylesheets/design/custom.scss b/app/assets/stylesheets/design/custom.scss index 29b395cf3..d88c62891 100644 --- a/app/assets/stylesheets/design/custom.scss +++ b/app/assets/stylesheets/design/custom.scss @@ -1081,9 +1081,11 @@ form.mass_build section.right { margin-right: 50px; } -.collapse { +.toggle { overflow: hidden; padding-top: 10px; + display: block; + visibility: hidden; } .min_width_120 { diff --git a/app/controllers/platforms/platforms_controller.rb b/app/controllers/platforms/platforms_controller.rb index e76800647..14058ba36 100644 --- a/app/controllers/platforms/platforms_controller.rb +++ b/app/controllers/platforms/platforms_controller.rb @@ -18,7 +18,7 @@ class Platforms::PlatformsController < Platforms::BaseController if mass_build.save redirect_to(mass_builds_platform_path(@platform), :notice => t("flash.platform.build_all_success")) else - @auto_publish_selected = params[:auto_publish].present? ? params[:auto_publish].present? : false + @auto_publish_selected = params[:auto_publish].present? @mass_builds = MassBuild.by_platform(@platform).order('created_at DESC').paginate(:page => params[:page], :per_page => 20) flash[:warning] = mass_build.errors.full_messages.join('. ') flash[:error] = t("flash.platform.build_all_error") diff --git a/app/views/platforms/platforms/build_all.html.haml b/app/views/platforms/platforms/build_all.html.haml index d486ac526..67b275ac9 100644 --- a/app/views/platforms/platforms/build_all.html.haml +++ b/app/views/platforms/platforms/build_all.html.haml @@ -38,28 +38,14 @@ %td= mass_build.id %td= link_to mass_build.name, build_lists_path(:filter => {:mass_build_id => mass_build.id}) %td.min_width_120 - = link_to t("layout.build_lists.all") + ": ", build_lists_path - = mass_build.build_lists_count - .both - = link_to t("layout.build_lists.statuses.build_published") + ": ", build_lists_path(:filter => {:status => BuildList::BUILD_PUBLISHED, :mass_build_id => mass_build.id}) - = mass_build.build_published_count - .both - = link_to t("layout.build_lists.statuses.build_pending") + ": ", build_lists_path(:filter => {:status => BuildList::BUILD_PENDING, :mass_build_id => mass_build.id}) - = mass_build.build_pending_count - .both - = link_to t("layout.build_lists.statuses.build_started") + ": ", build_lists_path(:filter => {:status => BuildServer::BUILD_STARTED, :mass_build_id => mass_build.id}) - = mass_build.build_started_count - .both - = link_to t("layout.build_lists.statuses.build_publish") + ": ", build_lists_path(:filter => {:status => BuildList::BUILD_PUBLISH, :mass_build_id => mass_build.id}) - = mass_build.build_publish_count - .both - = link_to t("layout.build_lists.statuses.build_error") + ": ", build_lists_path(:filter => {:status => BuildServer::BUILD_ERROR, :mass_build_id => mass_build.id}) - = mass_build.build_error_count - .both + - MassBuild::COUNT_STATUSES.each do |status| + = link_to t("layout.build_lists.statuses.#{status}") + ": ", build_lists_path(:filter => {:status => status, :mass_build_id => mass_build.id}) + = mass_build.read_attribute "#{status}_count" + .both %td= link_to t("layout.mass_builds.failed_builds_list"), failed_builds_list_platforms_path(:mass_build_id => mass_build.id), :target => "_blank" %td - %a{:href => "collapse_#{ mass_build.id }", :'data-toggle' => "collapse", :'data-target' => "#collapse_#{ mass_build.id }"}= t("layout.mass_builds.extended_data") - .in.collapse{:id => "collapse_#{ mass_build.id }"} + %a.toggle_btn{:href => "#toggle_#{ mass_build.id }", :'data-target' => "#toggle_#{ mass_build.id }"}= t("layout.mass_builds.extended_data") + .toggle{:id => "toggle_#{ mass_build.id }"} = t('activerecord.attributes.mass_build.arch_names') + ": " = mass_build.arch_names .both @@ -71,10 +57,4 @@ .both = t('activerecord.attributes.mass_build.created_at') + ": " = mass_build.created_at - .both = will_paginate @mass_builds - -= javascript_include_tag "lib/bootstrap-collapse" - -:javascript - $(".collapse").collapse(); diff --git a/config/locales/models/build_list.en.yml b/config/locales/models/build_list.en.yml index 9b8f0c912..139ae436b 100644 --- a/config/locales/models/build_list.en.yml +++ b/config/locales/models/build_list.en.yml @@ -45,7 +45,6 @@ en: layout: build_lists: - all: All filter_header: Filter current: Curent created_at_start: "Build to start on:" @@ -98,6 +97,7 @@ en: git_error: Git error statuses: + build_lists: All build_error: Build error build_published: Build has been published rejected_publish: Publishing rejected diff --git a/config/locales/models/build_list.ru.yml b/config/locales/models/build_list.ru.yml index 41c4054e8..910292188 100644 --- a/config/locales/models/build_list.ru.yml +++ b/config/locales/models/build_list.ru.yml @@ -44,7 +44,6 @@ ru: layout: build_lists: - all: Все filter_header: Фильтр current: Текущие created_at_start: "Время постановки на сборку с:" @@ -97,6 +96,7 @@ ru: git_error: проблема с гит statuses: + build_lists: Всего build_error: ошибка сборки build_published: опубликован rejected_publish: публикация отклонена From 46161253ab46644db05ab1d1016092ad9dac176e Mon Sep 17 00:00:00 2001 From: Vladimir Sharshov Date: Thu, 28 Jun 2012 19:54:58 +0400 Subject: [PATCH 52/61] [refs #462] Product status does not change --- app/controllers/platforms/product_build_lists_controller.rb | 3 ++- config/routes.rb | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/app/controllers/platforms/product_build_lists_controller.rb b/app/controllers/platforms/product_build_lists_controller.rb index daab1ef25..e749c4865 100644 --- a/app/controllers/platforms/product_build_lists_controller.rb +++ b/app/controllers/platforms/product_build_lists_controller.rb @@ -46,7 +46,8 @@ class Platforms::ProductBuildListsController < Platforms::BaseController end def authenticate_product_builder! - unless APP_CONFIG['product_builder_ip'].values.include?(request.remote_ip) + # FIXME: Rails(?) interpret the internal IP as 127.0.0.1 + unless (APP_CONFIG['product_builder_ip'].values + ["127.0.0.1"]).include?(request.remote_ip) render :nothing => true, :status => 403 end end diff --git a/config/routes.rb b/config/routes.rb index f6fec3ff7..16ba0f84f 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -74,6 +74,7 @@ Rosa::Application.routes.draw do match '/private/:platform_name/*file_path' => 'privates#show' resources :product_build_lists, :only => [:index] + match 'product_status', :to => 'product_build_lists#status_build' end scope :module => 'users' do @@ -117,7 +118,6 @@ Rosa::Application.routes.draw do match 'build_lists/pre_build', :to => "build_lists#pre_build" match 'build_lists/circle_build', :to => "build_lists#circle_build" match 'build_lists/new_bbdt', :to => "build_lists#new_bbdt" - match 'product_status', :to => 'product_build_lists#status_build' resources :build_lists, :only => [:index, :show, :update] do member do From 7561abca081a92f94518a4b784a7ef4004cfe70e Mon Sep 17 00:00:00 2001 From: Vladimir Sharshov Date: Thu, 28 Jun 2012 21:40:32 +0400 Subject: [PATCH 53/61] [refs #462] refactoring: remove notified_at --- .../product_build_lists_controller.rb | 3 +- app/models/product_build_list.rb | 4 +-- .../_product_build_list.html.haml | 3 +- .../product_build_lists/index.html.haml | 1 - .../locales/models/product_build_list.en.yml | 2 +- ...120628165702_remove_product_notified_at.rb | 9 ++++++ db/schema.rb | 28 +++++++++---------- spec/models/product_build_list_spec.rb | 1 - 8 files changed, 28 insertions(+), 23 deletions(-) create mode 100644 db/migrate/20120628165702_remove_product_notified_at.rb diff --git a/app/controllers/platforms/product_build_lists_controller.rb b/app/controllers/platforms/product_build_lists_controller.rb index e749c4865..9531cd68c 100644 --- a/app/controllers/platforms/product_build_lists_controller.rb +++ b/app/controllers/platforms/product_build_lists_controller.rb @@ -11,14 +11,13 @@ class Platforms::ProductBuildListsController < Platforms::BaseController before_filter :find_product_build_list, :only => [:status_build] def create - @product.product_build_lists.create! :base_url => "http://#{request.host_with_port}", :notified_at => Time.current + @product.product_build_lists.create! :base_url => "http://#{request.host_with_port}" flash[:notice] = t('flash.product.build_started') redirect_to [@platform, @product] end def status_build @product_build_list.status = params[:status].to_i # ProductBuildList::BUILD_COMPLETED : ProductBuildList::BUILD_FAILED) - @product_build_list.notified_at = Time.current @product_build_list.save! render :nothing => true end diff --git a/app/models/product_build_list.rb b/app/models/product_build_list.rb index eb7569b61..774f1d0ca 100644 --- a/app/models/product_build_list.rb +++ b/app/models/product_build_list.rb @@ -20,11 +20,11 @@ class ProductBuildList < ActiveRecord::Base validates :status, :inclusion => { :in => [BUILD_STARTED, BUILD_COMPLETED, BUILD_FAILED] } attr_accessor :base_url - attr_accessible :status, :notified_at, :base_url + attr_accessible :status, :base_url attr_readonly :product_id - scope :default_order, order('notified_at DESC') + scope :default_order, order('updated_at DESC') scope :for_status, lambda {|status| where(:status => status) } scope :for_user, lambda { |user| where(:user_id => user.id) } scope :scoped_to_product_name, lambda {|product_name| joins(:product).where('products.name LIKE ?', "%#{product_name}%")} diff --git a/app/views/platforms/product_build_lists/_product_build_list.html.haml b/app/views/platforms/product_build_lists/_product_build_list.html.haml index ac8dcf130..47cd0d8a5 100644 --- a/app/views/platforms/product_build_lists/_product_build_list.html.haml +++ b/app/views/platforms/product_build_lists/_product_build_list.html.haml @@ -3,6 +3,5 @@ %td= product_build_list.human_status %td= link_to nil, product_build_list.container_path %td= link_to product_build_list.product.name, platform_product_path(product_build_list.product.platform, product_build_list.product) - -#%td= link_to product_build_list.user.try(:fullname), product_build_list.user %td= link_to image_tag('x.png'), platform_product_product_build_list_path(product_build_list.product.platform, product_build_list.product, product_build_list), :method => :delete, :confirm => t("layout.confirm") if can? :destroy, product_build_list - %td= l(product_build_list.notified_at, :format => :long) + %td= l(product_build_list.updated_at, :format => :long) \ No newline at end of file diff --git a/app/views/platforms/product_build_lists/index.html.haml b/app/views/platforms/product_build_lists/index.html.haml index 7103bcfe9..494484f71 100644 --- a/app/views/platforms/product_build_lists/index.html.haml +++ b/app/views/platforms/product_build_lists/index.html.haml @@ -6,7 +6,6 @@ %th.lpadding16= t("activerecord.attributes.product_build_list.status") %th.lpadding16= t("activerecord.attributes.product_build_list.container_path") %th.lpadding16= t("activerecord.attributes.product_build_list.product") - -#%th.lpadding16= t("activerecord.attributes.product_build_list.user") %th= t("layout.product_build_lists.action") %th.lpadding16= t("activerecord.attributes.product_build_list.notified_at") %tbody= render :partial => 'platforms/product_build_lists/product_build_list', :collection => @product_build_lists diff --git a/config/locales/models/product_build_list.en.yml b/config/locales/models/product_build_list.en.yml index 1e047e4aa..6f6892274 100644 --- a/config/locales/models/product_build_list.en.yml +++ b/config/locales/models/product_build_list.en.yml @@ -10,7 +10,7 @@ en: '2': 'build in progress' build_failed: Build failed build_started: Build in progress - build_completed: Build + build_completed: Builded ownership: header: Build list ownership diff --git a/db/migrate/20120628165702_remove_product_notified_at.rb b/db/migrate/20120628165702_remove_product_notified_at.rb new file mode 100644 index 000000000..fe8ec3436 --- /dev/null +++ b/db/migrate/20120628165702_remove_product_notified_at.rb @@ -0,0 +1,9 @@ +class RemoveProductNotifiedAt < ActiveRecord::Migration + def up + remove_column :product_build_lists, :notified_at + end + + def down + add_column :product_build_lists, :notified_at, :datetime + end +end diff --git a/db/schema.rb b/db/schema.rb index 06ac06651..4eb6a8e93 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,14 +11,14 @@ # # It's strongly recommended to check this file into your version control system. -ActiveRecord::Schema.define(:version => 20120622092725) do +ActiveRecord::Schema.define(:version => 20120628165702) do create_table "activity_feeds", :force => true do |t| t.integer "user_id", :null => false t.string "kind" t.text "data" - t.datetime "created_at" - t.datetime "updated_at" + t.datetime "created_at", :null => false + t.datetime "updated_at", :null => false end create_table "advisories", :force => true do |t| @@ -223,7 +223,7 @@ ActiveRecord::Schema.define(:version => 20120622092725) do t.string "owner_type" t.string "visibility", :default => "open", :null => false t.string "platform_type", :default => "main", :null => false - t.string "distrib_type" + t.string "distrib_type", :null => false end add_index "platforms", ["name"], :name => "index_platforms_on_name", :unique => true, :case_sensitive => false @@ -239,8 +239,7 @@ ActiveRecord::Schema.define(:version => 20120622092725) do create_table "product_build_lists", :force => true do |t| t.integer "product_id" - t.integer "status", :default => 2, :null => false - t.datetime "notified_at" + t.integer "status", :default => 2, :null => false t.datetime "created_at" t.datetime "updated_at" end @@ -294,25 +293,27 @@ ActiveRecord::Schema.define(:version => 20120622092725) do t.text "description" t.string "ancestry" t.boolean "has_issues", :default => true - t.boolean "has_wiki", :default => false t.string "srpm_file_name" t.string "srpm_content_type" t.integer "srpm_file_size" t.datetime "srpm_updated_at" + t.boolean "has_wiki", :default => false t.string "default_branch", :default => "master" t.boolean "is_package", :default => true, :null => false t.integer "average_build_time", :default => 0, :null => false t.integer "build_count", :default => 0, :null => false end + add_index "projects", ["owner_id"], :name => "index_projects_on_name_and_owner_id_and_owner_type", :unique => true + create_table "register_requests", :force => true do |t| t.string "name" t.string "email" t.string "token" t.boolean "approved", :default => false t.boolean "rejected", :default => false - t.datetime "created_at", :null => false - t.datetime "updated_at", :null => false + t.datetime "created_at" + t.datetime "updated_at" t.string "interest" t.text "more" end @@ -366,7 +367,6 @@ ActiveRecord::Schema.define(:version => 20120622092725) do t.string "name" t.string "email", :default => "", :null => false t.string "encrypted_password", :limit => 128, :default => "", :null => false - t.string "password_salt", :default => "", :null => false t.string "reset_password_token" t.datetime "remember_created_at" t.datetime "created_at" @@ -374,11 +374,8 @@ ActiveRecord::Schema.define(:version => 20120622092725) do t.string "uname" t.string "role" t.string "language", :default => "en" - t.string "confirmation_token" - t.datetime "confirmed_at" - t.datetime "confirmation_sent_at" - t.integer "own_projects_count", :default => 0, :null => false t.datetime "reset_password_sent_at" + t.integer "own_projects_count", :default => 0, :null => false t.text "professional_experience" t.string "site" t.string "company" @@ -390,6 +387,9 @@ ActiveRecord::Schema.define(:version => 20120622092725) do t.integer "failed_attempts", :default => 0 t.string "unlock_token" t.datetime "locked_at" + t.string "confirmation_token" + t.datetime "confirmed_at" + t.datetime "confirmation_sent_at" t.string "authentication_token" t.integer "build_priority", :default => 50 end diff --git a/spec/models/product_build_list_spec.rb b/spec/models/product_build_list_spec.rb index 76587112f..3f0bbba51 100644 --- a/spec/models/product_build_list_spec.rb +++ b/spec/models/product_build_list_spec.rb @@ -21,7 +21,6 @@ describe ProductBuildList do it { should_not allow_mass_assignment_of(:product_id) } it { should allow_mass_assignment_of(:status) } - it { should allow_mass_assignment_of(:notified_at) } it { should allow_mass_assignment_of(:base_url) } end From 67c55bcb56e3000b03f6c878257c1797d2eb2665 Mon Sep 17 00:00:00 2001 From: Alexander Machehin Date: Fri, 29 Jun 2012 17:01:40 +0600 Subject: [PATCH 54/61] [refs #442] fixed infinite loop --- app/models/build_list.rb | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/app/models/build_list.rb b/app/models/build_list.rb index 8c2894046..0ae3e86af 100644 --- a/app/models/build_list.rb +++ b/app/models/build_list.rb @@ -103,10 +103,15 @@ class BuildList < ActiveRecord::Base state_machine :status, :initial => :waiting_for_response do - around_transition do |build_list, transition, block| + # WTF? around_transition -> infinite loop + before_transition do |build_list, transition| if build_list.mass_build MassBuild.decrement_counter "#{BuildList::HUMAN_STATUSES[build_list.status].to_s}_count", build_list.mass_build_id if MassBuild::COUNT_STATUSES.include?(build_list.status) - block.call + end + end + + after_transition do |build_list, transition| + if build_list.mass_build MassBuild.increment_counter "#{BuildList::HUMAN_STATUSES[build_list.status].to_s}_count", build_list.mass_build_id if MassBuild::COUNT_STATUSES.include?(build_list.status) end end From adb3b1ccabbe2188cc32f9ac629152f59eb766fe Mon Sep 17 00:00:00 2001 From: Alexander Machehin Date: Fri, 29 Jun 2012 17:38:06 +0600 Subject: [PATCH 55/61] [refs #442] fixed bug with priority --- app/models/build_list.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/build_list.rb b/app/models/build_list.rb index 0ae3e86af..9f26360ce 100644 --- a/app/models/build_list.rb +++ b/app/models/build_list.rb @@ -194,7 +194,7 @@ class BuildList < ActiveRecord::Base #TODO: Share this checking on product owner. def can_cancel? - [BUILD_PENDING, BuildServer::PLATFORM_PENDING].include? status && bs_id + [BUILD_PENDING, BuildServer::PLATFORM_PENDING].include?(status) && bs_id end def can_publish? From 01db786728ae9cb27ce9b286c47c2298ba839cd4 Mon Sep 17 00:00:00 2001 From: Alexander Machehin Date: Fri, 29 Jun 2012 17:39:54 +0600 Subject: [PATCH 56/61] [refs #442] remove double checking --- app/views/projects/build_lists/_build_list.html.haml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/projects/build_lists/_build_list.html.haml b/app/views/projects/build_lists/_build_list.html.haml index abb5f43b8..9eb7b1380 100644 --- a/app/views/projects/build_lists/_build_list.html.haml +++ b/app/views/projects/build_lists/_build_list.html.haml @@ -6,5 +6,5 @@ %td= link_to build_list.project_version, "#" %td= build_list.arch.name %td= link_to build_list.user.try(:fullname), build_list.user - %td= link_to image_tag('x.png', :class => 'delete-row', :id => "delete-row#{build_list_counter}"), cancel_build_list_path(build_list), :method => :put, :confirm => t('layout.confirm') if build_list.can_cancel? and can?(:cancel, build_list) + %td= link_to image_tag('x.png', :class => 'delete-row', :id => "delete-row#{build_list_counter}"), cancel_build_list_path(build_list), :method => :put, :confirm => t('layout.confirm') if can?(:cancel, build_list) %td= build_list.updated_at From 59c03005421b3e88120b4f2ab94a24299d8a47e5 Mon Sep 17 00:00:00 2001 From: Alexander Machehin Date: Fri, 29 Jun 2012 17:42:05 +0600 Subject: [PATCH 57/61] [refs #442] small refactoring --- app/models/build_list.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/app/models/build_list.rb b/app/models/build_list.rb index 9f26360ce..14ccd466d 100644 --- a/app/models/build_list.rb +++ b/app/models/build_list.rb @@ -105,14 +105,14 @@ class BuildList < ActiveRecord::Base # WTF? around_transition -> infinite loop before_transition do |build_list, transition| - if build_list.mass_build - MassBuild.decrement_counter "#{BuildList::HUMAN_STATUSES[build_list.status].to_s}_count", build_list.mass_build_id if MassBuild::COUNT_STATUSES.include?(build_list.status) + if build_list.mass_build && MassBuild::COUNT_STATUSES.include?(build_list.status) + MassBuild.decrement_counter "#{BuildList::HUMAN_STATUSES[build_list.status].to_s}_count", build_list.mass_build_id end end after_transition do |build_list, transition| - if build_list.mass_build - MassBuild.increment_counter "#{BuildList::HUMAN_STATUSES[build_list.status].to_s}_count", build_list.mass_build_id if MassBuild::COUNT_STATUSES.include?(build_list.status) + if build_list.mass_build && MassBuild::COUNT_STATUSES.include?(build_list.status) + MassBuild.increment_counter "#{BuildList::HUMAN_STATUSES[build_list.status].to_s}_count", build_list.mass_build_id end end From d3e89393a81426a1c9d0d757b56920e9bdf0484e Mon Sep 17 00:00:00 2001 From: Pavel Chipiga Date: Fri, 29 Jun 2012 16:09:06 +0300 Subject: [PATCH 58/61] Stop resque workers through rake. Refs #543 --- lib/recipes/resque.rb | 9 ++++++--- lib/tasks/resque.rake | 10 ++++++++++ 2 files changed, 16 insertions(+), 3 deletions(-) create mode 100644 lib/tasks/resque.rake diff --git a/lib/recipes/resque.rb b/lib/recipes/resque.rb index a3524324d..625e264de 100644 --- a/lib/recipes/resque.rb +++ b/lib/recipes/resque.rb @@ -20,12 +20,15 @@ Capistrano::Configuration.instance(:must_exist).load do end def stop_workers - ps = 'ps aux | grep resque | grep -v grep' - run "#{ps} && kill -QUIT `#{ps} | awk '{ print $2 }'` || echo 'Workers already stopped!'" + # ps = 'ps aux | grep resque | grep -v grep' + # run "#{ps} && kill -QUIT `#{ps} | awk '{ print $2 }'` || echo 'Workers already stopped!'" + # run "kill -QUIT `ps aux | grep resque | grep -v grep | awk '{ print $2 }'`" + # run "kill -QUIT `ps aux | grep resque | grep -v grep | awk '{ print $2 }'` > /dev/null 2>&1 &" + run "cd #{fetch :current_path} && #{rails_env} bundle exec rake resque:stop_workers" end def start_workers - run "cd #{fetch :current_path} && COUNT=#{ workers_count } QUEUE=fork_import,hook,clone_build,notification #{ rails_env } BACKGROUND=yes bundle exec rake resque:workers" + run "cd #{fetch :current_path} && COUNT=#{workers_count} QUEUE=fork_import,hook,clone_build,notification #{rails_env} BACKGROUND=yes bundle exec rake resque:workers" end end end diff --git a/lib/tasks/resque.rake b/lib/tasks/resque.rake new file mode 100644 index 000000000..5cc0e31e0 --- /dev/null +++ b/lib/tasks/resque.rake @@ -0,0 +1,10 @@ +namespace :resque do + desc 'Stop all Resque workers' + task :stop_workers => :environment do + pids = [] + Resque.workers.each do |worker| + pids << worker.to_s.split(/:/).second + end + system("kill -QUIT #{pids.join(' ')}") if pids.size > 0 + end +end From e78d9c54a123cf0fad7d656827a0b8892f8e4c34 Mon Sep 17 00:00:00 2001 From: Pavel Chipiga Date: Fri, 29 Jun 2012 16:52:32 +0300 Subject: [PATCH 59/61] Code cleanup. Refs #543 --- lib/recipes/resque.rb | 2 -- 1 file changed, 2 deletions(-) diff --git a/lib/recipes/resque.rb b/lib/recipes/resque.rb index 625e264de..8765558d9 100644 --- a/lib/recipes/resque.rb +++ b/lib/recipes/resque.rb @@ -22,8 +22,6 @@ Capistrano::Configuration.instance(:must_exist).load do def stop_workers # ps = 'ps aux | grep resque | grep -v grep' # run "#{ps} && kill -QUIT `#{ps} | awk '{ print $2 }'` || echo 'Workers already stopped!'" - # run "kill -QUIT `ps aux | grep resque | grep -v grep | awk '{ print $2 }'`" - # run "kill -QUIT `ps aux | grep resque | grep -v grep | awk '{ print $2 }'` > /dev/null 2>&1 &" run "cd #{fetch :current_path} && #{rails_env} bundle exec rake resque:stop_workers" end From ea8775f1f7c5f5442d2744169cfb97ea96de7ec4 Mon Sep 17 00:00:00 2001 From: Alexander Machehin Date: Tue, 3 Jul 2012 16:17:53 +0600 Subject: [PATCH 60/61] [refs #547] remove mistake condition --- app/models/ability.rb | 2 +- spec/models/product_build_list_spec.rb | 10 +++++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/app/models/ability.rb b/app/models/ability.rb index 893b2643d..f14e06989 100644 --- a/app/models/ability.rb +++ b/app/models/ability.rb @@ -18,7 +18,7 @@ class Ability can :read, Issue, :project => {:visibility => 'open'} can :search, BuildList can :read, BuildList, :project => {:visibility => 'open'} - can :read, ProductBuildList, :product => {:platform => {:visibility => 'open'}} + can :read, ProductBuildList#, :product => {:platform => {:visibility => 'open'}} # double nested hash don't work can :read, Advisory can(:advisories, Platform) {APP_CONFIG['anonymous_access']} # Core callbacks diff --git a/spec/models/product_build_list_spec.rb b/spec/models/product_build_list_spec.rb index 3f0bbba51..43c2abc61 100644 --- a/spec/models/product_build_list_spec.rb +++ b/spec/models/product_build_list_spec.rb @@ -22,5 +22,13 @@ describe ProductBuildList do it { should allow_mass_assignment_of(:status) } it { should allow_mass_assignment_of(:base_url) } - + + # see app/ability.rb + # can :read, ProductBuildList#, :product => {:platform => {:visibility => 'open'}} # double nested hash don't work + it 'should generate correct sql to get product build lists' do + stub_symlink_methods + user = FactoryGirl.create(:user) + ability = Ability.new user + ProductBuildList.accessible_by(ability).count.should == 0 + end end From b46a7aba393b2dcaec5c8f93fdd5a69a702a6ff6 Mon Sep 17 00:00:00 2001 From: Pavel Chipiga Date: Tue, 3 Jul 2012 15:05:27 +0300 Subject: [PATCH 61/61] Fix branch with dots. Refs #263 --- config/routes.rb | 52 ++++++++++++------------ db/schema.rb | 2 +- spec/routing/projects_routing_spec.rb.rb | 5 ++- 3 files changed, 31 insertions(+), 28 deletions(-) diff --git a/config/routes.rb b/config/routes.rb index 16ba0f84f..e09c8a1cb 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -179,31 +179,33 @@ Rosa::Application.routes.draw do get '/sections' => 'projects#sections', :as => :sections_project post '/sections' => 'projects#sections' delete '/remove_user' => 'projects#remove_user', :as => :remove_user_project - # Tree - get '/' => "git/trees#show", :as => :project - get '/tree/:treeish(/*path)' => "git/trees#show", :defaults => {:treeish => :master}, :as => :tree, :format => false - # Commits - get '/commits/:treeish(/*path)' => "git/commits#index", :defaults => {:treeish => :master}, :as => :commits, :format => false - get '/commit/:id(.:format)' => "git/commits#show", :as => :commit - # Commit comments - post '/commit/:commit_id/comments(.:format)' => "comments#create", :as => :project_commit_comments - get '/commit/:commit_id/comments/:id(.:format)' => "comments#edit", :as => :edit_project_commit_comment - put '/commit/:commit_id/comments/:id(.:format)' => "comments#update", :as => :project_commit_comment - delete '/commit/:commit_id/comments/:id(.:format)' => "comments#destroy" - # Commit subscribes - post '/commit/:commit_id/subscribe' => "commit_subscribes#create", :as => :subscribe_commit - delete '/commit/:commit_id/unsubscribe' => "commit_subscribes#destroy", :as => :unsubscribe_commit - # Editing files - get '/blob/:treeish/*path/edit' => "git/blobs#edit", :defaults => {:treeish => :master}, :as => :edit_blob - put '/blob/:treeish/*path' => "git/blobs#update", :defaults => {:treeish => :master}, :format => false - # Blobs - get '/blob/:treeish/*path' => "git/blobs#show", :defaults => {:treeish => :master}, :as => :blob, :format => false - # Blame - get '/blame/:treeish/*path' => "git/blobs#blame", :defaults => {:treeish => :master}, :as => :blame, :format => false - # Raw - get '/raw/:treeish/*path' => "git/blobs#raw", :defaults => {:treeish => :master}, :as => :raw, :format => false - # Archive - get '/archive/:format/tree/:treeish' => "git/trees#archive", :defaults => {:treeish => :master}, :as => :archive, :format => /zip|tar/ + constraints :treeish => /[^\/]+/ do + # Tree + get '/' => "git/trees#show", :as => :project + get '/tree/:treeish(/*path)' => "git/trees#show", :defaults => {:treeish => :master}, :as => :tree, :format => false + # Commits + get '/commits/:treeish(/*path)' => "git/commits#index", :defaults => {:treeish => :master}, :as => :commits, :format => false + get '/commit/:id(.:format)' => "git/commits#show", :as => :commit + # Commit comments + post '/commit/:commit_id/comments(.:format)' => "comments#create", :as => :project_commit_comments + get '/commit/:commit_id/comments/:id(.:format)' => "comments#edit", :as => :edit_project_commit_comment + put '/commit/:commit_id/comments/:id(.:format)' => "comments#update", :as => :project_commit_comment + delete '/commit/:commit_id/comments/:id(.:format)' => "comments#destroy" + # Commit subscribes + post '/commit/:commit_id/subscribe' => "commit_subscribes#create", :as => :subscribe_commit + delete '/commit/:commit_id/unsubscribe' => "commit_subscribes#destroy", :as => :unsubscribe_commit + # Editing files + get '/blob/:treeish/*path/edit' => "git/blobs#edit", :defaults => {:treeish => :master}, :as => :edit_blob + put '/blob/:treeish/*path' => "git/blobs#update", :defaults => {:treeish => :master}, :format => false + # Blobs + get '/blob/:treeish/*path' => "git/blobs#show", :defaults => {:treeish => :master}, :as => :blob, :format => false + # Blame + get '/blame/:treeish/*path' => "git/blobs#blame", :defaults => {:treeish => :master}, :as => :blame, :format => false + # Raw + get '/raw/:treeish/*path' => "git/blobs#raw", :defaults => {:treeish => :master}, :as => :raw, :format => false + # Archive + get '/archive/:format/tree/:treeish' => "git/trees#archive", :defaults => {:treeish => :master}, :as => :archive, :format => /zip|tar/ + end end end diff --git a/db/schema.rb b/db/schema.rb index 4eb6a8e93..2f0a24c6a 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -304,7 +304,7 @@ ActiveRecord::Schema.define(:version => 20120628165702) do t.integer "build_count", :default => 0, :null => false end - add_index "projects", ["owner_id"], :name => "index_projects_on_name_and_owner_id_and_owner_type", :unique => true + add_index "projects", ["owner_id"], :name => "index_projects_on_name_and_owner_id_and_owner_type", :unique => true, :case_sensitive => false create_table "register_requests", :force => true do |t| t.string "name" diff --git a/spec/routing/projects_routing_spec.rb.rb b/spec/routing/projects_routing_spec.rb.rb index ac8d5d2e2..5bcc65d06 100644 --- a/spec/routing/projects_routing_spec.rb.rb +++ b/spec/routing/projects_routing_spec.rb.rb @@ -36,8 +36,9 @@ describe Projects::Git::TreesController do it "routes to #show" do get("/import/glib2.0-mib").should route_to("projects/git/trees#show", :owner_name => 'import', :project_name => 'glib2.0-mib') - get("/import/glib2.0-mib/tree/branch").should route_to("projects/git/trees#show", :owner_name => 'import', :project_name => 'glib2.0-mib', :treeish => 'branch') - get("/import/glib2.0-mib/tree/branch/some/path.to").should route_to("projects/git/trees#show", :owner_name => 'import', :project_name => 'glib2.0-mib', :treeish => 'branch', :path => 'some/path.to') + get("/import/glib2.0-mib/tree/lib2safe-0.03").should route_to("projects/git/trees#show", :owner_name => 'import', :project_name => 'glib2.0-mib', :treeish => 'lib2safe-0.03') + get("/import/glib2.0-mib/tree/branch-with.dot/folder_with.dot/path-with.dot").should route_to("projects/git/trees#show", :owner_name => 'import', :project_name => 'glib2.0-mib', :treeish => 'branch-with.dot', :path => 'folder_with.dot/path-with.dot') + # get("/import/glib2.0-mib/tree/ветка-с.точкой/папка_с.точкой/путь-с.точкой").should route_to("projects/git/trees#show", :owner_name => 'import', :project_name => 'glib2.0-mib', :treeish => 'ветка-с.точкой', :path => 'папка_с.точкой/путь-с.точкой') end # TODO write more specs also with slash in branch name!