From 81e11da8567d6725db87163e746ac7ce4e601e7d Mon Sep 17 00:00:00 2001 From: Piotr Sarnacki Date: Tue, 24 Nov 2015 11:37:37 +0100 Subject: [PATCH 1/3] Fix error when default branch tries to be autosaved For some reason when branch from V2 models is being saved, it tries to also update relationships for V3 models, at least in tests. This fails, because default_branch association on the V3 Repository model has a primary key set to [:id, :default_branch]. In theory we use composite keys plugin, but it seems that it doesn't cover that case and because of that AR fails with an error "[:id, :default_branch] is not a Symbol" when it tries to call Model#send with primary_key as an argument. This commit fixes the issue by overriding the send method on the Repository model to not fail when AR does repository.send([:id, :default_branch_name]), when it needs to fetch a primary key. This is hacky, but I haven't found a nicer way to get around it. --- lib/travis/api/v3/models/repository.rb | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/lib/travis/api/v3/models/repository.rb b/lib/travis/api/v3/models/repository.rb index 6bf8f4de..b5cd94f8 100644 --- a/lib/travis/api/v3/models/repository.rb +++ b/lib/travis/api/v3/models/repository.rb @@ -49,5 +49,17 @@ module Travis::API::V3 rescue ActiveRecord::RecordNotUnique branches.where(name: name).first end + + def id_default_branch + [id, default_branch_name] + end + + def send(name, *args, &block) + if name == [:id, :default_branch] + name = :id_default_branch + end + + __send__(name, *args, &block) + end end end From dbea2f37606ca1040c8770ec7b41b78431f2c480 Mon Sep 17 00:00:00 2001 From: Piotr Sarnacki Date: Tue, 24 Nov 2015 14:05:35 +0100 Subject: [PATCH 2/3] Revert "v3: in access control object, avoid firing multiple permissions queries (even though they are cache hits)" This reverts commit 4a3357a4888b424a1074d2f3c10df951467e185a. --- lib/travis/api/v3/access_control/user.rb | 16 +--------------- 1 file changed, 1 insertion(+), 15 deletions(-) diff --git a/lib/travis/api/v3/access_control/user.rb b/lib/travis/api/v3/access_control/user.rb index 5b6460fe..e48bb577 100644 --- a/lib/travis/api/v3/access_control/user.rb +++ b/lib/travis/api/v3/access_control/user.rb @@ -8,7 +8,6 @@ module Travis::API::V3 user = Models::User.find(user.id) if user.is_a? ::User @user = user @access_permissions = user.permissions.where(user_id: user.id) - @got_request = false super() end @@ -21,7 +20,6 @@ module Travis::API::V3 end def visible_repositories(list) - load_permissions list.where('repositories.private = false OR repositories.id IN (?)'.freeze, access_permissions.map(&:repository_id)) end @@ -49,19 +47,7 @@ module Travis::API::V3 def permission?(type, id) id = id.id if id.is_a? ::Repository - - load_permissions if @got_request - @got_request = true - - if access_permissions.respond_to? :where - access_permissions.where(type => true, :repository_id => id).any? - else - access_permissions.any? { |p| p[type] == true and p.repository_id == id } - end - end - - def load_permissions - @access_permissions = @access_permissions.to_a + access_permissions.where(type => true, :repository_id => id).any? end end end From cf5915a06b7423ddc23cca68700fca526b68677c Mon Sep 17 00:00:00 2001 From: Piotr Sarnacki Date: Wed, 25 Nov 2015 18:11:43 +0100 Subject: [PATCH 3/3] Bump travis-core --- Gemfile.lock | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Gemfile.lock b/Gemfile.lock index f50dc7b9..8ae03428 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -50,7 +50,7 @@ GIT GIT remote: git://github.com/travis-ci/travis-core.git - revision: 3c20e66a20d9d540e2a6c5fb70c542fe97c62e25 + revision: 9a9f4caa2187734d34e98aa61ba5f4a61bc8a9f5 specs: travis-core (0.0.1) actionmailer (~> 3.2.19)