Disputes: Show when and who closed dispute

This commit is contained in:
Karl Erik Õunapuu 2020-05-18 15:11:34 +03:00
parent 26a5813fe9
commit c682155bf6
9 changed files with 48 additions and 31 deletions

View file

@ -44,7 +44,7 @@ module Admin
# DELETE /admin/disputes/1 # DELETE /admin/disputes/1
def delete def delete
@dispute.close @dispute.close(initiator: 'Admin')
redirect_to admin_disputes_url, notice: 'Dispute was successfully closed.' redirect_to admin_disputes_url, notice: 'Dispute was successfully closed.'
end end

View file

@ -31,10 +31,7 @@ class Registrant::DomainUpdateConfirmsController < RegistrantController
end end
elsif params[:confirmed] elsif params[:confirmed]
if @registrant_verification.domain_registrant_change_confirm!("email link, #{initiator}") if @registrant_verification.domain_registrant_change_confirm!("email link, #{initiator}")
if @domain.disputed? Dispute.close_by_domain(@domain.name) if @domain.disputed?
dispute = Dispute.active.find_by(domain_name: @domain.name)
dispute.close
end
flash[:notice] = t(:registrant_domain_verification_confirmed) flash[:notice] = t(:registrant_domain_verification_confirmed)
redirect_to registrant_domain_update_confirm_path(@domain.id, confirmed: true) redirect_to registrant_domain_update_confirm_path(@domain.id, confirmed: true)

View file

@ -13,7 +13,7 @@ class DisputeStatusUpdateJob < Que::Job
end end
def close_disputes def close_disputes
disputes = Dispute.where(closed: false).where('expires_at < ?', Time.zone.today).all disputes = Dispute.where(closed: nil).where('expires_at < ?', Time.zone.today).all
Rails.logger.info "DisputeStatusUpdateJob - Found #{disputes.count} closable disputes" Rails.logger.info "DisputeStatusUpdateJob - Found #{disputes.count} closable disputes"
disputes.each do |dispute| disputes.each do |dispute|
process_dispute(dispute, closing: true) process_dispute(dispute, closing: true)
@ -21,7 +21,7 @@ class DisputeStatusUpdateJob < Que::Job
end end
def activate_disputes def activate_disputes
disputes = Dispute.where(closed: false, starts_at: Time.zone.today).all disputes = Dispute.where(closed: nil, starts_at: Time.zone.today).all
Rails.logger.info "DisputeStatusUpdateJob - Found #{disputes.count} activatable disputes" Rails.logger.info "DisputeStatusUpdateJob - Found #{disputes.count} activatable disputes"
disputes.each do |dispute| disputes.each do |dispute|
@ -31,7 +31,7 @@ class DisputeStatusUpdateJob < Que::Job
def process_dispute(dispute, closing: false) def process_dispute(dispute, closing: false)
intent = closing ? 'close' : 'activate' intent = closing ? 'close' : 'activate'
success = closing ? dispute.close : dispute.generate_data success = closing ? dispute.close(initiator: 'Job') : dispute.generate_data
create_backlog_entry(dispute: dispute, intent: intent, successful: success) create_backlog_entry(dispute: dispute, intent: intent, successful: success)
end end

View file

