Commit e4cde428 authored by Sean McGivern's avatar Sean McGivern

Merge branch 'fix/project-delete-tooltip' into 'master'

Fix project queued for deletion re-creation tooltip

Closes #17235

See merge request !5393
parents 826adaaf d3cfa39e
module ValidAttribute
extend ActiveSupport::Concern
# Checks whether an attribute has failed validation or not
#
# +attribute+ The symbolised name of the attribute i.e :name
def valid_attribute?(attribute)
self.errors.empty? || self.errors.messages[attribute].nil?
end
end
...@@ -12,6 +12,7 @@ class Project < ActiveRecord::Base ...@@ -12,6 +12,7 @@ class Project < ActiveRecord::Base
include AfterCommitQueue include AfterCommitQueue
include CaseSensitivity include CaseSensitivity
include TokenAuthenticatable include TokenAuthenticatable
include ValidAttribute
include ProjectFeaturesCompatibility include ProjectFeaturesCompatibility
include SelectForProjectAuthorization include SelectForProjectAuthorization
include Routable include Routable
...@@ -65,6 +66,8 @@ class Project < ActiveRecord::Base ...@@ -65,6 +66,8 @@ class Project < ActiveRecord::Base
end end
end end
after_validation :check_pending_delete
ActsAsTaggableOn.strict_case_match = true ActsAsTaggableOn.strict_case_match = true
acts_as_taggable_on :tags acts_as_taggable_on :tags
...@@ -1320,4 +1323,21 @@ class Project < ActiveRecord::Base ...@@ -1320,4 +1323,21 @@ class Project < ActiveRecord::Base
stats = statistics || build_statistics stats = statistics || build_statistics
stats.update(namespace_id: namespace_id) stats.update(namespace_id: namespace_id)
end end
def check_pending_delete
return if valid_attribute?(:name) && valid_attribute?(:path)
return unless pending_delete_twin
%i[route route.path name path].each do |error|
errors.delete(error)
end
errors.add(:base, "The project is still being deleted. Please try again later.")
end
def pending_delete_twin
return false unless path
Project.unscoped.where(pending_delete: true).find_with_namespace(path_with_namespace)
end
end end
---
title: Fix project queued for deletion re-creation tooltip
merge_request:
author:
...@@ -190,34 +190,54 @@ describe Project, models: true do ...@@ -190,34 +190,54 @@ describe Project, models: true do
end end
it 'does not allow an invalid URI as import_url' do it 'does not allow an invalid URI as import_url' do
project2 = build(:project, import_url: 'invalid://') project2 = build(:empty_project, import_url: 'invalid://')
expect(project2).not_to be_valid expect(project2).not_to be_valid
end end
it 'does allow a valid URI as import_url' do it 'does allow a valid URI as import_url' do
project2 = build(:project, import_url: 'ssh://test@gitlab.com/project.git') project2 = build(:empty_project, import_url: 'ssh://test@gitlab.com/project.git')
expect(project2).to be_valid expect(project2).to be_valid
end end
it 'allows an empty URI' do it 'allows an empty URI' do
project2 = build(:project, import_url: '') project2 = build(:empty_project, import_url: '')
expect(project2).to be_valid expect(project2).to be_valid
end end
it 'does not produce import data on an empty URI' do it 'does not produce import data on an empty URI' do
project2 = build(:project, import_url: '') project2 = build(:empty_project, import_url: '')
expect(project2.import_data).to be_nil expect(project2.import_data).to be_nil
end end
it 'does not produce import data on an invalid URI' do it 'does not produce import data on an invalid URI' do
project2 = build(:project, import_url: 'test://') project2 = build(:empty_project, import_url: 'test://')
expect(project2.import_data).to be_nil expect(project2.import_data).to be_nil
end end
describe 'project pending deletion' do
let!(:project_pending_deletion) do
create(:empty_project,
pending_delete: true)
end
let(:new_project) do
build(:empty_project,
name: project_pending_deletion.name,
namespace: project_pending_deletion.namespace)
end
before do
new_project.validate
end
it 'contains errors related to the project being deleted' do
expect(new_project.errors.full_messages.first).to eq('The project is still being deleted. Please try again later.')
end
end
end end
describe 'default_scope' do describe 'default_scope' 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