Commit 004dbe1c authored by Alishan Ladhani's avatar Alishan Ladhani

Add ability to delete a serverless domain

- Create route for destroy
- Create destroy action
parent 2d242119
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
class Admin::Serverless::DomainsController < Admin::ApplicationController class Admin::Serverless::DomainsController < Admin::ApplicationController
before_action :check_feature_flag before_action :check_feature_flag
before_action :domain, only: [:update, :verify] before_action :domain, only: [:update, :verify, :destroy]
def index def index
@domain = PagesDomain.instance_serverless.first_or_initialize @domain = PagesDomain.instance_serverless.first_or_initialize
...@@ -30,6 +30,14 @@ class Admin::Serverless::DomainsController < Admin::ApplicationController ...@@ -30,6 +30,14 @@ class Admin::Serverless::DomainsController < Admin::ApplicationController
end end
end end
def destroy
domain.destroy!
redirect_to admin_serverless_domains_path,
status: :found,
notice: _('Domain was successfully deleted.')
end
def verify def verify
result = VerifyPagesDomainService.new(domain).execute result = VerifyPagesDomainService.new(domain).execute
......
...@@ -33,7 +33,7 @@ namespace :admin do ...@@ -33,7 +33,7 @@ namespace :admin do
resources :gitaly_servers, only: [:index] resources :gitaly_servers, only: [:index]
namespace :serverless do namespace :serverless do
resources :domains, only: [:index, :create, :update] do resources :domains, only: [:index, :create, :update, :destroy] do
member do member do
post '/verify', to: 'domains#verify' post '/verify', to: 'domains#verify'
end end
......
...@@ -6886,6 +6886,9 @@ msgstr "" ...@@ -6886,6 +6886,9 @@ msgstr ""
msgid "Domain was successfully created." msgid "Domain was successfully created."
msgstr "" msgstr ""
msgid "Domain was successfully deleted."
msgstr ""
msgid "Domain was successfully updated." msgid "Domain was successfully updated."
msgstr "" msgstr ""
......
...@@ -295,4 +295,62 @@ describe Admin::Serverless::DomainsController do ...@@ -295,4 +295,62 @@ describe Admin::Serverless::DomainsController do
end end
end 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
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 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