From df0de4d0ecc942ae13eee9b53cf45f9f9bf6be8c Mon Sep 17 00:00:00 2001 From: Vokhmin Alexey V Date: Tue, 23 Dec 2014 00:58:19 +0300 Subject: [PATCH 1/5] added dependent_projects into API --- app/views/api/v1/build_lists/show.json.jbuilder | 1 - app/views/api/v1/maintainers/_package.json.jbuilder | 7 ++++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/app/views/api/v1/build_lists/show.json.jbuilder b/app/views/api/v1/build_lists/show.json.jbuilder index 794f92e0f..37095d14c 100644 --- a/app/views/api/v1/build_lists/show.json.jbuilder +++ b/app/views/api/v1/build_lists/show.json.jbuilder @@ -1,7 +1,6 @@ json.build_list do json.(@build_list, :id, :container_status, :status, :duration) json.(@build_list, :update_type, :priority, :new_core) - json.(@build_list, :advisory, :mass_build) json.(@build_list, :auto_publish_status, :package_version, :commit_hash, :last_published_commit_hash, :auto_create_container, :use_cached_chroot, :use_extra_tests) json.build_log_url log_build_list_path(@build_list) diff --git a/app/views/api/v1/maintainers/_package.json.jbuilder b/app/views/api/v1/maintainers/_package.json.jbuilder index 9940da2ce..29294ffff 100644 --- a/app/views/api/v1/maintainers/_package.json.jbuilder +++ b/app/views/api/v1/maintainers/_package.json.jbuilder @@ -1,4 +1,9 @@ json.(package, :id, :name, :version, :release, :epoch) json.type package.package_type json.updated_at package.updated_at.to_i -json.url (package.sha1 ? "#{APP_CONFIG['file_store_url']}/api/v1/file_stores/#{package.sha1}" : '' ) \ No newline at end of file +json.url (package.sha1 ? "#{APP_CONFIG['file_store_url']}/api/v1/file_stores/#{package.sha1}" : '' ) + +json.dependent_projects dependent_projects(package) do |project, packages| + json.partial! 'api/v1/projects/project', project: project + json.dependent_packages packages +end if package.build_list.save_to_platform.main? \ No newline at end of file From 28c9e9e65bec2e7ba04d250617c51eb151420852 Mon Sep 17 00:00:00 2001 From: Alexander Machehin Date: Tue, 23 Dec 2014 12:22:06 +0400 Subject: [PATCH 2/5] Updated show.json.jbuilder --- .../api/v1/build_lists/show.json.jbuilder | 22 +++++++++++++------ 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/app/views/api/v1/build_lists/show.json.jbuilder b/app/views/api/v1/build_lists/show.json.jbuilder index 37095d14c..b4cb8a726 100644 --- a/app/views/api/v1/build_lists/show.json.jbuilder +++ b/app/views/api/v1/build_lists/show.json.jbuilder @@ -62,14 +62,22 @@ json.build_list do json.extra_params @build_list.extra_params - json.advisory do - json.name @build_list.advisory.advisory_id - json.(@build_list.advisory, :description) - end if @build_list.advisory + if @build_list.advisory + json.advisory do + json.name @build_list.advisory.advisory_id + json.(@build_list.advisory, :description) + end + else + json.advisory nil + end - json.mass_build do - json.(@build_list.mass_build, :id, :name) - end if @build_list.mass_build + if @build_list.mass_build + json.mass_build do + json.(@build_list.mass_build, :id, :name) + end + else + json.mass_build nil + end json.logs (@build_list.results || []) do |result| json.file_name result['file_name'] From 9b9137801b4b5332c3083984e628bb968272b4ad Mon Sep 17 00:00:00 2001 From: Vokhmin Alexey V Date: Wed, 24 Dec 2014 00:56:30 +0300 Subject: [PATCH 3/5] Added ability for project writer to create ProductBuildList --- app/models/ability.rb | 1 + app/models/product_build_list.rb | 6 +++ .../api/v1/product_build_lists_controller.rb | 1 + spec/models/cancan_spec.rb | 38 +++++++++++++++++++ 4 files changed, 46 insertions(+) diff --git a/app/models/ability.rb b/app/models/ability.rb index dfe309f97..01cb79a4c 100644 --- a/app/models/ability.rb +++ b/app/models/ability.rb @@ -141,6 +141,7 @@ class Ability can(:read, Product, read_relations_for('products', 'platforms')) {|product| product.platform.main?} can([:create, :update, :destroy, :clone], Product) {|product| local_admin? product.platform and product.platform.main?} + can([:create, :cancel], ProductBuildList) {|pbl| can?(:write, pbl.project)} can([:create, :cancel, :update], ProductBuildList) {|pbl| can?(:update, pbl.product)} can(:destroy, ProductBuildList) {|pbl| can?(:destroy, pbl.product)} diff --git a/app/models/product_build_list.rb b/app/models/product_build_list.rb index f4a55a066..ff77f2681 100644 --- a/app/models/product_build_list.rb +++ b/app/models/product_build_list.rb @@ -80,6 +80,8 @@ class ProductBuildList < ActiveRecord::Base Time.now - LIVE_TIME, Time.now - MAX_LIVE_TIME) } + after_initialize :init_project, if: :new_record? + after_create :add_job_to_abf_worker_queue before_destroy :can_destroy? @@ -153,6 +155,10 @@ class ProductBuildList < ActiveRecord::Base protected + def init_project + self.project ||= product.try(:project) + end + def abf_worker_priority '' end diff --git a/spec/controllers/api/v1/product_build_lists_controller.rb b/spec/controllers/api/v1/product_build_lists_controller.rb index 35ee395a3..38810b276 100644 --- a/spec/controllers/api/v1/product_build_lists_controller.rb +++ b/spec/controllers/api/v1/product_build_lists_controller.rb @@ -115,6 +115,7 @@ end describe Api::V1::ProductBuildListsController do before(:each) do stub_symlink_methods + FactoryGirl.create(:arch, name: 'x86_64') @product_build_list = FactoryGirl.create(:product_build_list) @another_user = FactoryGirl.create(:user) diff --git a/spec/models/cancan_spec.rb b/spec/models/cancan_spec.rb index 867010e1f..2a8e262cf 100644 --- a/spec/models/cancan_spec.rb +++ b/spec/models/cancan_spec.rb @@ -318,5 +318,43 @@ describe CanCan do end end end # 'repository relations' + + context 'product build list relations' do + let(:product_build_list) { FactoryGirl.create(:product_build_list) } + + before { FactoryGirl.create(:arch, name: 'x86_64') } + + context 'with platform admin rights' do + before do + product_build_list.product.platform.owner = @user + product_build_list.product.platform.save + end + + [:read, :create, :update, :destroy, :log, :cancel].each do |action| + it "should be able to #{action} product build list" do + @ability.should be_able_to(action, product_build_list) + end + end + end + + context 'with project writer rights' do + before do + create_relation(product_build_list.project, @user, 'writer') + end + + [:read, :create, :log, :cancel].each do |action| + it "should be able to #{action} product build list" do + @ability.should be_able_to(action, product_build_list) + end + end + + [:update, :destroy].each do |action| + it "should not be able to #{action} product build list" do + @ability.should_not be_able_to(action, product_build_list) + end + end + end + end # 'repository relations' + end # 'Site user' end From 5992427773a5566874108dd34b069c5a0f758456 Mon Sep 17 00:00:00 2001 From: Vokhmin Alexey V Date: Wed, 24 Dec 2014 00:59:08 +0300 Subject: [PATCH 4/5] updated comments --- spec/models/cancan_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/models/cancan_spec.rb b/spec/models/cancan_spec.rb index 2a8e262cf..4aa674e98 100644 --- a/spec/models/cancan_spec.rb +++ b/spec/models/cancan_spec.rb @@ -354,7 +354,7 @@ describe CanCan do end end end - end # 'repository relations' + end # 'product build list relations' end # 'Site user' end From c71e05ad3cae4893960394db2a7789f645706d17 Mon Sep 17 00:00:00 2001 From: Alexander Machehin Date: Thu, 22 Jan 2015 15:21:51 +0500 Subject: [PATCH 5/5] [#369] remove detecting renames from a diff stats method --- lib/ext/git/grit.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/ext/git/grit.rb b/lib/ext/git/grit.rb index 5e67c2d26..62ca5dc6a 100644 --- a/lib/ext/git/grit.rb +++ b/lib/ext/git/grit.rb @@ -83,7 +83,7 @@ module Grit def diff_stats(a,b) stats = [] Dir.chdir(path) do - lines = self.git.native(:diff, {numstat: true, M: true}, "#{a}...#{b}").split("\n") + lines = self.git.native(:diff, {numstat: true}, "#{a}...#{b}").split("\n") while !lines.empty? files = [] while lines.first =~ /^([-\d]+)\s+([-\d]+)\s+(.+)/