Commit be65c3c1 authored by Grzegorz Bizon's avatar Grzegorz Bizon

Merge branch 'ali/198445-delete-serverless-domain' into 'master'

Add ability to delete an instance-level serverless domain (Backend)

See merge request gitlab-org/gitlab!25841
parents 0b14793d 6b955118
......@@ -2,7 +2,7 @@
class Admin::Serverless::DomainsController < Admin::ApplicationController
before_action :check_feature_flag
before_action :domain, only: [:update, :verify]
before_action :domain, only: [:update, :verify, :destroy]
def index
@domain = PagesDomain.instance_serverless.first_or_initialize
......@@ -30,6 +30,20 @@ class Admin::Serverless::DomainsController < Admin::ApplicationController
end
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,
status: :found,
notice: _('Domain was successfully deleted.')
end
def verify
result = VerifyPagesDomainService.new(domain).execute
......
......@@ -11,6 +11,7 @@ class PagesDomain < ApplicationRecord
belongs_to :project
has_many :acme_orders, class_name: "PagesDomainAcmeOrder"
has_many :serverless_domain_clusters, class_name: 'Serverless::DomainCluster', inverse_of: :pages_domain
validates :domain, hostname: { allow_numeric_hostname: true }
validates :domain, uniqueness: { case_sensitive: false }
......
......@@ -33,7 +33,7 @@ namespace :admin do
resources :gitaly_servers, only: [:index]
namespace :serverless do
resources :domains, only: [:index, :create, :update] do
resources :domains, only: [:index, :create, :update, :destroy] do
member do
post '/verify', to: 'domains#verify'
end
......
......@@ -6880,12 +6880,18 @@ 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 ""
msgid "Domain was successfully created."
msgstr ""
msgid "Domain was successfully deleted."
msgstr ""
msgid "Domain was successfully updated."
msgstr ""
......
......@@ -15,7 +15,7 @@ describe Admin::Serverless::DomainsController do
it 'responds with 404' do
get :index
expect(response.status).to eq(404)
expect(response).to have_gitlab_http_status(:not_found)
end
end
......@@ -33,7 +33,7 @@ describe Admin::Serverless::DomainsController do
it 'responds with 404' do
get :index
expect(response.status).to eq(404)
expect(response).to have_gitlab_http_status(:not_found)
end
end
......@@ -81,7 +81,7 @@ describe Admin::Serverless::DomainsController do
it 'responds with 404' do
post :create, params: { pages_domain: create_params }
expect(response.status).to eq(404)
expect(response).to have_gitlab_http_status(:not_found)
end
end
......@@ -98,7 +98,7 @@ describe Admin::Serverless::DomainsController do
it 'responds with 404' do
post :create, params: { pages_domain: create_params }
expect(response.status).to eq(404)
expect(response).to have_gitlab_http_status(:not_found)
end
end
......@@ -169,7 +169,7 @@ describe Admin::Serverless::DomainsController do
it 'responds with 404' do
put :update, params: { id: domain.id, pages_domain: update_params }
expect(response.status).to eq(404)
expect(response).to have_gitlab_http_status(:not_found)
end
end
......@@ -186,7 +186,7 @@ describe Admin::Serverless::DomainsController do
it 'responds with 404' do
put :update, params: { id: domain.id, pages_domain: update_params }
expect(response.status).to eq(404)
expect(response).to have_gitlab_http_status(:not_found)
end
end
......@@ -221,7 +221,7 @@ describe Admin::Serverless::DomainsController do
it 'returns 404' do
put :update, params: { id: 0, pages_domain: update_params }
expect(response.status).to eq(404)
expect(response).to have_gitlab_http_status(:not_found)
end
end
......@@ -247,7 +247,7 @@ describe Admin::Serverless::DomainsController do
it 'responds with 404' do
post :verify, params: { id: domain.id }
expect(response.status).to eq(404)
expect(response).to have_gitlab_http_status(:not_found)
end
end
......@@ -272,7 +272,7 @@ describe Admin::Serverless::DomainsController do
it 'responds with 404' do
post :verify, params: { id: domain.id }
expect(response.status).to eq(404)
expect(response).to have_gitlab_http_status(:not_found)
end
end
......@@ -295,4 +295,76 @@ describe Admin::Serverless::DomainsController do
end
end
end
describe '#destroy' do
let!(:domain) { create(:pages_domain, :instance_serverless) }
context 'non-admin user' do
before do
sign_in(user)
end
it 'responds with 404' do
delete :destroy, params: { id: domain.id }
expect(response).to have_gitlab_http_status(:not_found)
end
end
context 'admin user' do
before do
sign_in(admin)
end
context 'with serverless_domain feature disabled' do
before do
stub_feature_flags(serverless_domain: false)
end
it 'responds with 404' do
delete :destroy, params: { id: domain.id }
expect(response).to have_gitlab_http_status(:not_found)
end
end
context 'when domain exists' do
context 'and is not associated to any clusters' do
it 'deletes the domain' do
expect { delete :destroy, params: { id: domain.id } }
.to change { PagesDomain.count }.from(1).to(0)
expect(response).to have_gitlab_http_status(:found)
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
before do
domain.destroy!
end
it 'responds with 404' do
delete :destroy, params: { id: domain.id }
expect(response).to have_gitlab_http_status(:not_found)
end
end
end
end
end
......@@ -9,6 +9,7 @@ describe PagesDomain do
describe 'associations' do
it { is_expected.to belong_to(:project) }
it { is_expected.to have_many(:serverless_domain_clusters) }
end
describe 'validate domain' 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