Merge branch 'bvl-fix-deleting-forked-projects' into 'master'

Fix errors when deleting a forked project

Closes #39196

See merge request gitlab-org/gitlab-ce!14916
This commit is contained in:
Douwe Maan 2017-10-17 15:42:05 +00:00
commit 85d8ab52ca
4 changed files with 24 additions and 2 deletions

View file

@ -1272,7 +1272,7 @@ class Project < ActiveRecord::Base
# self.forked_from_project will be nil before the project is saved, so
# 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
level <= original_project.visibility_level

View file

@ -15,8 +15,8 @@ module Projects
refresh_forks_count(@project.forked_from_project)
@project.forked_project_link.destroy
@project.fork_network_member.destroy
@project.forked_project_link.destroy
end
def refresh_forks_count(project)

View file

@ -0,0 +1,5 @@
---
title: Fix error when updating a forked project with deleted `ForkedProjectLink`
merge_request: 14916
author:
type: fixed

View file

@ -1,6 +1,8 @@
require 'spec_helper'
describe Projects::DestroyService do
include ProjectForksHelper
let!(:user) { create(:user) }
let!(:project) { create(:project, :repository, namespace: user.namespace) }
let!(:path) { project.repository.path_to_repo }
@ -212,6 +214,21 @@ describe Projects::DestroyService do
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)
forked_project.forked_project_link.destroy
forked_project.reload
end
it 'destroys the fork' do
expect { destroy_project(forked_project, user) }
.not_to raise_error
end
end
context 'as the root of a fork network' do
let!(:fork_network) { create(:fork_network, root_project: project) }