diff --git a/app/controllers/admin/auctions_controller.rb b/app/controllers/admin/auctions_controller.rb index 80793e086..5f2ff69cf 100644 --- a/app/controllers/admin/auctions_controller.rb +++ b/app/controllers/admin/auctions_controller.rb @@ -9,6 +9,7 @@ module Admin .with_status(params[:statuses_contains]) .with_start_created_at_date(params[:created_at_start]) .with_end_created_at_date(params[:created_at_end]) + .order(created_at: :desc) @auction = Auction.new @@ -28,7 +29,18 @@ module Admin end def create - auction = Auction.new(domain: params[:domain], status: Auction.statuses[:started], platform: 'manually') + auction = Auction.new(domain: params[:domain], status: Auction.statuses[:started], platform: 'manual') + + if domain_exists_in_blocked_disputed_and_registered?(params[:domain]) + flash[:alert] = "Adding #{params[:domain]} failed - domain registered or regsitration is blocked" + redirect_to admin_auctions_path and return + end + + result = check_availability(params[:domain])[0] + if result[:avail].zero? + flash[:alert] = "Cannot generate domain. Reason: #{result[:reason]}" + redirect_to admin_auctions_path and return + end if auction.save remove_from_reserved(auction) @@ -41,33 +53,62 @@ module Admin end def upload_spreadsheet + if params[:q].nil? + flash[:alert] = 'No file upload! Look at the left of upload button!' + redirect_to admin_auctions_path and return + end + filename = params[:q][:file] table = CSV.parse(File.read(filename), headers: true) + failed_names = [] + if validate_table(table) table.each do |row| record = row.to_h - auction = Auction.new(domain: record['name'], status: Auction.statuses[:started], platform: 'manually') + + if domain_exists_in_blocked_disputed_and_registered?(record['name']) + failed_names << record['name'] + + next + end + + result = check_availability(record['name'])[0] + if result[:avail].zero? + failed_names << record['name'] + + next + end + + auction = Auction.new(domain: record['name'], status: Auction.statuses[:started], platform: 'manual') remove_from_reserved(auction) if auction.save! end - flash[:notice] = "Domains added" - redirect_to admin_auctions_path + + flash[:notice] = 'Domains added!' + flash[:notice] = "Domains added! But these domains were ignored: #{failed_names.join(' ')}" if failed_names.present? else - flash[:alert] = "Invalid CSV format." - redirect_to admin_auctions_path + flash[:alert] = "Invalid CSV format. Should be column with 'name' where is the list of name of domains!" end + + redirect_to admin_auctions_path end private + def check_availability(domain_name) + Epp::Domain.check_availability(domain_name) + end + + def domain_exists_in_blocked_disputed_and_registered?(domain_name) + Domain.exists?(name: domain_name) || + BlockedDomain.exists?(name: domain_name) || + Dispute.exists?(domain_name: domain_name) || + Auction.exists?(domain: domain_name) + end + 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' + first_row.include? 'name' end def remove_from_reserved(auction) diff --git a/app/controllers/admin/reserved_domains_controller.rb b/app/controllers/admin/reserved_domains_controller.rb index 3812a2394..20957dec4 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: 'manually') + Auction.create!(domain: domain.name, status: Auction.statuses[:started], platform: 'manual') domain.destroy! end diff --git a/app/models/auction.rb b/app/models/auction.rb index d7d1e1c23..465a827ec 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[automatically manually] + enum platform: %i[auto manual] PENDING_STATUSES = [statuses[:started], statuses[:awaiting_payment], @@ -21,15 +21,15 @@ 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_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? + scope :with_end_created_at_date, ->(end_created_at) { + where('created_at <= ?', end_created_at) if end_created_at.present? } - scope :with_domain_name, -> (domain_name) { + scope :with_domain_name, ->(domain_name) { where('domain ilike ?', "%#{domain_name.strip}%") if domain_name.present? } diff --git a/app/models/dns/domain_name.rb b/app/models/dns/domain_name.rb index 5d89868ff..6c68c3797 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 = 'automatically' + auction.platform = 'auto' 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 9d530b80f..59063865e 100644 --- a/app/views/admin/auctions/index.html.erb +++ b/app/views/admin/auctions/index.html.erb @@ -108,7 +108,7 @@ <%= sort_link(@q, 'created_at') %> - + <%= sort_link(@q, 'registration_code') %> @@ -126,9 +126,9 @@ <%= colorize_auction(auction) %> <%= auction.status %> <%= auction.created_at %> - <%= auction.registration_code %> + <%= auction.registration_code %> <%= auction.registration_deadline %> - <%= auction.platform.nil? ? 'automatically' : auction.platform %> + <%= auction.platform.nil? ? 'auto' : auction.platform %> <% end %> diff --git a/app/views/admin/reserved_domains/index.html.erb b/app/views/admin/reserved_domains/index.html.erb index 6f1018875..109dbad9a 100644 --- a/app/views/admin/reserved_domains/index.html.erb +++ b/app/views/admin/reserved_domains/index.html.erb @@ -50,7 +50,10 @@
<%= form_for :reserved_elements, url: release_to_auction_admin_reserved_domains_path, html: { class: 'form-horizontal', autocomplete: 'off' } do |f| %> - <%= f.submit 'Send to the auction list', class: 'btn btn-primary', style: 'margin: 10px 0 20px 0;' %> +
+ <%= f.submit 'Send to the auction list', class: 'btn btn-primary', style: 'margin: 10px 0 20px 0;' %> + Domains will be removed from reserved list! +
diff --git a/db/structure.sql b/db/structure.sql index 8512da48e..2697c3147 100644 --- a/db/structure.sql +++ b/db/structure.sql @@ -5090,5 +5090,5 @@ INSERT INTO "schema_migrations" (version) VALUES ('20220413084748'), ('20220124105717'), ('20220216113112'), -('20220228093211'); +('20220228093211'), ('20220412130856');