@ -10,9 +10,9 @@ class Dispute < ApplicationRecord
scope :expired, -> { where('expires_at < ?', Time.zone.today) } scope :expired, -> { where('expires_at < ?', Time.zone.today) }
scope :active, lambda { scope :active, lambda {
where('starts_at <= ? AND expires_at >= ? AND closed = false', Time.zone.today, Time.zone.today) where('starts_at <= ? AND expires_at >= ? AND closed IS NULL', Time.zone.today, Time.zone.today)
} }
scope :closed, -> { where(closed: true) } scope :closed, -> { where.not(closed: nil) }
attr_readonly :domain_name attr_readonly :domain_name
@ -24,7 +24,7 @@ class Dispute < ApplicationRecord
dispute = Dispute.active.find_by(domain_name: domain_name) dispute = Dispute.active.find_by(domain_name: domain_name)
return false unless dispute return false unless dispute
dispute.close dispute.close(initiator: 'Registrant')
end end
def self.valid_auth?(domain_name, password) def self.valid_auth?(domain_name, password)
@ -52,8 +52,8 @@ class Dispute < ApplicationRecord
wr.save wr.save
end end
def close def close(initiator: 'Unknown')
return false unless update(closed: true) return false unless update(closed: Time.zone.now, initiator: initiator)
return if Dispute.active.where(domain_name: domain_name).any? return if Dispute.active.where(domain_name: domain_name).any?
domain&.unmark_as_disputed domain&.unmark_as_disputed
@ -129,7 +129,7 @@ class Dispute < ApplicationRecord
end end
def validate_domain_name_period_uniqueness def validate_domain_name_period_uniqueness
existing_dispute = Dispute.unscoped.where(domain_name: domain_name, closed: false) existing_dispute = Dispute.unscoped.where(domain_name: domain_name, closed: nil)
.where('expires_at >= ?', starts_at) .where('expires_at >= ?', starts_at)
existing_dispute = existing_dispute.where.not(id: id) unless new_record? existing_dispute = existing_dispute.where.not(id: id) unless new_record?

View file

@ -125,13 +125,13 @@
<%= sort_link(@q, 'name') %> <%= sort_link(@q, 'name') %>
</th> </th>
<th class="col-xs-2"> <th class="col-xs-2">
<%= sort_link(@q, 'password') %> <%= sort_link(@q, 'Initiator') %>
</th> </th>
<th class="col-xs-2"> <th class="col-xs-2">
<%= sort_link(@q, 'starts_at') %> <%= sort_link(@q, 'starts_at') %>
</th> </th>
<th class="col-xs-2"> <th class="col-xs-2">
<%= sort_link(@q, 'expires_at') %> <%= sort_link(@q, 'Expired/Closed At') %>
</th> </th>
<th class="col-xs-2"> <th class="col-xs-2">
<%= sort_link(@q, 'comment') %> <%= sort_link(@q, 'comment') %>
@ -145,13 +145,13 @@
<%= x.domain_name %> <%= x.domain_name %>
</td> </td>
<td> <td>
<%= x.password %> <%= x.initiator %>
</td> </td>
<td> <td>
<%= x.starts_at %> <%= x.starts_at %>
</td> </td>
<td> <td>
<%= x.expires_at %> <%= x.closed %>
</td> </td>
<td> <td>
<%= x.comment %> <%= x.comment %>

View file

@ -0,0 +1,19 @@
class AddClosedDateTimeAndUpdatorToDispute < ActiveRecord::Migration[5.2]
def up
rename_column :disputes, :closed, :closed_boolean
add_column :disputes, :closed, :datetime
execute 'UPDATE disputes SET closed = updated_at WHERE closed_boolean = true'
execute 'UPDATE disputes SET closed = NULL WHERE closed_boolean = false'
remove_column :disputes, :closed_boolean
add_column :disputes, :initiator, :string
end
def down
rename_column :disputes, :closed, :closed_datetime
add_column :disputes, :closed, :boolean, null: false, default: false
execute 'UPDATE disputes SET closed = true WHERE closed_datetime != NULL'
execute 'UPDATE disputes SET closed = false WHERE closed_datetime = NULL'
remove_column :disputes, :closed_datetime
remove_column :disputes, :initiator
end
end

View file

