From 42946dfa15ede2cbda5adfdb6ab773a18f6b0761 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karl=20Erik=20=C3=95unapuu?= Date: Mon, 27 Apr 2020 10:56:27 +0300 Subject: [PATCH] Add closed disputed sections to disputes view --- app/controllers/admin/disputes_controller.rb | 8 +- app/models/dispute.rb | 17 +- app/views/admin/disputes/index.haml | 69 ------- app/views/admin/disputes/index.html.erb | 182 +++++++++++++++++++ 4 files changed, 202 insertions(+), 74 deletions(-) delete mode 100644 app/views/admin/disputes/index.haml create mode 100644 app/views/admin/disputes/index.html.erb diff --git a/app/controllers/admin/disputes_controller.rb b/app/controllers/admin/disputes_controller.rb index 8d26db614..25bb41bf8 100644 --- a/app/controllers/admin/disputes_controller.rb +++ b/app/controllers/admin/disputes_controller.rb @@ -8,10 +8,16 @@ module Admin # GET /admin/disputes def index params[:q] ||= {} - disputes = Dispute.all.order(:domain_name) + disputes = Dispute.active.all.order(:domain_name) + @q = disputes.search(params[:q]) @disputes = @q.result.page(params[:page]) @disputes = @disputes.per(params[:results_per_page]) if params[:results_per_page].to_i.positive? + + closed_disputes = Dispute.closed.order(:domain_name) + @closed_q = closed_disputes.search(params[:closed_q]) + @closed_disputes = @closed_q.result.page(params[:closed_page]) + @closed_disputes = @closed_disputes.per(params[:results_per_page]) if params[:results_per_page].to_i.positive? end # GET /admin/disputes/1 diff --git a/app/models/dispute.rb b/app/models/dispute.rb index 450a92a2b..a1fa45501 100644 --- a/app/models/dispute.rb +++ b/app/models/dispute.rb @@ -2,10 +2,10 @@ class Dispute < ApplicationRecord validates :domain_name, :password, :starts_at, :expires_at, presence: true - validates_uniqueness_of :domain_name, case_sensitive: true before_validation :fill_empty_passwords before_validation :set_expiry_date - validate :validate_domain_name + validate :validate_domain_name_format + validate :validate_domain_name_period_uniqueness with_options on: :admin do validate :validate_start_date @@ -15,7 +15,7 @@ class Dispute < ApplicationRecord after_destroy :remove_data scope :expired, -> { where('expires_at < ?', Time.zone.today) } - scope :active, -> { where('expires_at > ? AND closed = 0', Time.zone.today) } + scope :active, -> { where('expires_at > ? AND closed = false', Time.zone.today) } scope :closed, -> { where(closed: true) } alias_attribute :name, :domain_name @@ -78,7 +78,7 @@ class Dispute < ApplicationRecord errors.add(:starts_at, :past) if starts_at.past? end - def validate_domain_name + def validate_domain_name_format return unless domain_name zone = domain_name.split('.').last @@ -86,4 +86,13 @@ class Dispute < ApplicationRecord errors.add(:domain_name, :unsupported_zone) unless supported_zone end + + def validate_domain_name_period_uniqueness + return unless new_record? + + existing_dispute = Dispute.unscoped.where(domain_name: domain_name, closed: false).where('expires_at > ?', starts_at) + return unless existing_dispute.any? + + errors.add(:base, 'Dispute already exists for this domain at given timeframe') + end end diff --git a/app/views/admin/disputes/index.haml b/app/views/admin/disputes/index.haml deleted file mode 100644 index 86ba2a093..000000000 --- a/app/views/admin/disputes/index.haml +++ /dev/null @@ -1,69 +0,0 @@ -- content_for :actions do - = link_to(t('.new_btn'), new_admin_dispute_path, class: 'btn btn-primary') -= render 'shared/title', name: t('.title') - -.row - .col-md-12 - = search_form_for [:admin, @q], html: { style: 'margin-bottom: 0;', class: 'js-form', autocomplete: 'off' } do |f| - .row - .col-md-3 - .form-group - = f.label :name - = f.search_field :name_matches, value: params[:q][:name_matches], class: 'form-control', placeholder: t(:name) - .col-md-3 - .form-group - = f.label t(:created_at_from) - = f.search_field :created_at_gteq, value: params[:q][:created_at_gteq], class: 'form-control js-datepicker', placeholder: t(:created_at_from) - .col-md-3 - .form-group - = f.label t(:created_at_until) - = f.search_field :created_at_lteq, value: params[:q][:created_at_lteq], class: 'form-control js-datepicker', placeholder: t(:created_at_until) - .row - .col-md-3 - .form-group - = label_tag t(:results_per_page) - = text_field_tag :results_per_page, params[:results_per_page], class: 'form-control', placeholder: t(:results_per_page) - .col-md-3{style: 'padding-top: 25px;'} - %button.btn.btn-primary -   - %span.glyphicon.glyphicon-search -   - = link_to(t('.reset_btn'), admin_disputes_path, class: 'btn btn-default') -%hr -.row - .col-md-12 - .table-responsive - %table.table.table-hover.table-bordered.table-condensed - %thead - %tr - %th{class: 'col-xs-2'} - = sort_link(@q, 'name') - %th{class: 'col-xs-2'} - = sort_link(@q, 'password') - %th{class: 'col-xs-2'} - = sort_link(@q, 'starts_at') - %th{class: 'col-xs-2'} - = sort_link(@q, 'expires_at') - %th{class: 'col-xs-2'} - = sort_link(@q, 'comment') - %th{class: 'col-xs-2'} - = t(:actions) - %tbody - - @disputes.each do |x| - %tr - %td= x.domain_name - %td= x.password - %td= x.starts_at - %td= x.expires_at - %td= x.comment - %td - = link_to(t(:edit), edit_admin_dispute_path(id: x.id), - class: 'btn btn-primary btn-xs') - = link_to(t(:delete), delete_admin_dispute_path(id: x.id), - data: { confirm: t(:are_you_sure) }, class: 'btn btn-danger btn-xs') -.row - .col-md-6 - = paginate @disputes - .col-md-6.text-right - .pagination - = t(:result_count, count: @disputes.total_count) diff --git a/app/views/admin/disputes/index.html.erb b/app/views/admin/disputes/index.html.erb new file mode 100644 index 000000000..eea74f59a --- /dev/null +++ b/app/views/admin/disputes/index.html.erb @@ -0,0 +1,182 @@ +<% content_for :actions do %> +<%= link_to(t('.new_btn'), new_admin_dispute_path, class: 'btn btn-primary') %> +<% end %> +<%= render 'shared/title', name: t('.title') %> +
+
+ <%= search_form_for [:admin, @q], html: { style: 'margin-bottom: 0;', class: 'js-form', autocomplete: 'off' } do |f| %> +
+
+
+ <%= f.label :name %> + <%= f.search_field :name_matches, value: params[:q][:name_matches], class: 'form-control', placeholder: t(:name) %> +
+
+
+
+ <%= f.label t(:created_at_from) %> + <%= f.search_field :created_at_gteq, value: params[:q][:created_at_gteq], class: 'form-control js-datepicker', placeholder: t(:created_at_from) %> +
+
+
+
+ <%= f.label t(:created_at_until) %> + <%= f.search_field :created_at_lteq, value: params[:q][:created_at_lteq], class: 'form-control js-datepicker', placeholder: t(:created_at_until) %> +
+
+
+
+
+
+ <%= label_tag t(:results_per_page) %> + <%= text_field_tag :results_per_page, params[:results_per_page], class: 'form-control', placeholder: t(:results_per_page) %> +
+
+
+ + <%= link_to(t('.reset_btn'), admin_disputes_path, class: 'btn btn-default') %> +
+
+ <% end %> +
+
+
+

