Commit 2c0b6776 authored by Bob Van Landuyt's avatar Bob Van Landuyt
Browse files

Fix errors when deleting a forked project

The problem would occur when the `ForkedProjectLink` was deleted, but
the `ForkNetworkMember` was not. The delete would be rolled back and

But the error would not be saved because `Project#forked?`
would still be true, because the `ForkNetworkMember` exists. But the
`Project#forked_project_link` would be `nil`. So the validation for
the visibility level would fail.
parent 241b4b57c6c5
...@@ -1272,7 +1272,7 @@ def visibility_level_allowed_as_fork?(level = self.visibility_level) ...@@ -1272,7 +1272,7 @@ def visibility_level_allowed_as_fork?(level = self.visibility_level)
# self.forked_from_project will be nil before the project is saved, so # self.forked_from_project will be nil before the project is saved, so
# we need to go through the relation # we need to go through the relation
original_project = forked_project_link.forked_from_project original_project = forked_project_link&.forked_from_project
return true unless original_project return true unless original_project
level <= original_project.visibility_level level <= original_project.visibility_level
...@@ -15,8 +15,8 @@ def execute ...@@ -15,8 +15,8 @@ def execute
refresh_forks_count(@project.forked_from_project) refresh_forks_count(@project.forked_from_project)
@project.fork_network_member.destroy @project.fork_network_member.destroy
end end
def refresh_forks_count(project) def refresh_forks_count(project)
title: Fix error when updating a forked project with deleted `ForkedProjectLink`
merge_request: 14916
type: fixed
require 'spec_helper' require 'spec_helper'
describe Projects::DestroyService do describe Projects::DestroyService do
include ProjectForksHelper
let!(:user) { create(:user) } let!(:user) { create(:user) }
let!(:project) { create(:project, :repository, namespace: user.namespace) } let!(:project) { create(:project, :repository, namespace: user.namespace) }
let!(:path) { project.repository.path_to_repo } let!(:path) { project.repository.path_to_repo }
...@@ -212,6 +214,21 @@ ...@@ -212,6 +214,21 @@
end end
end end
context 'for a forked project with LFS objects' do
let(:forked_project) { fork_project(project, user) }
before do
project.lfs_objects << create(:lfs_object)
it 'destroys the fork' do
expect { destroy_project(forked_project, user) }
.not_to raise_error
context 'as the root of a fork network' do context 'as the root of a fork network' do
let!(:fork_network) { create(:fork_network, root_project: project) } let!(:fork_network) { create(:fork_network, root_project: project) }
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