@ -1,6 +1,6 @@
-- ---
-- PostgreSQL database dump --- PostgreSQL database dump
-- ---
SET statement_timeout = 0; SET statement_timeout = 0;
SET lock_timeout = 0; SET lock_timeout = 0;
@ -605,9 +605,10 @@ CREATE TABLE public.disputes (
expires_at date NOT NULL, expires_at date NOT NULL,
starts_at date NOT NULL, starts_at date NOT NULL,
comment text, comment text,
closed boolean DEFAULT false NOT NULL,
created_at timestamp without time zone NOT NULL, created_at timestamp without time zone NOT NULL,
updated_at timestamp without time zone NOT NULL updated_at timestamp without time zone NOT NULL,
closed timestamp without time zone,
initiator character varying
); );
@ -4520,5 +4521,7 @@ INSERT INTO "schema_migrations" (version) VALUES
('20200417075720'), ('20200417075720'),
('20200421093637'), ('20200421093637'),
('20200505103316'), ('20200505103316'),
('20200505150413'); ('20200505150413'),
('20200518104105');

View file

@ -3,22 +3,20 @@ active:
password: active-001 password: active-001
starts_at: <%= Date.parse '2010-07-05' %> starts_at: <%= Date.parse '2010-07-05' %>
expires_at: <%= Date.parse '2013-07-05' %> expires_at: <%= Date.parse '2013-07-05' %>
closed: false
future: future:
domain_name: future-dispute.test domain_name: future-dispute.test
password: active-001 password: active-001
starts_at: <%= Date.parse '2010-10-05' %> starts_at: <%= Date.parse '2010-10-05' %>
expires_at: <%= Date.parse '2013-10-05' %> expires_at: <%= Date.parse '2013-10-05' %>
closed: false
expired: expired:
domain_name: expired-dispute.test domain_name: expired-dispute.test
password: active-001 password: active-001
starts_at: <%= Date.parse '2010-07-05' %> starts_at: <%= Date.parse '2010-07-05' %>
expires_at: <%= Date.parse '2013-07-05' %> expires_at: <%= Date.parse '2013-07-05' %>
closed: true closed: <%= Date.parse '2013-07-05' %>
closed: closed:
domain_name: closed_dispute.test domain_name: closed_dispute.test
password: active-001 password: active-001
starts_at: <%= Date.parse '2010-07-05' %> starts_at: <%= Date.parse '2010-07-05' %>
expires_at: <%= Date.parse '2013-07-05' %> expires_at: <%= Date.parse '2013-07-05' %>
closed: true closed: <%= Date.parse '2013-07-05' %>

View file

@ -18,7 +18,7 @@ class AdminDisputesSystemTest < ApplicationSystemTestCase
assert_nil Dispute.active.find_by(domain_name: 'disputed.test') assert_nil Dispute.active.find_by(domain_name: 'disputed.test')
visit admin_disputes_path visit admin_disputes_path
click_on 'New domain dispute' click_on 'New disputed domain'
fill_in 'Domain name', with: 'disputed.test' fill_in 'Domain name', with: 'disputed.test'
fill_in 'Password', with: '1234' fill_in 'Password', with: '1234'
@ -34,7 +34,7 @@ class AdminDisputesSystemTest < ApplicationSystemTestCase
assert_nil Dispute.active.find_by(domain_name: 'disputed.test') assert_nil Dispute.active.find_by(domain_name: 'disputed.test')
visit admin_disputes_path visit admin_disputes_path
click_on 'New domain dispute' click_on 'New disputed domain'
fill_in 'Domain name', with: 'disputed.test' fill_in 'Domain name', with: 'disputed.test'
fill_in 'Password', with: '1234' fill_in 'Password', with: '1234'
@ -65,7 +65,7 @@ class AdminDisputesSystemTest < ApplicationSystemTestCase
def test_can_not_create_overlapping_dispute def test_can_not_create_overlapping_dispute
visit admin_disputes_path visit admin_disputes_path
click_on 'New domain dispute' click_on 'New disputed domain'
fill_in 'Domain name', with: 'active-dispute.test' fill_in 'Domain name', with: 'active-dispute.test'
fill_in 'Starts at', with: @dispute.starts_at + 1.day fill_in 'Starts at', with: @dispute.starts_at + 1.day