Commit f841efb8 authored by Stan Hu's avatar Stan Hu

Fix incorrect project path warning after failed project path rename

If an update to the project path fails validation, the unsaved
attributes would still be presented because the controller would fall
through and call `render` on the unsaved object. This resulted in the
wrong project path being displayed in the "Delete project"
warning. However, unlike with
https://gitlab.com/gitlab-org/gitlab/-/merge_requests/40353, changes in
`Project#to_param` in ea4d6c87 prevented
the wrong project path from being deleted.

While it may have been intentional to retain the failed values, it's
better to be safe and reset all the values back to their persisted
state.

Relates to https://gitlab.com/gitlab-org/gitlab/-/issues/241110
parent cf00a6bc
......@@ -98,6 +98,7 @@ class ProjectsController < Projects::ApplicationController
end
else
flash.now[:alert] = result[:message]
@project.reset
format.html { render_edit }
end
......
---
title: Fix incorrect project path warning after failed project path rename
merge_request: 40422
author:
type: fixed
......@@ -555,6 +555,18 @@ RSpec.describe ProjectsController do
end
shared_examples_for 'updating a project' do
context 'when there is a conflicting project path' do
let(:random_name) { "project-#{SecureRandom.hex(8)}" }
let!(:conflict_project) { create(:project, name: random_name, path: random_name, namespace: project.namespace) }
it 'does not show any references to the conflicting path' do
expect { update_project(path: random_name) }.not_to change { project.reload.path }
expect(response).to have_gitlab_http_status(:ok)
expect(response.body).not_to include(random_name)
end
end
context 'when only renaming a project path' do
it "sets the repository to the right path after a rename" do
original_repository_path = Gitlab::GitalyClient::StorageSettings.allow_disk_access do
......
......@@ -37,7 +37,7 @@ RSpec.describe 'Projects > Settings > User renames a project' do
it 'shows errors for invalid project path' do
change_path(project, 'foo&bar')
expect(page).to have_field 'Path', with: 'foo&bar'
expect(page).to have_field 'Path', with: 'gitlab'
expect(page).to have_content "Path can contain only letters, digits, '_', '-' and '.'. Cannot start with '-', end in '.git' or end in '.atom'"
end
end
......
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