Commit ebd51744 authored by James Edwards-Jones's avatar James Edwards-Jones

Handle forks in Gitlab::Checks::LfsIntegrity

parent 78ea074f
......@@ -91,15 +91,7 @@ module LfsRequest
end
def storage_project
@storage_project ||= begin
result = project
# TODO: Make this go to the fork_network root immeadiatly
# dependant on the discussion in: https://gitlab.com/gitlab-org/gitlab-ce/issues/39769
result = result.fork_source while result.forked?
result
end
@storage_project ||= project.lfs_storage_project
end
def objects
......
......@@ -6,16 +6,8 @@ class LfsObject < ActiveRecord::Base
mount_uploader :file, LfsObjectUploader
def storage_project(project)
if project && project.forked?
storage_project(project.forked_from_project)
else
project
end
end
def project_allowed_access?(project)
projects.exists?(storage_project(project).id)
projects.exists?(project.lfs_storage_project.id)
end
def self.destroy_unreferenced
......
......@@ -1042,6 +1042,18 @@ class Project < ActiveRecord::Base
forked_from_project || fork_network&.root_project
end
def lfs_storage_project
@lfs_storage_project ||= begin
result = self
# TODO: Make this go to the fork_network root immeadiatly
# dependant on the discussion in: https://gitlab.com/gitlab-org/gitlab-ce/issues/39769
result = result.fork_source while result&.forked?
result || self
end
end
def personal?
!group
end
......
......@@ -15,7 +15,10 @@ module Gitlab
return false unless new_lfs_pointers.present?
existing_count = @project.lfs_objects.where(oid: new_lfs_pointers.map(&:lfs_oid)).count
existing_count = @project.lfs_storage_project
.lfs_objects
.where(oid: new_lfs_pointers.map(&:lfs_oid))
.count
existing_count != new_lfs_pointers.count
end
......
require 'spec_helper'
describe Gitlab::Checks::LfsIntegrity do
include ProjectForksHelper
let(:project) { create(:project, :repository) }
let(:newrev) { '54fcc214b94e78d7a41a9a8fe6d87a5e59500e51' }
......@@ -49,5 +50,25 @@ describe Gitlab::Checks::LfsIntegrity do
expect(subject.objects_missing?).to be_falsey
end
end
context 'for forked project' do
let(:parent_project) { create(:project, :repository) }
let(:project) { fork_project(parent_project, nil, repository: true) }
before do
allow(project).to receive(:lfs_enabled?).and_return(true)
end
it 'is true parent project is missing LFS objects' do
expect(subject.objects_missing?).to be_truthy
end
it 'is false parent project already conatins LFS objects for the fork' do
lfs_object = create(:lfs_object, oid: blob_object.lfs_oid)
create(:lfs_objects_project, project: parent_project, lfs_object: lfs_object)
expect(subject.objects_missing?).to be_falsey
end
end
end
end
......@@ -1943,6 +1943,24 @@ describe Project do
expect(second_fork.fork_source).to eq(project)
end
end
describe '#lfs_storage_project' do
it 'returns self for non-forks' do
expect(project.lfs_storage_project).to eq project
end
it 'returns the fork network root for forks' do
second_fork = fork_project(forked_project)
expect(second_fork.lfs_storage_project).to eq project
end
it 'returns self when fork_source is nil' do
expect(forked_project).to receive(:fork_source).and_return(nil)
expect(forked_project.lfs_storage_project).to eq forked_project
end
end
end
describe '#pushes_since_gc' do
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment