Commit 1859d13a authored by Paul Slaughter's avatar Paul Slaughter

Merge branch '343591-restore-namespace-requirement-for-project-deletion-confirmation' into 'master'

Restore namespace requirement for project deletion confirmation

See merge request gitlab-org/gitlab!73176
parents 7ee3e537 d20ed309
<script> <script>
import { GlModal, GlModalDirective, GlFormInput, GlButton } from '@gitlab/ui'; import { GlModal, GlModalDirective, GlFormTextarea, GlButton } from '@gitlab/ui';
import { uniqueId } from 'lodash'; import { uniqueId } from 'lodash';
import csrf from '~/lib/utils/csrf'; import csrf from '~/lib/utils/csrf';
import { __ } from '~/locale'; import { __ } from '~/locale';
...@@ -7,7 +7,7 @@ import { __ } from '~/locale'; ...@@ -7,7 +7,7 @@ import { __ } from '~/locale';
export default { export default {
components: { components: {
GlModal, GlModal,
GlFormInput, GlFormTextarea,
GlButton, GlButton,
}, },
directives: { directives: {
...@@ -88,12 +88,7 @@ export default { ...@@ -88,12 +88,7 @@ export default {
<p> <p>
<code class="gl-white-space-pre-wrap">{{ confirmPhrase }}</code> <code class="gl-white-space-pre-wrap">{{ confirmPhrase }}</code>
</p> </p>
<gl-form-input <gl-form-textarea id="confirm_name_input" v-model="userInput" name="confirm_name_input" />
id="confirm_name_input"
v-model="userInput"
name="confirm_name_input"
type="text"
/>
<slot name="modal-footer"></slot> <slot name="modal-footer"></slot>
</div> </div>
</gl-modal> </gl-modal>
......
...@@ -382,6 +382,16 @@ module ProjectsHelper ...@@ -382,6 +382,16 @@ module ProjectsHelper
"" ""
end end
# Returns the confirm phrase the user needs to type in order to delete the project
#
# Occasionally a user will delete one project, believing it is a different (similar) one.
# Specifically, a user might delete an original project, believing it is a fork.
# Thus the phrase should be the project full name to include the namespace.
# Relevant issue: https://gitlab.com/gitlab-org/gitlab/-/issues/343591
def delete_confirm_phrase(project)
s_('DeleteProject|Delete %{name}') % { name: project.full_name }
end
private private
def tab_ability_map def tab_ability_map
......
...@@ -7,4 +7,4 @@ ...@@ -7,4 +7,4 @@
= link_to _('Learn more.'), help_page_path('user/project/settings/index', anchor: 'removing-a-fork-relationship'), target: '_blank', rel: 'noopener noreferrer' = link_to _('Learn more.'), help_page_path('user/project/settings/index', anchor: 'removing-a-fork-relationship'), target: '_blank', rel: 'noopener noreferrer'
%p %p
%strong= _('Deleted projects cannot be restored!') %strong= _('Deleted projects cannot be restored!')
#js-project-delete-button{ data: { form_path: project_path(project), confirm_phrase: project.path } } #js-project-delete-button{ data: { form_path: project_path(project), confirm_phrase: delete_confirm_phrase(project) } }
...@@ -19,7 +19,7 @@ ...@@ -19,7 +19,7 @@
%p= permanent_delete_message(project) %p= permanent_delete_message(project)
%p %p
%strong= _('Are you ABSOLUTELY SURE you wish to delete this project?') %strong= _('Are you ABSOLUTELY SURE you wish to delete this project?')
#js-project-delete-button{ data: { form_path: project_path(project), confirm_phrase: project.path } } #js-project-delete-button{ data: { form_path: project_path(project), confirm_phrase: delete_confirm_phrase(project) } }
- else - else
= render 'projects/settings/restore', project: project = render 'projects/settings/restore', project: project
= render 'projects/settings/permanently_delete', project: project = render 'projects/settings/permanently_delete', project: project
......
...@@ -60,10 +60,10 @@ exports[`Project remove modal initialized matches the snapshot 1`] = ` ...@@ -60,10 +60,10 @@ exports[`Project remove modal initialized matches the snapshot 1`] = `
</code> </code>
</p> </p>
<gl-form-input-stub <gl-form-textarea-stub
id="confirm_name_input" id="confirm_name_input"
name="confirm_name_input" name="confirm_name_input"
type="text" noresize="true"
/> />
<p <p
......
...@@ -11101,6 +11101,9 @@ msgstr "" ...@@ -11101,6 +11101,9 @@ msgstr ""
msgid "Delete variable" msgid "Delete variable"
msgstr "" msgstr ""
msgid "DeleteProject|Delete %{name}"
msgstr ""
msgid "DeleteProject|Failed to remove project repository. Please try again or contact administrator." msgid "DeleteProject|Failed to remove project repository. Please try again or contact administrator."
msgstr "" msgstr ""
......
...@@ -257,7 +257,7 @@ RSpec.describe 'Project' do ...@@ -257,7 +257,7 @@ RSpec.describe 'Project' do
end end
it 'deletes a project', :sidekiq_inline do it 'deletes a project', :sidekiq_inline do
expect { remove_with_confirm('Delete project', project.path, 'Yes, delete project') }.to change { Project.count }.by(-1) expect { remove_with_confirm('Delete project', "Delete #{project.full_name}", 'Yes, delete project') }.to change { Project.count }.by(-1)
expect(page).to have_content "Project '#{project.full_name}' is in the process of being deleted." expect(page).to have_content "Project '#{project.full_name}' is in the process of being deleted."
expect(Project.all.count).to be_zero expect(Project.all.count).to be_zero
expect(project.issues).to be_empty expect(project.issues).to be_empty
......
...@@ -71,10 +71,10 @@ exports[`Project remove modal initialized matches the snapshot 1`] = ` ...@@ -71,10 +71,10 @@ exports[`Project remove modal initialized matches the snapshot 1`] = `
</code> </code>
</p> </p>
<gl-form-input-stub <gl-form-textarea-stub
id="confirm_name_input" id="confirm_name_input"
name="confirm_name_input" name="confirm_name_input"
type="text" noresize="true"
/> />
</div> </div>
......
...@@ -51,10 +51,10 @@ exports[`Project remove modal intialized matches the snapshot 1`] = ` ...@@ -51,10 +51,10 @@ exports[`Project remove modal intialized matches the snapshot 1`] = `
</code> </code>
</p> </p>
<gl-form-input-stub <gl-form-textarea-stub
id="confirm_name_input" id="confirm_name_input"
name="confirm_name_input" name="confirm_name_input"
type="text" noresize="true"
/> />
</div> </div>
......
...@@ -983,4 +983,12 @@ RSpec.describe ProjectsHelper do ...@@ -983,4 +983,12 @@ RSpec.describe ProjectsHelper do
it { is_expected.not_to include('project-highlight-puc') } it { is_expected.not_to include('project-highlight-puc') }
end end
end end
describe "#delete_confirm_phrase" do
subject { helper.delete_confirm_phrase(project) }
it 'includes the project full name' do
expect(subject).to eq("Delete #{project.full_name}")
end
end
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