Compare commits

...

4 Commits

Author SHA1 Message Date
Piotr Sarnacki
54fd33dece Auto-merged master into try-fixing-branches-autosave on deployment. 2015-11-24 14:12:51 +01:00
Piotr Sarnacki
fa994c9c9b Revert "v3: in access control object, avoid firing multiple permissions queries (even though they are cache hits)"
This reverts commit 4a3357a488.
2015-11-24 14:05:35 +01:00
Piotr Sarnacki
1cc6a2623d 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.
2015-11-24 13:46:15 +01:00
Piotr Sarnacki
7b5fc46e01 Bump travis-core 2015-11-24 11:37:21 +01:00
2 changed files with 13 additions and 15 deletions

View File

@ -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

View File

@ -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