Active disputes

+
+
+
+ + + + + + + + + + + + + <% @disputes.each do |x| %> + + + + + + + + + <% end %> + +
+ <%= sort_link(@q, 'name') %> + + <%= sort_link(@q, 'password') %> + + <%= sort_link(@q, 'starts_at') %> + + <%= sort_link(@q, 'expires_at') %> + + <%= sort_link(@q, 'comment') %> + + <%= t(:actions) %> +
+ <%= x.domain_name %> + + <%= x.password %> + + <%= x.starts_at %> + + <%= x.expires_at %> + + <%= x.comment %> + + <%= link_to t(:edit), edit_admin_dispute_path(id: x.id), + class: 'btn btn-primary btn-xs' %> + <%= link_to t(:delete), delete_admin_dispute_path(id: x.id), + data: { confirm: t(:are_you_sure) }, class: 'btn btn-danger btn-xs' %> +
+
+
+
+
+
+ <%= paginate @disputes %> +
+
+ +
+
+
+

Expired / Closed disputes

+
+
+
+ + + + + + + + + + + + + <% @closed_disputes.each do |x| %> + + + + + + + + + <% end %> + +
+ <%= sort_link(@q, 'name') %> + + <%= sort_link(@q, 'password') %> + + <%= sort_link(@q, 'starts_at') %> + + <%= sort_link(@q, 'expires_at') %> + + <%= sort_link(@q, 'comment') %> + + <%= t(:actions) %> +
+ <%= x.domain_name %> + + <%= x.password %> + + <%= x.starts_at %> + + <%= x.expires_at %> + + <%= x.comment %> + + <%= link_to t(:delete), delete_admin_dispute_path(id: x.id), + data: { confirm: t(:are_you_sure) }, class: 'btn btn-danger btn-xs' %> +
+
+
+
+
+
+ <%= paginate @closed_disputes %> +
+
+ +
+