diff --git a/app/controllers/admin/auctions_controller.rb b/app/controllers/admin/auctions_controller.rb index c1023b705..05bfc239f 100644 --- a/app/controllers/admin/auctions_controller.rb +++ b/app/controllers/admin/auctions_controller.rb @@ -44,7 +44,7 @@ module Admin if auction.save reserved_domain = auction.domain if remove_from_reserved(auction) - flash[:notice] = "Auction #{params[:domain]} created. + flash[:notice] = "Auction #{params[:domain]} created. #{reserved_domain.present? ? 'These domain will be removed from reserved list: ' + reserved_domain : ' '}" else flash[:alert] = 'Something goes wrong' @@ -53,6 +53,18 @@ module Admin redirect_to admin_auctions_path end + def destroy + auction = Auction.find(params[:id]) + + if auction.destroy + flash[:notice] = I18n.t('record_deleted') + else + flash.now[:alert] = I18n.t('failed_to_delete_record') + end + + redirect_to admin_auctions_path + end + def upload_spreadsheet if params[:q].nil? flash[:alert] = 'No file upload! Look at the left of upload button!' diff --git a/app/views/admin/auctions/index.html.erb b/app/views/admin/auctions/index.html.erb index 85d533fa7..21cd0ab57 100644 --- a/app/views/admin/auctions/index.html.erb +++ b/app/views/admin/auctions/index.html.erb @@ -129,6 +129,7 @@ <%= auction.registration_code %> <%= auction.registration_deadline %> <%= auction.platform.nil? ? 'auto' : auction.platform %> + <%= link_to(t(:delete), admin_auction_path(auction), method: :delete, data: { confirm: t(:are_you_sure_you_want_to_delete_auction) }, class: 'btn btn-danger', id: "delete-auction-#{auction.id}") %> <% end %> @@ -152,4 +153,4 @@ $('#user-form-edit').on("show.bs.modal", function(e) { $(this).find('.modal-body').load(e.relatedTarget.dataset.url); }); - \ No newline at end of file + diff --git a/config/locales/en.yml b/config/locales/en.yml index 4d1d9a52c..2eda989b3 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -440,6 +440,7 @@ en: exDate: 'Valid to' dequeue: 'Dequeue' are_you_sure_you_want_to_delete_domain: 'Are you sure you want to delete domain %{domain}?' + are_you_sure_you_want_to_delete_auction: 'Warning: Are you sure you want to delete this record? Be advised that doing so will remove the record only from registry database and will make the domain available for anyone to register. This will not affect auction system if the auction record is already created there. You will need to delete the record in auction system first to remove the domain from auction.' upload_key: 'Upload key' legal_document: 'Legal document' legal_document_max_size: '(max. 8MB)' diff --git a/config/routes.rb b/config/routes.rb index fc4a188fd..26b57b42b 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -306,7 +306,7 @@ Rails.application.routes.draw do resources :accounts resources :account_activities - resources :auctions, only: [ :index, :create ] do + resources :auctions, only: %i[index create destroy] do collection do post 'upload_spreadsheet', to: 'auctions#upload_spreadsheet', as: :upload_spreadsheet end diff --git a/test/integration/admin_area/auction_test.rb b/test/integration/admin_area/auction_test.rb index c51465ab2..54bd64456 100644 --- a/test/integration/admin_area/auction_test.rb +++ b/test/integration/admin_area/auction_test.rb @@ -170,4 +170,15 @@ class AdminAreaAuctionIntegrationTest < ApplicationSystemTestCase find(:id, "reserved-modal", match: :first).click assert_text 'Reserved domains' end + + def test_delete_auction + visit admin_auctions_path + domain = Auction.first + + find(:id, "delete-auction-#{domain.id}", match: :first).click + + assert_raises ActiveRecord::RecordNotFound do + domain.reload + end + end end