From 3b9ff74bd24210798e94acb08d8434c7e72eff46 Mon Sep 17 00:00:00 2001 From: olegphenomenon Date: Fri, 22 Apr 2022 14:04:29 +0300 Subject: [PATCH] fix issues --- app/controllers/admin/auctions_controller.rb | 35 +++++++++++++++---- .../admin/reserved_domains_controller.rb | 2 +- app/models/auction.rb | 10 +++++- app/models/dns/domain_name.rb | 2 +- app/views/admin/auctions/index.html.erb | 26 +++++++++++--- app/views/admin/base/_menu.haml | 2 +- config/routes.rb | 3 ++ 7 files changed, 66 insertions(+), 14 deletions(-) diff --git a/app/controllers/admin/auctions_controller.rb b/app/controllers/admin/auctions_controller.rb index fc89c01f7..8e3e0ce3d 100644 --- a/app/controllers/admin/auctions_controller.rb +++ b/app/controllers/admin/auctions_controller.rb @@ -24,7 +24,7 @@ module Admin end def create - auction = Auction.new(domain: params[:domain], status: Auction.statuses[:started], platform: 'english') + auction = Auction.new(domain: params[:domain], status: Auction.statuses[:started], platform: 'manually') if auction.save remove_from_reserved(auction) @@ -40,17 +40,40 @@ module Admin filename = params[:q][:file] table = CSV.parse(File.read(filename), headers: true) - table.each do |row| - record = row.to_h - auction = Auction.new(domain: record['name'], status: Auction.statuses[:started], platform: 'english') - remove_from_reserved(auction) if auction.save! + if validate_table(table) + table.each do |row| + record = row.to_h + auction = Auction.new(domain: record['name'], status: Auction.statuses[:started], platform: 'manually') + remove_from_reserved(auction) if auction.save! + end + flash[:notice] = "Domains added" + redirect_to admin_auctions_path + else + flash[:alert] = "Invalid CSV format." + redirect_to admin_auctions_path end + end - redirect_to admin_auctions_path + def send_to_auction + auction = Auction.find(params[:id]) + + p ">>>>>.." + p auction + p ">>>>>>" end private + def validate_table(table) + first_row = table.headers + first_row[0] == 'id' && + first_row[1] == 'created_at' && + first_row[2] == 'updated_at' && + first_row[3] == 'creator_str' && + first_row[4] == 'updator_str' && + first_row[5] == 'name' + end + def remove_from_reserved(auction) domain = ReservedDomain.find_by(name: auction.domain) diff --git a/app/controllers/admin/reserved_domains_controller.rb b/app/controllers/admin/reserved_domains_controller.rb index 2daa6e068..3812a2394 100644 --- a/app/controllers/admin/reserved_domains_controller.rb +++ b/app/controllers/admin/reserved_domains_controller.rb @@ -58,7 +58,7 @@ module Admin reserved_domains = ReservedDomain.where(id: reserved_domains_ids) reserved_domains.each do |domain| - Auction.create!(domain: domain.name, status: Auction.statuses[:started], platform: 'english') + Auction.create!(domain: domain.name, status: Auction.statuses[:started], platform: 'manually') domain.destroy! end diff --git a/app/models/auction.rb b/app/models/auction.rb index 56acba7c6..cb0e9916d 100644 --- a/app/models/auction.rb +++ b/app/models/auction.rb @@ -9,7 +9,7 @@ class Auction < ApplicationRecord domain_not_registered: 'domain_not_registered', } - enum platform: %i[blind english] + enum platform: %i[automatically manually] PENDING_STATUSES = [statuses[:started], statuses[:awaiting_payment], @@ -21,6 +21,14 @@ class Auction < ApplicationRecord where(status: status) if status.present? } + scope :with_start_created_at_date, -> (start_created_at) { + where("created_at >= ?", start_created_at) if start_created_at.present? + } + + scope :with_end_created_at_date, -> (end_created_at) { + where("created_at <= ?", end_created_at) if end_created_at.present? + } + def self.pending(domain_name) find_by(domain: domain_name.to_s, status: PENDING_STATUSES) end diff --git a/app/models/dns/domain_name.rb b/app/models/dns/domain_name.rb index f914e3439..5d89868ff 100644 --- a/app/models/dns/domain_name.rb +++ b/app/models/dns/domain_name.rb @@ -35,7 +35,7 @@ module DNS def sell_at_auction auction = Auction.new auction.domain = name - auction.platform = 'blind' + auction.platform = 'automatically' auction.start ToStdout.msg "Created the auction: #{auction.inspect}" update_whois_from_auction(auction) diff --git a/app/views/admin/auctions/index.html.erb b/app/views/admin/auctions/index.html.erb index 52472e7fa..bae4a2239 100644 --- a/app/views/admin/auctions/index.html.erb +++ b/app/views/admin/auctions/index.html.erb @@ -41,11 +41,11 @@  
- <%= link_to(t('.reset_btn'), admin_auctions_path, class: 'btn btn-default') %> + <%= link_to('Clear', admin_auctions_path, class: 'btn btn-default') %>
<%= link_to 'Download auction list', admin_auctions_path(format: :csv, params: params.permit!), - "data-toggle" => "tooltip", "data-placement" => "bottom", "title" => t('.download_csv_btn'), + "data-toggle" => "tooltip", "data-placement" => "bottom", "title" => 'Download CSV', class: 'btn btn-primary' %>
@@ -114,10 +114,12 @@ <%= sort_link(@q, 'registration_deadline') %> - + <%= sort_link(@q, 'type') %> - + + Action + @@ -130,6 +132,11 @@ <%= auction.registration_code %> <%= auction.registration_deadline %> <%= auction.platform %> + + <%= button_tag type: 'button', data: { confirm: "Are you sure?" }, class: 'btn btn-primary' do %> + <% link_to 'Send to auction', send_to_auction_admin_auction_path(auction), method: :post, style: "color: white;" %> + <% end %> + <% end %> @@ -138,6 +145,17 @@
+
+
+ <%= paginate @auctions %> +
+
+ +
+
+