Commit 3435195f authored by Alishan Ladhani's avatar Alishan Ladhani

Prevent deletion a serverless domain that is in use

parent 004dbe1c
......@@ -31,6 +31,12 @@ class Admin::Serverless::DomainsController < Admin::ApplicationController
end
def destroy
if domain.serverless_domain_clusters.count > 0
return redirect_to admin_serverless_domains_path,
status: :conflict,
notice: _('Domain cannot be deleted while associated to one or more clusters.')
end
domain.destroy!
redirect_to admin_serverless_domains_path,
......
......@@ -6880,6 +6880,9 @@ msgstr ""
msgid "Domain"
msgstr ""
msgid "Domain cannot be deleted while associated to one or more clusters."
msgstr ""
msgid "Domain verification is an essential security measure for public GitLab sites. Users are required to demonstrate they control a domain before it is enabled"
msgstr ""
......
......@@ -338,6 +338,20 @@ describe Admin::Serverless::DomainsController do
expect(flash[:notice]).to include('Domain was successfully deleted.')
end
end
context 'and is associated to any clusters' do
before do
create(:serverless_domain_cluster, pages_domain: domain)
end
it 'does not delete the domain' do
expect { delete :destroy, params: { id: domain.id } }
.not_to change { PagesDomain.count }
expect(response).to have_gitlab_http_status(:conflict)
expect(flash[:notice]).to include('Domain cannot be deleted while associated to one or more clusters.')
end
end
end
context 'when domain does not exist' 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