From 3dd17f83f36fd2813304e69dc4a2a473b302a7f6 Mon Sep 17 00:00:00 2001 From: Artur Beljajev Date: Sun, 8 Apr 2018 22:55:53 +0300 Subject: [PATCH 01/72] Remove unneeded attribute alias #791 --- app/models/concerns/domain/force_delete.rb | 4 ---- app/presenters/domain_presenter.rb | 2 +- app/views/admin/domains/partials/_general.html.erb | 4 ++-- config/locales/admin/domains.en.yml | 1 - spec/models/concerns/domain/force_delete_spec.rb | 2 -- spec/presenters/domain_presenter_spec.rb | 4 ++-- 6 files changed, 5 insertions(+), 12 deletions(-) diff --git a/app/models/concerns/domain/force_delete.rb b/app/models/concerns/domain/force_delete.rb index 96f1a94b3..30dc1b1ec 100644 --- a/app/models/concerns/domain/force_delete.rb +++ b/app/models/concerns/domain/force_delete.rb @@ -1,10 +1,6 @@ module Concerns::Domain::ForceDelete extend ActiveSupport::Concern - included do - alias_attribute :force_delete_time, :force_delete_at - end - def force_delete_scheduled? statuses.include?(DomainStatus::FORCE_DELETE) end diff --git a/app/presenters/domain_presenter.rb b/app/presenters/domain_presenter.rb index 9597330b8..cf117a1fb 100644 --- a/app/presenters/domain_presenter.rb +++ b/app/presenters/domain_presenter.rb @@ -23,7 +23,7 @@ class DomainPresenter end def force_delete_date - view.l(domain.force_delete_time, format: :date) if domain.force_delete_time + view.l(domain.force_delete_at, format: :date) if domain.force_delete_at end def admin_contact_names diff --git a/app/views/admin/domains/partials/_general.html.erb b/app/views/admin/domains/partials/_general.html.erb index eeeef6eb5..0c2da7bbd 100644 --- a/app/views/admin/domains/partials/_general.html.erb +++ b/app/views/admin/domains/partials/_general.html.erb @@ -34,8 +34,8 @@
<%= t('.delete_time') %>
<%= l(@domain.delete_at) %>
-
<%= t('.force_delete_time') %>
-
<%= l(@domain.force_delete_at) %>
+
<%= Domain.human_attribute_name :force_delete_at %>
+
<%= l @domain.force_delete_at %>
diff --git a/config/locales/admin/domains.en.yml b/config/locales/admin/domains.en.yml index 200657d01..8d66347ae 100644 --- a/config/locales/admin/domains.en.yml +++ b/config/locales/admin/domains.en.yml @@ -29,7 +29,6 @@ en: general: outzone_time: Outzone time delete_time: Delete time - force_delete_time: Force delete time admin_contacts: title: Admin. contacts diff --git a/spec/models/concerns/domain/force_delete_spec.rb b/spec/models/concerns/domain/force_delete_spec.rb index cc022a6d7..8a82faa8e 100644 --- a/spec/models/concerns/domain/force_delete_spec.rb +++ b/spec/models/concerns/domain/force_delete_spec.rb @@ -1,8 +1,6 @@ require 'rails_helper' RSpec.describe Domain do - it { is_expected.to alias_attribute(:force_delete_time, :force_delete_at) } - before :example do create(:zone, origin: 'ee') end diff --git a/spec/presenters/domain_presenter_spec.rb b/spec/presenters/domain_presenter_spec.rb index 3726960b4..c83ca58ca 100644 --- a/spec/presenters/domain_presenter_spec.rb +++ b/spec/presenters/domain_presenter_spec.rb @@ -63,7 +63,7 @@ RSpec.describe DomainPresenter do subject(:force_delete_date) { presenter.force_delete_date } context 'when present' do - let(:domain) { instance_double(Domain, force_delete_time: '05.07.2010') } + let(:domain) { instance_double(Domain, force_delete_at: '05.07.2010') } it 'returns localized date' do expect(view).to receive(:l).with('05.07.2010', format: :date).and_return('delete date') @@ -72,7 +72,7 @@ RSpec.describe DomainPresenter do end context 'when absent' do - let(:domain) { instance_double(Domain, force_delete_time: nil) } + let(:domain) { instance_double(Domain, force_delete_at: nil) } specify { expect(force_delete_date).to be_nil } end From be8ce276c71a6b2ec2736bef23cb17582a13b940 Mon Sep 17 00:00:00 2001 From: Artur Beljajev Date: Sat, 21 Apr 2018 23:27:09 +0300 Subject: [PATCH 02/72] Refactor domain "force delete" operation #791 --- app/models/concerns/domain/force_delete.rb | 45 ++++---- .../concerns/domain/force_delete_spec.rb | 100 ------------------ test/models/domain/force_delete_test.rb | 40 +++++++ 3 files changed, 61 insertions(+), 124 deletions(-) delete mode 100644 spec/models/concerns/domain/force_delete_spec.rb create mode 100644 test/models/domain/force_delete_test.rb diff --git a/app/models/concerns/domain/force_delete.rb b/app/models/concerns/domain/force_delete.rb index 30dc1b1ec..ec5c651be 100644 --- a/app/models/concerns/domain/force_delete.rb +++ b/app/models/concerns/domain/force_delete.rb @@ -6,21 +6,6 @@ module Concerns::Domain::ForceDelete end def schedule_force_delete - self.statuses_backup = statuses - statuses.delete(DomainStatus::CLIENT_DELETE_PROHIBITED) - statuses.delete(DomainStatus::SERVER_DELETE_PROHIBITED) - statuses.delete(DomainStatus::PENDING_UPDATE) - statuses.delete(DomainStatus::PENDING_TRANSFER) - statuses.delete(DomainStatus::PENDING_RENEW) - statuses.delete(DomainStatus::PENDING_CREATE) - - statuses.delete(DomainStatus::FORCE_DELETE) - statuses.delete(DomainStatus::SERVER_RENEW_PROHIBITED) - statuses.delete(DomainStatus::SERVER_TRANSFER_PROHIBITED) - statuses.delete(DomainStatus::SERVER_UPDATE_PROHIBITED) - statuses.delete(DomainStatus::SERVER_MANUAL_INZONE) - statuses.delete(DomainStatus::PENDING_DELETE) - statuses << DomainStatus::FORCE_DELETE statuses << DomainStatus::SERVER_RENEW_PROHIBITED statuses << DomainStatus::SERVER_TRANSFER_PROHIBITED @@ -31,20 +16,32 @@ module Concerns::Domain::ForceDelete statuses << DomainStatus::SERVER_MANUAL_INZONE end - self.force_delete_at = (Time.zone.now + (Setting.redemption_grace_period.days + 1.day)).utc.beginning_of_day unless force_delete_at - save!(validate: false) + self.force_delete_at = (Time.zone.now + (Setting.redemption_grace_period.days + 1.day)).utc + .beginning_of_day + stop_all_pending_actions + save(validate: false) end def cancel_force_delete - s = [] - s << DomainStatus::EXPIRED if statuses.include?(DomainStatus::EXPIRED) - s << DomainStatus::SERVER_HOLD if statuses.include?(DomainStatus::SERVER_HOLD) - s << DomainStatus::DELETE_CANDIDATE if statuses.include?(DomainStatus::DELETE_CANDIDATE) - - self.statuses = (statuses_backup + s).uniq + statuses.delete(DomainStatus::FORCE_DELETE) + statuses.delete(DomainStatus::SERVER_RENEW_PROHIBITED) + statuses.delete(DomainStatus::SERVER_TRANSFER_PROHIBITED) + statuses.delete(DomainStatus::SERVER_UPDATE_PROHIBITED) + statuses.delete(DomainStatus::PENDING_DELETE) + statuses.delete(DomainStatus::SERVER_MANUAL_INZONE) self.force_delete_at = nil - self.statuses_backup = [] save(validate: false) end + + private + + def stop_all_pending_actions + statuses.delete(DomainStatus::CLIENT_DELETE_PROHIBITED) + statuses.delete(DomainStatus::SERVER_DELETE_PROHIBITED) + statuses.delete(DomainStatus::PENDING_UPDATE) + statuses.delete(DomainStatus::PENDING_TRANSFER) + statuses.delete(DomainStatus::PENDING_RENEW) + statuses.delete(DomainStatus::PENDING_CREATE) + end end diff --git a/spec/models/concerns/domain/force_delete_spec.rb b/spec/models/concerns/domain/force_delete_spec.rb deleted file mode 100644 index 8a82faa8e..000000000 --- a/spec/models/concerns/domain/force_delete_spec.rb +++ /dev/null @@ -1,100 +0,0 @@ -require 'rails_helper' - -RSpec.describe Domain do - before :example do - create(:zone, origin: 'ee') - end - - it 'should set force delete time' do - domain = build(:domain) - domain.nameservers.build(attributes_for(:nameserver)) - domain.nameservers.build(attributes_for(:nameserver)) - domain.save! - - domain.statuses = ['ok'] - domain.schedule_force_delete - - domain.statuses.should match_array([ - "serverForceDelete", - "pendingDelete", - "serverManualInzone", - "serverRenewProhibited", - "serverTransferProhibited", - "serverUpdateProhibited" - ]) - - domain.cancel_force_delete - - domain.statuses.should == ['ok'] - - domain.statuses = [ - DomainStatus::CLIENT_DELETE_PROHIBITED, - DomainStatus::SERVER_DELETE_PROHIBITED, - DomainStatus::PENDING_UPDATE, - DomainStatus::PENDING_TRANSFER, - DomainStatus::PENDING_RENEW, - DomainStatus::PENDING_CREATE, - DomainStatus::CLIENT_HOLD, - DomainStatus::EXPIRED, - DomainStatus::SERVER_HOLD, - DomainStatus::DELETE_CANDIDATE - ] - - domain.save - - domain.schedule_force_delete - - domain.statuses.should match_array([ - "clientHold", - "deleteCandidate", - "expired", - "serverForceDelete", - "pendingDelete", - "serverHold", - "serverRenewProhibited", - "serverTransferProhibited", - "serverUpdateProhibited" - ]) - - domain.cancel_force_delete - - domain.statuses.should match_array([ - "clientDeleteProhibited", - "clientHold", - "deleteCandidate", - "expired", - "pendingCreate", - "pendingRenew", - "pendingTransfer", - "pendingUpdate", - "serverDeleteProhibited", - "serverHold" - ]) - end - - it 'should should be manual in zone and held after force delete' do - domain = create(:domain) - Setting.redemption_grace_period = 1 - - domain.valid? - domain.outzone_at = Time.zone.now + 1.day # before redemption grace period - # what should this be? - # domain.server_holdable?.should be true - domain.statuses.include?(DomainStatus::SERVER_HOLD).should be false - domain.statuses.include?(DomainStatus::SERVER_MANUAL_INZONE).should be false - domain.schedule_force_delete - domain.server_holdable?.should be false - domain.statuses.include?(DomainStatus::SERVER_MANUAL_INZONE).should be true - domain.statuses.include?(DomainStatus::SERVER_HOLD).should be false - end - - it 'should not allow update after force delete' do - domain = create(:domain) - domain.valid? - domain.pending_update_prohibited?.should be false - domain.update_prohibited?.should be false - domain.schedule_force_delete - domain.pending_update_prohibited?.should be true - domain.update_prohibited?.should be true - end -end diff --git a/test/models/domain/force_delete_test.rb b/test/models/domain/force_delete_test.rb new file mode 100644 index 000000000..27b792fe7 --- /dev/null +++ b/test/models/domain/force_delete_test.rb @@ -0,0 +1,40 @@ +require 'test_helper' + +class DomainForceDeleteTest < ActiveSupport::TestCase + def setup + @domain = domains(:shop) + end + + def test_schedule_force_delete + @original_redemption_grace_period = Setting.redemption_grace_period + Setting.redemption_grace_period = 30 + travel_to Time.zone.parse('2010-07-05 00:00') + + @domain.schedule_force_delete + + assert @domain.force_delete_scheduled? + assert_equal Time.zone.parse('2010-08-04 03:00'), @domain.force_delete_at + + travel_back + Setting.redemption_grace_period = @original_redemption_grace_period + end + + def test_scheduling_force_delete_bypasses_validation + @domain = domains(:invalid) + @domain.schedule_force_delete + assert @domain.force_delete_scheduled? + end + + def test_cancel_force_delete + @domain.cancel_force_delete + assert_not @domain.force_delete_scheduled? + assert_nil @domain.force_delete_at + end + + def test_cancelling_force_delete_bypasses_validation + @domain = domains(:invalid) + @domain.schedule_force_delete + @domain.cancel_force_delete + assert_not @domain.force_delete_scheduled? + end +end From ed6f067a8d861f130fc74b90eab2970f054cbef8 Mon Sep 17 00:00:00 2001 From: Artur Beljajev Date: Sun, 22 Apr 2018 16:14:17 +0300 Subject: [PATCH 03/72] Require a domain to be discarded before cancelling force delete #791 --- app/models/concerns/domain/force_delete.rb | 2 ++ test/models/domain/force_delete_test.rb | 14 +++++++++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/app/models/concerns/domain/force_delete.rb b/app/models/concerns/domain/force_delete.rb index ec5c651be..bf67a33f2 100644 --- a/app/models/concerns/domain/force_delete.rb +++ b/app/models/concerns/domain/force_delete.rb @@ -23,6 +23,8 @@ module Concerns::Domain::ForceDelete end def cancel_force_delete + raise 'Domain must be discarded before cancelling force delete procedure' unless discarded? + statuses.delete(DomainStatus::FORCE_DELETE) statuses.delete(DomainStatus::SERVER_RENEW_PROHIBITED) statuses.delete(DomainStatus::SERVER_TRANSFER_PROHIBITED) diff --git a/test/models/domain/force_delete_test.rb b/test/models/domain/force_delete_test.rb index 27b792fe7..328a45658 100644 --- a/test/models/domain/force_delete_test.rb +++ b/test/models/domain/force_delete_test.rb @@ -11,6 +11,7 @@ class DomainForceDeleteTest < ActiveSupport::TestCase travel_to Time.zone.parse('2010-07-05 00:00') @domain.schedule_force_delete + @domain.reload assert @domain.force_delete_scheduled? assert_equal Time.zone.parse('2010-08-04 03:00'), @domain.force_delete_at @@ -25,14 +26,25 @@ class DomainForceDeleteTest < ActiveSupport::TestCase assert @domain.force_delete_scheduled? end - def test_cancel_force_delete + def test_cancelling_force_delete_on_discarded_domain + @domain.discard + @domain.schedule_force_delete @domain.cancel_force_delete + @domain.reload assert_not @domain.force_delete_scheduled? assert_nil @domain.force_delete_at end + def test_cancelling_force_delete_requires_a_domain_to_be_discarded + @domain.schedule_force_delete + assert_raises StandardError do + @domain.cancel_force_delete + end + end + def test_cancelling_force_delete_bypasses_validation @domain = domains(:invalid) + @domain.discard @domain.schedule_force_delete @domain.cancel_force_delete assert_not @domain.force_delete_scheduled? From 615eb0557cbde0dc654976a4652cd9243519ff97 Mon Sep 17 00:00:00 2001 From: Artur Beljajev Date: Sun, 22 Apr 2018 19:15:45 +0300 Subject: [PATCH 04/72] Rename column #791 --- ...omains_statuses_backup_to_statuses_before_force_delete.rb | 5 +++++ db/structure.sql | 4 +++- 2 files changed, 8 insertions(+), 1 deletion(-) create mode 100644 db/migrate/20180422154642_rename_domains_statuses_backup_to_statuses_before_force_delete.rb diff --git a/db/migrate/20180422154642_rename_domains_statuses_backup_to_statuses_before_force_delete.rb b/db/migrate/20180422154642_rename_domains_statuses_backup_to_statuses_before_force_delete.rb new file mode 100644 index 000000000..a6784f02e --- /dev/null +++ b/db/migrate/20180422154642_rename_domains_statuses_backup_to_statuses_before_force_delete.rb @@ -0,0 +1,5 @@ +class RenameDomainsStatusesBackupToStatusesBeforeForceDelete < ActiveRecord::Migration + def change + rename_column :domains, :statuses_backup, :statuses_before_force_delete + end +end diff --git a/db/structure.sql b/db/structure.sql index 744ea9e19..c319b8e28 100644 --- a/db/structure.sql +++ b/db/structure.sql @@ -895,7 +895,7 @@ CREATE TABLE domains ( statuses character varying[], reserved boolean DEFAULT false, status_notes hstore, - statuses_backup character varying[] DEFAULT '{}'::character varying[], + statuses_before_force_delete character varying[] DEFAULT '{}'::character varying[], upid integer, up_date timestamp without time zone ); @@ -4716,3 +4716,5 @@ INSERT INTO schema_migrations (version) VALUES ('20180327151906'); INSERT INTO schema_migrations (version) VALUES ('20180331200125'); +INSERT INTO schema_migrations (version) VALUES ('20180422154642'); + From 3ee49cdae903178a08af7515913e07662f45bde1 Mon Sep 17 00:00:00 2001 From: Artur Beljajev Date: Mon, 23 Apr 2018 02:30:29 +0300 Subject: [PATCH 05/72] Add tests #791 --- app/models/concerns/domain/force_delete.rb | 51 ++++++++++------ test/models/domain/force_delete_test.rb | 69 +++++++++++++++++++++- 2 files changed, 102 insertions(+), 18 deletions(-) diff --git a/app/models/concerns/domain/force_delete.rb b/app/models/concerns/domain/force_delete.rb index bf67a33f2..c7b3ef454 100644 --- a/app/models/concerns/domain/force_delete.rb +++ b/app/models/concerns/domain/force_delete.rb @@ -6,16 +6,8 @@ module Concerns::Domain::ForceDelete end def schedule_force_delete - statuses << DomainStatus::FORCE_DELETE - statuses << DomainStatus::SERVER_RENEW_PROHIBITED - statuses << DomainStatus::SERVER_TRANSFER_PROHIBITED - statuses << DomainStatus::SERVER_UPDATE_PROHIBITED - statuses << DomainStatus::PENDING_DELETE - - if (statuses & [DomainStatus::SERVER_HOLD, DomainStatus::CLIENT_HOLD]).empty? - statuses << DomainStatus::SERVER_MANUAL_INZONE - end - + preserve_current_statuses_for_force_delete + add_force_delete_statuses self.force_delete_at = (Time.zone.now + (Setting.redemption_grace_period.days + 1.day)).utc .beginning_of_day stop_all_pending_actions @@ -25,13 +17,8 @@ module Concerns::Domain::ForceDelete def cancel_force_delete raise 'Domain must be discarded before cancelling force delete procedure' unless discarded? - statuses.delete(DomainStatus::FORCE_DELETE) - statuses.delete(DomainStatus::SERVER_RENEW_PROHIBITED) - statuses.delete(DomainStatus::SERVER_TRANSFER_PROHIBITED) - statuses.delete(DomainStatus::SERVER_UPDATE_PROHIBITED) - statuses.delete(DomainStatus::PENDING_DELETE) - statuses.delete(DomainStatus::SERVER_MANUAL_INZONE) - + restore_statuses_before_force_delete + remove_force_delete_statuses self.force_delete_at = nil save(validate: false) end @@ -46,4 +33,34 @@ module Concerns::Domain::ForceDelete statuses.delete(DomainStatus::PENDING_RENEW) statuses.delete(DomainStatus::PENDING_CREATE) end + + def preserve_current_statuses_for_force_delete + self.statuses_before_force_delete = statuses + end + + def restore_statuses_before_force_delete + self.statuses = statuses_before_force_delete + self.statuses_before_force_delete = nil + end + + def add_force_delete_statuses + statuses << DomainStatus::FORCE_DELETE + statuses << DomainStatus::SERVER_RENEW_PROHIBITED + statuses << DomainStatus::SERVER_TRANSFER_PROHIBITED + statuses << DomainStatus::SERVER_UPDATE_PROHIBITED + statuses << DomainStatus::PENDING_DELETE + + if (statuses & [DomainStatus::SERVER_HOLD, DomainStatus::CLIENT_HOLD]).empty? + statuses << DomainStatus::SERVER_MANUAL_INZONE + end + end + + def remove_force_delete_statuses + statuses.delete(DomainStatus::FORCE_DELETE) + statuses.delete(DomainStatus::SERVER_RENEW_PROHIBITED) + statuses.delete(DomainStatus::SERVER_TRANSFER_PROHIBITED) + statuses.delete(DomainStatus::SERVER_UPDATE_PROHIBITED) + statuses.delete(DomainStatus::PENDING_DELETE) + statuses.delete(DomainStatus::SERVER_MANUAL_INZONE) + end end diff --git a/test/models/domain/force_delete_test.rb b/test/models/domain/force_delete_test.rb index 328a45658..058a49bfb 100644 --- a/test/models/domain/force_delete_test.rb +++ b/test/models/domain/force_delete_test.rb @@ -20,13 +20,50 @@ class DomainForceDeleteTest < ActiveSupport::TestCase Setting.redemption_grace_period = @original_redemption_grace_period end + def test_scheduling_force_delete_adds_corresponding_statuses + statuses = [ + DomainStatus::FORCE_DELETE, + DomainStatus::SERVER_RENEW_PROHIBITED, + DomainStatus::SERVER_TRANSFER_PROHIBITED, + DomainStatus::SERVER_UPDATE_PROHIBITED, + DomainStatus::PENDING_DELETE, + ] + + @domain.schedule_force_delete + @domain.reload + assert (@domain.statuses & statuses) == statuses + end + + def test_scheduling_force_delete_stops_pending_actions + statuses = [ + DomainStatus::CLIENT_DELETE_PROHIBITED, + DomainStatus::SERVER_DELETE_PROHIBITED, + DomainStatus::PENDING_UPDATE, + DomainStatus::PENDING_TRANSFER, + DomainStatus::PENDING_RENEW, + DomainStatus::PENDING_CREATE, + ] + + @domain.statuses = statuses + %w[other-status] + @domain.schedule_force_delete + @domain.reload + assert_not (@domain.statuses & statuses).any?, 'Pending actions should be stopped' + end + + def test_scheduling_force_delete_preserves_current_statuses + @domain.statuses = %w[test1 test2] + @domain.schedule_force_delete + @domain.reload + assert_equal %w[test1 test2], @domain.statuses_before_force_delete + end + def test_scheduling_force_delete_bypasses_validation @domain = domains(:invalid) @domain.schedule_force_delete assert @domain.force_delete_scheduled? end - def test_cancelling_force_delete_on_discarded_domain + def test_cancelling_force_delete_on_a_discarded_domain @domain.discard @domain.schedule_force_delete @domain.cancel_force_delete @@ -49,4 +86,34 @@ class DomainForceDeleteTest < ActiveSupport::TestCase @domain.cancel_force_delete assert_not @domain.force_delete_scheduled? end + + def test_cancelling_force_delete_removes_statuses_that_were_set_on_force_delete + statuses = [ + DomainStatus::FORCE_DELETE, + DomainStatus::SERVER_RENEW_PROHIBITED, + DomainStatus::SERVER_TRANSFER_PROHIBITED, + DomainStatus::SERVER_UPDATE_PROHIBITED, + DomainStatus::PENDING_DELETE, + DomainStatus::SERVER_MANUAL_INZONE + ] + @domain.discard + @domain.statuses = @domain.statuses + statuses + @domain.schedule_force_delete + + @domain.cancel_force_delete + @domain.reload + + assert (@domain.statuses & statuses).empty? + end + + def test_cancelling_force_delete_restores_statuses_that_a_domain_had_before_force_delete + @domain.discard + @domain.statuses_before_force_delete = ['test1', DomainStatus::DELETE_CANDIDATE] + + @domain.cancel_force_delete + @domain.reload + + assert_equal ['test1', DomainStatus::DELETE_CANDIDATE], @domain.statuses + assert_nil @domain.statuses_before_force_delete + end end From 304b04bd61d592cfcfa20194c08fcd6b790a95c1 Mon Sep 17 00:00:00 2001 From: Artur Beljajev Date: Mon, 11 Jun 2018 06:19:33 +0300 Subject: [PATCH 06/72] Remove `domains.statuses_before_force_delete` from REST API --- app/models/domain.rb | 1 + doc/repp/v1/domain.md | 5 +---- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/app/models/domain.rb b/app/models/domain.rb index 55596aedf..ebe7e93d2 100644 --- a/app/models/domain.rb +++ b/app/models/domain.rb @@ -639,6 +639,7 @@ class Domain < ActiveRecord::Base hash = super hash['auth_info'] = hash.delete('transfer_code') # API v1 requirement hash['valid_from'] = hash['registered_at'] # API v1 requirement + hash.delete('statuses_before_force_delete') hash end diff --git a/doc/repp/v1/domain.md b/doc/repp/v1/domain.md index adb9c4c8e..4c9476125 100644 --- a/doc/repp/v1/domain.md +++ b/doc/repp/v1/domain.md @@ -63,10 +63,7 @@ Content-Type: application/json ], "reserved": false, "status_notes": { - }, - "statuses_backup": [ - - ] + } } ], "total_number_of_records": 2 From 4e2bd9f2dabbece172c511db506217d1de34e080 Mon Sep 17 00:00:00 2001 From: Artur Beljajev Date: Mon, 11 Jun 2018 08:10:32 +0300 Subject: [PATCH 07/72] Improve readability --- test/models/domain/force_delete_test.rb | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/test/models/domain/force_delete_test.rb b/test/models/domain/force_delete_test.rb index 058a49bfb..c04244052 100644 --- a/test/models/domain/force_delete_test.rb +++ b/test/models/domain/force_delete_test.rb @@ -21,7 +21,7 @@ class DomainForceDeleteTest < ActiveSupport::TestCase end def test_scheduling_force_delete_adds_corresponding_statuses - statuses = [ + statuses_to_be_added = [ DomainStatus::FORCE_DELETE, DomainStatus::SERVER_RENEW_PROHIBITED, DomainStatus::SERVER_TRANSFER_PROHIBITED, @@ -31,11 +31,11 @@ class DomainForceDeleteTest < ActiveSupport::TestCase @domain.schedule_force_delete @domain.reload - assert (@domain.statuses & statuses) == statuses + assert (@domain.statuses & statuses_to_be_added) == statuses_to_be_added end def test_scheduling_force_delete_stops_pending_actions - statuses = [ + statuses_to_be_removed = [ DomainStatus::CLIENT_DELETE_PROHIBITED, DomainStatus::SERVER_DELETE_PROHIBITED, DomainStatus::PENDING_UPDATE, @@ -44,10 +44,10 @@ class DomainForceDeleteTest < ActiveSupport::TestCase DomainStatus::PENDING_CREATE, ] - @domain.statuses = statuses + %w[other-status] + @domain.statuses = statuses_to_be_removed + %w[other-status] @domain.schedule_force_delete @domain.reload - assert_not (@domain.statuses & statuses).any?, 'Pending actions should be stopped' + assert_empty @domain.statuses & statuses_to_be_removed, 'Pending actions should be stopped' end def test_scheduling_force_delete_preserves_current_statuses @@ -103,7 +103,7 @@ class DomainForceDeleteTest < ActiveSupport::TestCase @domain.cancel_force_delete @domain.reload - assert (@domain.statuses & statuses).empty? + assert_empty @domain.statuses & statuses end def test_cancelling_force_delete_restores_statuses_that_a_domain_had_before_force_delete From c2d5b7c7040b1ab6c7eafb1bef107fb5807508bb Mon Sep 17 00:00:00 2001 From: Artur Beljajev Date: Mon, 11 Jun 2018 08:26:17 +0300 Subject: [PATCH 08/72] Extract method --- app/models/concerns/domain/force_delete.rb | 8 ++++++-- test/models/domain/force_delete_test.rb | 12 +++++++++++- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/app/models/concerns/domain/force_delete.rb b/app/models/concerns/domain/force_delete.rb index c7b3ef454..45f45dab6 100644 --- a/app/models/concerns/domain/force_delete.rb +++ b/app/models/concerns/domain/force_delete.rb @@ -11,6 +11,7 @@ module Concerns::Domain::ForceDelete self.force_delete_at = (Time.zone.now + (Setting.redemption_grace_period.days + 1.day)).utc .beginning_of_day stop_all_pending_actions + allow_deletion save(validate: false) end @@ -26,8 +27,6 @@ module Concerns::Domain::ForceDelete private def stop_all_pending_actions - statuses.delete(DomainStatus::CLIENT_DELETE_PROHIBITED) - statuses.delete(DomainStatus::SERVER_DELETE_PROHIBITED) statuses.delete(DomainStatus::PENDING_UPDATE) statuses.delete(DomainStatus::PENDING_TRANSFER) statuses.delete(DomainStatus::PENDING_RENEW) @@ -63,4 +62,9 @@ module Concerns::Domain::ForceDelete statuses.delete(DomainStatus::PENDING_DELETE) statuses.delete(DomainStatus::SERVER_MANUAL_INZONE) end + + def allow_deletion + statuses.delete(DomainStatus::CLIENT_DELETE_PROHIBITED) + statuses.delete(DomainStatus::SERVER_DELETE_PROHIBITED) + end end diff --git a/test/models/domain/force_delete_test.rb b/test/models/domain/force_delete_test.rb index c04244052..535ad84d8 100644 --- a/test/models/domain/force_delete_test.rb +++ b/test/models/domain/force_delete_test.rb @@ -34,10 +34,20 @@ class DomainForceDeleteTest < ActiveSupport::TestCase assert (@domain.statuses & statuses_to_be_added) == statuses_to_be_added end - def test_scheduling_force_delete_stops_pending_actions + def test_scheduling_force_delete_allows_domain_deletion statuses_to_be_removed = [ DomainStatus::CLIENT_DELETE_PROHIBITED, DomainStatus::SERVER_DELETE_PROHIBITED, + ] + + @domain.statuses = statuses_to_be_removed + %w[other-status] + @domain.schedule_force_delete + @domain.reload + assert_empty @domain.statuses & statuses_to_be_removed + end + + def test_scheduling_force_delete_stops_pending_actions + statuses_to_be_removed = [ DomainStatus::PENDING_UPDATE, DomainStatus::PENDING_TRANSFER, DomainStatus::PENDING_RENEW, From cd6a40b1bb637bfde9ef3ca3cb39920387d606f2 Mon Sep 17 00:00:00 2001 From: Artur Beljajev Date: Fri, 15 Jun 2018 17:10:06 +0300 Subject: [PATCH 09/72] Fix test --- test/integration/admin/domains/force_delete_test.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/integration/admin/domains/force_delete_test.rb b/test/integration/admin/domains/force_delete_test.rb index 0ef017c11..df95307b4 100644 --- a/test/integration/admin/domains/force_delete_test.rb +++ b/test/integration/admin/domains/force_delete_test.rb @@ -44,8 +44,8 @@ class AdminAreaDomainForceDeleteTest < ActionDispatch::IntegrationTest end def test_cancels_scheduled_domain_force_delete - @domain.update_attribute(:statuses, [DomainStatus::FORCE_DELETE]) - assert @domain.force_delete_scheduled? + @domain.discard + @domain.schedule_force_delete visit edit_admin_domain_url(@domain) click_link_or_button 'Cancel force delete' From 0f6df9e3f8d8d5c328582dfd05e59fb3012ad20d Mon Sep 17 00:00:00 2001 From: Artur Beljajev Date: Tue, 19 Jun 2018 20:00:40 +0300 Subject: [PATCH 10/72] Regenerate Devise translation --- config/locales/devise.en.yml | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/config/locales/devise.en.yml b/config/locales/devise.en.yml index 9524e860c..3a853fe31 100644 --- a/config/locales/devise.en.yml +++ b/config/locales/devise.en.yml @@ -9,12 +9,12 @@ en: failure: already_authenticated: "You are already signed in." inactive: "Your account is not activated yet." - invalid: "Invalid email or password." + invalid: "Invalid %{authentication_keys} or password." locked: "Your account is locked." last_attempt: "You have one more attempt before your account is locked." - not_found_in_database: "Invalid email address or password." + not_found_in_database: "Invalid %{authentication_keys} or password." timeout: "Your session expired. Please sign in again to continue." - unauthenticated: "You need to sign in." + unauthenticated: "You need to sign in before continuing." unconfirmed: "You have to confirm your email address before continuing." mailer: confirmation_instructions: @@ -23,6 +23,10 @@ en: subject: "Reset password instructions" unlock_instructions: subject: "Unlock instructions" + email_changed: + subject: "Email Changed" + password_change: + subject: "Password Changed" omniauth_callbacks: failure: "Could not authenticate you from %{kind} because \"%{reason}\"." success: "Successfully authenticated from %{kind} account." From ebe831e78247bde3eb50347969b46622ee24db21 Mon Sep 17 00:00:00 2001 From: Artur Beljajev Date: Tue, 19 Jun 2018 20:23:54 +0300 Subject: [PATCH 11/72] Regenerate and tune Devise config --- config/initializers/devise.rb | 82 +++++++++++++++++++++-------------- 1 file changed, 49 insertions(+), 33 deletions(-) diff --git a/config/initializers/devise.rb b/config/initializers/devise.rb index eceb6d5f2..c2f89e691 100644 --- a/config/initializers/devise.rb +++ b/config/initializers/devise.rb @@ -1,26 +1,31 @@ -require 'devise_custom_failure' +# frozen_string_literal: true # Use this hook to configure devise mailer, warden hooks and so forth. # Many of these configuration options can be set straight in your model. Devise.setup do |config| - config.warden do |manager| - manager.failure_app = DeviseCustomFailure - end - # The secret key used by Devise. Devise uses this key to generate # random tokens. Changing this key will render invalid all existing # confirmation, reset password and unlock tokens in the database. + # Devise will use the `secret_key_base` as its `secret_key` + # by default. You can change it below and use your own secret key. config.secret_key = ENV['devise_secret'] + # ==> Controller configuration + # Configure the parent class to the devise controllers. + # config.parent_controller = 'DeviseController' + # ==> Mailer Configuration # Configure the e-mail address which will be shown in Devise::Mailer, # note that it will be overwritten if you use your own mailer class # with default "from" parameter. - config.mailer_sender = 'noreply@example.com' + config.mailer_sender = 'please-change-me-at-config-initializers-devise@example.com' # Configure the class responsible to send e-mails. # config.mailer = 'Devise::Mailer' + # Configure the parent class responsible to send e-mails. + # config.parent_mailer = 'ActionMailer::Base' + # ==> ORM configuration # Load and configure the ORM. Supports :active_record (default) and # :mongoid (bson_ext recommended) by default. Other ORMs may be @@ -35,7 +40,7 @@ Devise.setup do |config| # session. If you need permissions, you should implement that in a before filter. # You can also supply a hash where the value is a boolean determining whether # or not authentication should be aborted when the value is not present. - # config.authentication_keys = [ :email ] + # config.authentication_keys = [:email] # Configure parameters from the request object used for authentication. Each entry # given should be a request method and it will automatically be passed to the @@ -67,7 +72,7 @@ Devise.setup do |config| # :database = Support basic authentication with authentication key + password # config.http_authenticatable = false - # If http headers should be returned for AJAX requests. True by default. + # If 401 status code should be returned for AJAX requests. True by default. # config.http_authenticatable_on_xhr = true # The realm used in Http Basic Authentication. 'Application' by default. @@ -91,20 +96,31 @@ Devise.setup do |config| # from the server. You can disable this option at your own risk. # config.clean_up_csrf_token_on_authentication = true + # When false, Devise will not attempt to reload routes on eager load. + # This can reduce the time taken to boot the app but if your application + # requires the Devise mappings to be loaded during boot time the application + # won't boot properly. + # config.reload_routes = true + # ==> Configuration for :database_authenticatable - # For bcrypt, this is the cost for hashing the password and defaults to 10. If - # using other encryptors, it sets how many times you want the password re-encrypted. + # For bcrypt, this is the cost for hashing the password and defaults to 11. If + # using other algorithms, it sets how many times you want the password to be hashed. # # Limiting the stretches to just one in testing will increase the performance of # your test suite dramatically. However, it is STRONGLY RECOMMENDED to not use # a value less than 10 in other environments. Note that, for bcrypt (the default - # encryptor), the cost increases exponentially with the number of stretches (e.g. + # algorithm), the cost increases exponentially with the number of stretches (e.g. # a value of 20 is already extremely slow: approx. 60 seconds for 1 calculation). - config.stretches = Rails.env.test? ? 1 : 10 + config.stretches = Rails.env.test? ? 1 : 11 - # Setup a pepper to generate the encrypted password. - # config.pepper = '4d1b39f778c3ea5b415476ce410f337a27895181a8ccd586c60e50e0f7284' \ - # '3d5d6ded80558ed7a4637de6b3a1504379270af6eee995fd9a329e4f4c5daa33882' + # Set up a pepper to generate the hashed password. + # config.pepper = '1fc02c7f3a9d5d0dc6c3e49828eb45d29e5fdb3136f78ee0063a2cdf774b7ed53ea40176d5823703554b7f015dd23c0e491fb488bb705a0768db32d02b1d088d' + + # Send a notification to the original email when the user's email is changed. + # config.send_email_changed_notification = false + + # Send a notification email when the user's password is changed. + # config.send_password_change_notification = false # ==> Configuration for :confirmable # A period that the user is allowed to access the website even without @@ -129,11 +145,11 @@ Devise.setup do |config| config.reconfirmable = true # Defines which key will be used when confirming an account - # config.confirmation_keys = [ :email ] + # config.confirmation_keys = [:email] # ==> Configuration for :rememberable # The time the user will be remembered without asking for credentials again. - config.remember_for = 2.weeks + # config.remember_for = 2.weeks # Invalidates all the remember me tokens when the user signs out. config.expire_all_remember_me_on_sign_out = true @@ -152,15 +168,12 @@ Devise.setup do |config| # Email regex used to validate email formats. It simply asserts that # one (and only one) @ exists in the given string. This is mainly # to give user feedback and not to assert the e-mail validity. - # config.email_regexp = /\A[^@]+@[^@]+\z/ + config.email_regexp = /\A[^@\s]+@[^@\s]+\z/ # ==> Configuration for :timeoutable # The time you want to timeout the user session without activity. After this # time the user will be asked for credentials again. Default is 30 minutes. - config.timeout_in = ENV['user_session_timeout'].to_i.seconds if ENV['user_session_timeout'] - - # If true, expires auth token on session timeout. - # config.expire_auth_token_on_timeout = false + # config.timeout_in = 30.minutes # ==> Configuration for :lockable # Defines which strategy will be used to lock an account. @@ -169,7 +182,7 @@ Devise.setup do |config| # config.lock_strategy = :failed_attempts # Defines which key will be used when locking and unlocking an account - # config.unlock_keys = [ :email ] + # config.unlock_keys = [:email] # Defines which strategy will be used to unlock an account. # :email = Sends an unlock link to the user email @@ -186,24 +199,28 @@ Devise.setup do |config| # config.unlock_in = 1.hour # Warn on the last attempt before the account is locked. - # config.last_attempt_warning = false + # config.last_attempt_warning = true # ==> Configuration for :recoverable # # Defines which key will be used when recovering the password for an account - # config.reset_password_keys = [ :email ] + # config.reset_password_keys = [:email] # Time interval you can reset your password with a reset password key. # Don't put a too small interval or your users won't have the time to # change their passwords. config.reset_password_within = 6.hours + # When set to false, does not sign a user in automatically after their password is + # reset. Defaults to true, so a user is signed in automatically after a reset. + # config.sign_in_after_reset_password = true + # ==> Configuration for :encryptable - # Allow you to use another encryption algorithm besides bcrypt (default). You can use - # :sha1, :sha512 or encryptors from others authentication tools as :clearance_sha1, - # :authlogic_sha512 (then you should set stretches above to 20 for default behavior) - # and :restful_authentication_sha1 (then you should set stretches to 10, and copy - # REST_AUTH_SITE_KEY to pepper). + # Allow you to use another hashing or encryption algorithm besides bcrypt (default). + # You can use :sha1, :sha512 or algorithms from others authentication tools as + # :clearance_sha1, :authlogic_sha512 (then you should set stretches above to 20 + # for default behavior) and :restful_authentication_sha1 (then you should set + # stretches to 10, and copy REST_AUTH_SITE_KEY to pepper). # # Require the `devise-encryptable` gem when using anything other than bcrypt # config.encryptor = :sha512 @@ -220,7 +237,7 @@ Devise.setup do |config| # Set this configuration to false if you want /users/sign_out to sign out # only the current scope. By default, Devise signs out all scopes. - # config.sign_out_all_scopes = true + config.sign_out_all_scopes = false # ==> Navigation configuration # Lists the formats that should be treated as navigational. Formats like @@ -260,8 +277,7 @@ Devise.setup do |config| # The router that invoked `devise_for`, in the example above, would be: # config.router_name = :my_engine # - # When using omniauth, Devise cannot automatically set Omniauth path, + # When using OmniAuth, Devise cannot automatically set OmniAuth path, # so you need to do it manually. For the users scope, it would be: # config.omniauth_path_prefix = '/my_engine/users/auth' end - From bb39d0340e6eeaf441c34aa4d76cedf484ccda72 Mon Sep 17 00:00:00 2001 From: Artur Beljajev Date: Tue, 19 Jun 2018 20:24:52 +0300 Subject: [PATCH 12/72] Remove routing specs --- app/models/user.rb | 2 +- spec/routing/registrar/domains_routing_spec.rb | 9 --------- spec/routing/registrar/sessions_routing_spec.rb | 9 --------- 3 files changed, 1 insertion(+), 19 deletions(-) delete mode 100644 spec/routing/registrar/domains_routing_spec.rb delete mode 100644 spec/routing/registrar/sessions_routing_spec.rb diff --git a/app/models/user.rb b/app/models/user.rb index b69e0250c..150311e90 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -1,6 +1,6 @@ class User < ActiveRecord::Base include Versions # version/user_version.rb - devise :trackable, :timeoutable + devise :database_authenticatable, :trackable, :timeoutable attr_accessor :phone diff --git a/spec/routing/registrar/domains_routing_spec.rb b/spec/routing/registrar/domains_routing_spec.rb deleted file mode 100644 index e30d1dd24..000000000 --- a/spec/routing/registrar/domains_routing_spec.rb +++ /dev/null @@ -1,9 +0,0 @@ -require 'rails_helper' - -RSpec.describe Registrar::DomainsController do - describe 'routing' do - it 'routes to #index' do - expect(get: '/registrar/domains').to route_to('registrar/domains#index') - end - end -end diff --git a/spec/routing/registrar/sessions_routing_spec.rb b/spec/routing/registrar/sessions_routing_spec.rb deleted file mode 100644 index 24e075e58..000000000 --- a/spec/routing/registrar/sessions_routing_spec.rb +++ /dev/null @@ -1,9 +0,0 @@ -require 'rails_helper' - -RSpec.describe Registrar::SessionsController do - describe 'routing' do - it 'routes to #login' do - expect(get: '/registrar/login').to route_to('registrar/sessions#login') - end - end -end From c538579d5b2a451f5b522b06b7ba6fb1f9eafd33 Mon Sep 17 00:00:00 2001 From: Artur Beljajev Date: Tue, 19 Jun 2018 20:36:06 +0300 Subject: [PATCH 13/72] Remove `rememberable` and `lockable` modules from `AdminUser` --- app/models/admin_user.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/admin_user.rb b/app/models/admin_user.rb index d76c42dec..c2c213226 100644 --- a/app/models/admin_user.rb +++ b/app/models/admin_user.rb @@ -9,7 +9,7 @@ class AdminUser < User ROLES = %w(user customer_service admin) # should not match to api_users roles - devise :database_authenticatable, :rememberable, :trackable, :validatable, :lockable + devise :database_authenticatable, :trackable, :validatable def self.min_password_length Devise.password_length.min From 756836001c9179c00575a9dbdd5e0fc3f2e4db35 Mon Sep 17 00:00:00 2001 From: Artur Beljajev Date: Tue, 19 Jun 2018 20:39:52 +0300 Subject: [PATCH 14/72] Remove unused routes --- config/routes.rb | 4 ---- 1 file changed, 4 deletions(-) diff --git a/config/routes.rb b/config/routes.rb index ecb054409..6fe587caa 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -20,7 +20,6 @@ Rails.application.routes.draw do # REGISTRAR ROUTES namespace :registrar do - resource :dashboard root 'dashboard#show' resources :invoices do @@ -247,9 +246,6 @@ Rails.application.routes.draw do end resources :delayed_jobs - - resource :dashboard - resources :epp_logs resources :repp_logs From 28416a3375580d604a278f2c400b49b7247eddae Mon Sep 17 00:00:00 2001 From: Artur Beljajev Date: Tue, 19 Jun 2018 20:43:23 +0300 Subject: [PATCH 15/72] Use singular controller --- app/controllers/admin/dashboard_controller.rb | 8 ++++++++ app/controllers/admin/dashboards_controller.rb | 9 --------- .../{dashboards/show.haml => dashboard/show.html.erb} | 0 config/routes.rb | 4 ++-- 4 files changed, 10 insertions(+), 11 deletions(-) create mode 100644 app/controllers/admin/dashboard_controller.rb delete mode 100644 app/controllers/admin/dashboards_controller.rb rename app/views/admin/{dashboards/show.haml => dashboard/show.html.erb} (100%) diff --git a/app/controllers/admin/dashboard_controller.rb b/app/controllers/admin/dashboard_controller.rb new file mode 100644 index 000000000..35efab599 --- /dev/null +++ b/app/controllers/admin/dashboard_controller.rb @@ -0,0 +1,8 @@ +module Admin + class DashboardController < BaseController + authorize_resource class: false + + def show + end + end +end \ No newline at end of file diff --git a/app/controllers/admin/dashboards_controller.rb b/app/controllers/admin/dashboards_controller.rb deleted file mode 100644 index 52d82ea0a..000000000 --- a/app/controllers/admin/dashboards_controller.rb +++ /dev/null @@ -1,9 +0,0 @@ -module Admin - class DashboardsController < BaseController - authorize_resource class: false - - def show - redirect_to [:admin, :domains] if can? :show, Domain - end - end -end diff --git a/app/views/admin/dashboards/show.haml b/app/views/admin/dashboard/show.html.erb similarity index 100% rename from app/views/admin/dashboards/show.haml rename to app/views/admin/dashboard/show.html.erb diff --git a/config/routes.rb b/config/routes.rb index 6fe587caa..7e0e99815 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -149,6 +149,8 @@ Rails.application.routes.draw do # ADMIN ROUTES namespace :admin do + root 'dashboard#show' + resources :keyrelays resources :zonefiles resources :zones, controller: 'dns/zones', except: %i[show destroy] @@ -258,8 +260,6 @@ Rails.application.routes.draw do authenticate :user do mount Que::Web, at: 'que' end - - root 'dashboards#show' end devise_for :users From 724d421f4410297cedad8d2c2d2c1f94ef9e46b9 Mon Sep 17 00:00:00 2001 From: Artur Beljajev Date: Tue, 19 Jun 2018 20:50:02 +0300 Subject: [PATCH 16/72] Remove Devise FailureApp --- lib/devise_custom_failure.rb | 18 ------------------ 1 file changed, 18 deletions(-) delete mode 100644 lib/devise_custom_failure.rb diff --git a/lib/devise_custom_failure.rb b/lib/devise_custom_failure.rb deleted file mode 100644 index a8a947173..000000000 --- a/lib/devise_custom_failure.rb +++ /dev/null @@ -1,18 +0,0 @@ -class DeviseCustomFailure < Devise::FailureApp - def redirect_url - return registrant_login_url if request.original_fullpath.to_s.match(%r{^\/registrant}) - return registrar_login_url if request.original_fullpath.to_s.match(%r{^\/registrar}) - return '/admin' if request.original_fullpath.to_s.match(%r{^\/admin\/que}) - return admin_login_url if request.original_fullpath.to_s.match(%r{^\/admin}) - root_url - end - - # You need to override respond to eliminate recall - def respond - if http_auth? - http_auth - else - redirect - end - end -end From febbe1282d94f39530f7cc2f66e6b9fdc9770774 Mon Sep 17 00:00:00 2001 From: Artur Beljajev Date: Tue, 19 Jun 2018 21:02:56 +0300 Subject: [PATCH 17/72] Fix links --- app/views/layouts/admin/base.haml | 2 +- app/views/layouts/devise.haml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/views/layouts/admin/base.haml b/app/views/layouts/admin/base.haml index 717c5015c..8ec55c424 100644 --- a/app/views/layouts/admin/base.haml +++ b/app/views/layouts/admin/base.haml @@ -19,7 +19,7 @@ %span.icon-bar %span.icon-bar %span.icon-bar - = link_to admin_dashboard_path, class: 'navbar-brand' do + = link_to admin_root_path, class: 'navbar-brand' do = ENV['app_name'] - if unstable_env.present? .text-center diff --git a/app/views/layouts/devise.haml b/app/views/layouts/devise.haml index 81248b86d..aaa1c8e31 100644 --- a/app/views/layouts/devise.haml +++ b/app/views/layouts/devise.haml @@ -18,7 +18,7 @@ %span.icon-bar %span.icon-bar %span.icon-bar - = link_to admin_dashboard_path, class: 'navbar-brand' do + = link_to admin_login_path, class: 'navbar-brand' do = ENV['app_name'] - if unstable_env.present? .text-center From 450a95f628676d7ca07c775f28d6c71fd36558ab Mon Sep 17 00:00:00 2001 From: Artur Beljajev Date: Tue, 19 Jun 2018 21:08:44 +0300 Subject: [PATCH 18/72] Revert "Remove routing specs" This reverts commit bb39d0340e6eeaf441c34aa4d76cedf484ccda72. --- app/models/user.rb | 2 +- spec/routing/registrar/domains_routing_spec.rb | 9 +++++++++ spec/routing/registrar/sessions_routing_spec.rb | 9 +++++++++ 3 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 spec/routing/registrar/domains_routing_spec.rb create mode 100644 spec/routing/registrar/sessions_routing_spec.rb diff --git a/app/models/user.rb b/app/models/user.rb index 150311e90..b69e0250c 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -1,6 +1,6 @@ class User < ActiveRecord::Base include Versions # version/user_version.rb - devise :database_authenticatable, :trackable, :timeoutable + devise :trackable, :timeoutable attr_accessor :phone diff --git a/spec/routing/registrar/domains_routing_spec.rb b/spec/routing/registrar/domains_routing_spec.rb new file mode 100644 index 000000000..e30d1dd24 --- /dev/null +++ b/spec/routing/registrar/domains_routing_spec.rb @@ -0,0 +1,9 @@ +require 'rails_helper' + +RSpec.describe Registrar::DomainsController do + describe 'routing' do + it 'routes to #index' do + expect(get: '/registrar/domains').to route_to('registrar/domains#index') + end + end +end diff --git a/spec/routing/registrar/sessions_routing_spec.rb b/spec/routing/registrar/sessions_routing_spec.rb new file mode 100644 index 000000000..24e075e58 --- /dev/null +++ b/spec/routing/registrar/sessions_routing_spec.rb @@ -0,0 +1,9 @@ +require 'rails_helper' + +RSpec.describe Registrar::SessionsController do + describe 'routing' do + it 'routes to #login' do + expect(get: '/registrar/login').to route_to('registrar/sessions#login') + end + end +end From 02137b620ed2bff753162fb9c64cf85a4956f0f9 Mon Sep 17 00:00:00 2001 From: Artur Beljajev Date: Tue, 19 Jun 2018 21:10:53 +0300 Subject: [PATCH 19/72] Remove routing specs --- spec/routing/registrar/domains_routing_spec.rb | 9 --------- spec/routing/registrar/sessions_routing_spec.rb | 9 --------- 2 files changed, 18 deletions(-) delete mode 100644 spec/routing/registrar/domains_routing_spec.rb delete mode 100644 spec/routing/registrar/sessions_routing_spec.rb diff --git a/spec/routing/registrar/domains_routing_spec.rb b/spec/routing/registrar/domains_routing_spec.rb deleted file mode 100644 index e30d1dd24..000000000 --- a/spec/routing/registrar/domains_routing_spec.rb +++ /dev/null @@ -1,9 +0,0 @@ -require 'rails_helper' - -RSpec.describe Registrar::DomainsController do - describe 'routing' do - it 'routes to #index' do - expect(get: '/registrar/domains').to route_to('registrar/domains#index') - end - end -end diff --git a/spec/routing/registrar/sessions_routing_spec.rb b/spec/routing/registrar/sessions_routing_spec.rb deleted file mode 100644 index 24e075e58..000000000 --- a/spec/routing/registrar/sessions_routing_spec.rb +++ /dev/null @@ -1,9 +0,0 @@ -require 'rails_helper' - -RSpec.describe Registrar::SessionsController do - describe 'routing' do - it 'routes to #login' do - expect(get: '/registrar/login').to route_to('registrar/sessions#login') - end - end -end From c31f507c254195094997fb6727195839afe6ca60 Mon Sep 17 00:00:00 2001 From: Artur Beljajev Date: Tue, 19 Jun 2018 22:20:52 +0300 Subject: [PATCH 20/72] Specify Devise modules for each type of user --- app/models/admin_user.rb | 2 +- app/models/api_user.rb | 1 + app/models/registrant_user.rb | 2 ++ app/models/user.rb | 1 - 4 files changed, 4 insertions(+), 2 deletions(-) diff --git a/app/models/admin_user.rb b/app/models/admin_user.rb index c2c213226..b53d6531a 100644 --- a/app/models/admin_user.rb +++ b/app/models/admin_user.rb @@ -9,7 +9,7 @@ class AdminUser < User ROLES = %w(user customer_service admin) # should not match to api_users roles - devise :database_authenticatable, :trackable, :validatable + devise :database_authenticatable, :trackable, :validatable, :timeoutable def self.min_password_length Devise.password_length.min diff --git a/app/models/api_user.rb b/app/models/api_user.rb index ce32c4045..378292076 100644 --- a/app/models/api_user.rb +++ b/app/models/api_user.rb @@ -2,6 +2,7 @@ require 'open3' class ApiUser < User include EppErrors + devise :database_authenticatable, :trackable, :timeoutable def epp_code_map { diff --git a/app/models/registrant_user.rb b/app/models/registrant_user.rb index 12cae0d82..1e1eb452f 100644 --- a/app/models/registrant_user.rb +++ b/app/models/registrant_user.rb @@ -2,6 +2,8 @@ class RegistrantUser < User ACCEPTED_ISSUER = 'AS Sertifitseerimiskeskus' attr_accessor :idc_data + devise :database_authenticatable, :trackable, :timeoutable + def ability @ability ||= Ability.new(self) end diff --git a/app/models/user.rb b/app/models/user.rb index b69e0250c..8968e2736 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -1,6 +1,5 @@ class User < ActiveRecord::Base include Versions # version/user_version.rb - devise :trackable, :timeoutable attr_accessor :phone From 9684c8e59f58d2b7285b65122c3250fe7b97ac26 Mon Sep 17 00:00:00 2001 From: Artur Beljajev Date: Wed, 20 Jun 2018 12:21:22 +0300 Subject: [PATCH 21/72] Refactor Devise integration - Use scoped users - Use the named route helpers instead of hardcoded paths --- app/controllers/admin/base_controller.rb | 14 ++++- .../admin/pending_deletes_controller.rb | 4 +- .../admin/pending_updates_controller.rb | 4 +- app/controllers/admin/sessions_controller.rb | 23 +++++--- app/controllers/application_controller.rb | 56 ++---------------- .../registrant/contacts_controller.rb | 3 +- .../domain_delete_confirms_controller.rb | 2 +- .../domain_update_confirms_controller.rb | 2 +- .../registrant/domains_controller.rb | 4 +- .../registrant/sessions_controller.rb | 21 +++++-- app/controllers/registrant_controller.rb | 15 ++++- .../account_activities_controller.rb | 2 +- app/controllers/registrar/base_controller.rb | 14 +++-- .../registrar/bulk_change_controller.rb | 2 +- .../registrar/contacts_controller.rb | 6 +- .../registrar/current_user_controller.rb | 4 +- .../registrar/deposits_controller.rb | 2 +- app/controllers/registrar/depp_controller.rb | 10 ++-- .../registrar/domain_transfers_controller.rb | 2 +- .../registrar/domains_controller.rb | 8 +-- .../registrar/invoices_controller.rb | 2 +- .../registrar/nameservers_controller.rb | 2 +- .../registrar/profile_controller.rb | 4 +- .../registrar/sessions_controller.rb | 32 +++++----- .../registrar/tech_contacts_controller.rb | 2 +- app/views/admin/base/_menu.haml | 2 +- .../admin/sessions/{login.haml => new.haml} | 2 +- app/views/layouts/devise.haml | 2 +- .../layouts/registrant/application.html.erb | 6 +- .../sessions/{login.haml => new.haml} | 0 .../registrar/base/_current_user.html.erb | 4 +- app/views/registrar/invoices/index.haml | 4 +- .../sessions/{login.haml => new.haml} | 2 +- config/locales/registrar/sessions.en.yml | 2 +- config/routes.rb | 59 ++++++++----------- doc/controllers_complete.svg | 8 --- spec/features/registrar/home_link_spec.rb | 2 +- .../registrar/sign_in/mobile_id_spec.rb | 2 +- .../registrar/sign_in/password_spec.rb | 39 ------------ spec/features/registrar/sign_out_spec.rb | 14 ----- .../requests/registrar/ip_restriction_spec.rb | 12 ++-- spec/requests/registrar/linked_users_spec.rb | 9 ++- .../registrar/sign_in/password_spec.rb | 16 ----- spec/requests/registrar/sign_out_spec.rb | 18 ------ spec/support/features/session_helpers.rb | 4 +- spec/support/requests/session_helpers.rb | 6 +- test/integration/admin/login_test.rb | 27 +++++++++ test/integration/admin/logout_test.rb | 15 +++++ test/integration/admin/protected_area_test.rb | 22 +++++++ test/integration/registrar/login_test.rb | 39 ++++++++++++ test/integration/registrar/logout_test.rb | 15 +++++ .../registrar/protected_area_test.rb | 22 +++++++ 52 files changed, 313 insertions(+), 280 deletions(-) rename app/views/admin/sessions/{login.haml => new.haml} (84%) rename app/views/registrant/sessions/{login.haml => new.haml} (100%) rename app/views/registrar/sessions/{login.haml => new.haml} (88%) delete mode 100644 spec/features/registrar/sign_in/password_spec.rb delete mode 100644 spec/features/registrar/sign_out_spec.rb delete mode 100644 spec/requests/registrar/sign_in/password_spec.rb delete mode 100644 spec/requests/registrar/sign_out_spec.rb create mode 100644 test/integration/admin/login_test.rb create mode 100644 test/integration/admin/logout_test.rb create mode 100644 test/integration/admin/protected_area_test.rb create mode 100644 test/integration/registrar/login_test.rb create mode 100644 test/integration/registrar/logout_test.rb create mode 100644 test/integration/registrar/protected_area_test.rb diff --git a/app/controllers/admin/base_controller.rb b/app/controllers/admin/base_controller.rb index 7de43f7fc..52ff6aa7c 100644 --- a/app/controllers/admin/base_controller.rb +++ b/app/controllers/admin/base_controller.rb @@ -1,10 +1,20 @@ module Admin class BaseController < ApplicationController - before_action :authenticate_user! + before_action :authenticate_admin_user! helper_method :head_title_sufix def head_title_sufix t(:admin_head_title_sufix) end + + private + + def current_ability + @current_ability ||= Ability.new(current_admin_user) + end + + def user_for_paper_trail + current_admin_user.present? ? current_admin_user.id_role_username : 'public' + end end -end +end \ No newline at end of file diff --git a/app/controllers/admin/pending_deletes_controller.rb b/app/controllers/admin/pending_deletes_controller.rb index 86529da84..9cc8702c5 100644 --- a/app/controllers/admin/pending_deletes_controller.rb +++ b/app/controllers/admin/pending_deletes_controller.rb @@ -6,7 +6,7 @@ module Admin def update authorize! :update, :pending - if registrant_verification.domain_registrant_delete_confirm!("admin #{current_user.username}") + if registrant_verification.domain_registrant_delete_confirm!("admin #{current_admin_user.username}") redirect_to admin_domain_path(@domain.id), notice: t(:pending_applied) else redirect_to admin_domain_path(@domain.id), alert: t(:failure) @@ -16,7 +16,7 @@ module Admin def destroy authorize! :destroy, :pending - if registrant_verification.domain_registrant_delete_reject!("admin #{current_user.username}") + if registrant_verification.domain_registrant_delete_reject!("admin #{current_admin_user.username}") redirect_to admin_domain_path(@domain.id), notice: t(:pending_removed) else redirect_to admin_domain_path(@domain.id), alert: t(:failure) diff --git a/app/controllers/admin/pending_updates_controller.rb b/app/controllers/admin/pending_updates_controller.rb index e402227e0..4a2e5ec7c 100644 --- a/app/controllers/admin/pending_updates_controller.rb +++ b/app/controllers/admin/pending_updates_controller.rb @@ -6,7 +6,7 @@ module Admin def update authorize! :update, :pending - if registrant_verification.domain_registrant_change_confirm!("admin #{current_user.username}") + if registrant_verification.domain_registrant_change_confirm!("admin #{current_admin_user.username}") redirect_to admin_domain_path(@domain.id), notice: t(:pending_applied) else redirect_to edit_admin_domain_path(@domain.id), alert: t(:failure) @@ -15,7 +15,7 @@ module Admin def destroy authorize! :destroy, :pending - if registrant_verification.domain_registrant_change_reject!("admin #{current_user.username}") + if registrant_verification.domain_registrant_change_reject!("admin #{current_admin_user.username}") redirect_to admin_domain_path(@domain.id), notice: t(:pending_removed) else redirect_to admin_domain_path(@domain.id), alert: t(:failure) diff --git a/app/controllers/admin/sessions_controller.rb b/app/controllers/admin/sessions_controller.rb index 1bdcd30dc..1e9be9eb7 100644 --- a/app/controllers/admin/sessions_controller.rb +++ b/app/controllers/admin/sessions_controller.rb @@ -1,8 +1,6 @@ module Admin class SessionsController < Devise::SessionsController - skip_authorization_check only: :create - - def login + def new @admin_user = AdminUser.new end @@ -10,19 +8,28 @@ module Admin if params[:admin_user].blank? @admin_user = AdminUser.new flash[:alert] = 'Something went wrong' - return render 'login' + return render :new end @admin_user = AdminUser.find_by(username: params[:admin_user][:username]) @admin_user ||= AdminUser.new(username: params[:admin_user][:username]) if @admin_user.valid_password?(params[:admin_user][:password]) - sign_in @admin_user, event: :authentication - redirect_to admin_root_url, notice: I18n.t(:welcome) + sign_in_and_redirect(:admin_user, @admin_user, event: :authentication) else flash[:alert] = 'Authorization error' - render 'login' + render :new end end + + private + + def after_sign_in_path_for(resource_or_scope) + admin_root_path + end + + def after_sign_out_path_for(resource_or_scope) + new_admin_user_session_path + end end -end +end \ No newline at end of file diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 87dabad01..518b752b7 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -12,63 +12,15 @@ class ApplicationController < ActionController::Base end rescue_from CanCan::AccessDenied do |exception| - redirect_to current_root_url, alert: exception.message + redirect_to root_url, alert: exception.message end - helper_method :registrant_request?, :registrar_request?, :admin_request?, :current_root_url helper_method :available_languages - def registrant_request? - request.path.match(/^\/registrant/) - end - - def registrar_request? - request.path.match(/^\/registrar/) - end - - def admin_request? - request.path.match(/^\/admin/) - end - - def current_root_url - if registrar_request? - registrar_root_url - elsif registrant_request? - registrant_login_url - elsif admin_request? - admin_root_url - end - end - - def after_sign_in_path_for(_resource) - rt = session[:user_return_to].to_s.presence - login_paths = [admin_login_path, registrar_login_path, '/login'] - return rt if rt && !login_paths.include?(rt) - current_root_url - end - - def after_sign_out_path_for(_resource) - if registrar_request? - registrar_login_url - elsif registrant_request? - registrant_login_url - elsif admin_request? - admin_login_url - end - end - def info_for_paper_trail { uuid: request.uuid } end - def user_for_paper_trail - user_log_str(current_user) - end - - def user_log_str(user) - user.nil? ? 'public' : user.id_role_username - end - def comma_support_for(parent_key, key) return if params[parent_key].blank? return if params[parent_key][key].blank? @@ -80,4 +32,8 @@ class ApplicationController < ActionController::Base def available_languages { en: 'English', et: 'Estonian' }.invert end -end + + def user_for_paper_trail + current_user.present? ? current_user.id_role_username : 'public' + end +end \ No newline at end of file diff --git a/app/controllers/registrant/contacts_controller.rb b/app/controllers/registrant/contacts_controller.rb index db6c279eb..948bc1a94 100644 --- a/app/controllers/registrant/contacts_controller.rb +++ b/app/controllers/registrant/contacts_controller.rb @@ -2,7 +2,6 @@ class Registrant::ContactsController < RegistrantController helper_method :domain_ids def show @contact = Contact.where(id: contacts).find_by(id: params[:id]) - @current_user = current_user authorize! :read, @contact end @@ -19,7 +18,7 @@ class Registrant::ContactsController < RegistrantController def domain_ids @domain_ids ||= begin - ident_cc, ident = @current_user.registrant_ident.to_s.split '-' + ident_cc, ident = current_registrant_user.registrant_ident.to_s.split '-' BusinessRegistryCache.fetch_by_ident_and_cc(ident, ident_cc).associated_domain_ids end end diff --git a/app/controllers/registrant/domain_delete_confirms_controller.rb b/app/controllers/registrant/domain_delete_confirms_controller.rb index af8516462..a57c6178a 100644 --- a/app/controllers/registrant/domain_delete_confirms_controller.rb +++ b/app/controllers/registrant/domain_delete_confirms_controller.rb @@ -19,7 +19,7 @@ class Registrant::DomainDeleteConfirmsController < RegistrantController domain_name: @domain.name, verification_token: params[:token]) - initiator = current_user ? current_user.username : t(:user_not_authenticated) + initiator = current_registrant_user ? current_registrant_user.username : t(:user_not_authenticated) if params[:rejected] if @registrant_verification.domain_registrant_delete_reject!("email link #{initiator}") diff --git a/app/controllers/registrant/domain_update_confirms_controller.rb b/app/controllers/registrant/domain_update_confirms_controller.rb index ca91f0192..feaa39d6e 100644 --- a/app/controllers/registrant/domain_update_confirms_controller.rb +++ b/app/controllers/registrant/domain_update_confirms_controller.rb @@ -19,7 +19,7 @@ class Registrant::DomainUpdateConfirmsController < RegistrantController domain_name: @domain.name, verification_token: params[:token]) - initiator = current_user ? current_user.username : t(:user_not_authenticated) + initiator = current_registrant_user ? current_registrant_user.username : t(:user_not_authenticated) if params[:rejected] if @registrant_verification.domain_registrant_change_reject!("email link, #{initiator}") diff --git a/app/controllers/registrant/domains_controller.rb b/app/controllers/registrant/domains_controller.rb index 0e2f6eeaf..06b24624d 100644 --- a/app/controllers/registrant/domains_controller.rb +++ b/app/controllers/registrant/domains_controller.rb @@ -54,13 +54,13 @@ class Registrant::DomainsController < RegistrantController end def domains - ident_cc, ident = @current_user.registrant_ident.split '-' + ident_cc, ident = current_registrant_user.registrant_ident.split '-' begin BusinessRegistryCache.fetch_associated_domains ident, ident_cc rescue Soap::Arireg::NotAvailableError => error flash[:notice] = I18n.t(error.json[:message]) Rails.logger.fatal("[EXCEPTION] #{error.to_s}") - current_user.domains + current_registrant_user.domains end end diff --git a/app/controllers/registrant/sessions_controller.rb b/app/controllers/registrant/sessions_controller.rb index 80a23eb0a..c29c920b0 100644 --- a/app/controllers/registrant/sessions_controller.rb +++ b/app/controllers/registrant/sessions_controller.rb @@ -1,7 +1,7 @@ class Registrant::SessionsController < Devise::SessionsController layout 'registrant/application' - def login + def new end def id @@ -10,11 +10,10 @@ class Registrant::SessionsController < Devise::SessionsController @user = RegistrantUser.find_or_create_by_idc_data(id_code, id_issuer) if @user - sign_in(@user, event: :authentication) - redirect_to registrant_root_url + sign_in_and_redirect(:registrant_user, @user, event: :authentication) else flash[:alert] = t('login_failed_check_id_card') - redirect_to registrant_login_url + redirect_to new_registrant_user_session_url end end @@ -68,7 +67,7 @@ class Registrant::SessionsController < Devise::SessionsController when 'USER_AUTHENTICATED' @user = RegistrantUser.find_by(registrant_ident: "#{session[:user_country]}-#{session[:user_id_code]}") - sign_in @user + sign_in(:registrant_user, @user) flash[:notice] = t(:welcome) flash.keep(:notice) render js: "window.location = '#{registrant_root_path}'" @@ -97,4 +96,14 @@ class Registrant::SessionsController < Devise::SessionsController return User.new unless idc ApiUser.find_by(identity_code: idc) || User.new end -end + + private + + def after_sign_in_path_for(resource_or_scope) + registrant_root_path + end + + def after_sign_out_path_for(resource_or_scope) + new_registrant_user_session_path + end +end \ No newline at end of file diff --git a/app/controllers/registrant_controller.rb b/app/controllers/registrant_controller.rb index 72fb78a08..76be97a1f 100644 --- a/app/controllers/registrant_controller.rb +++ b/app/controllers/registrant_controller.rb @@ -1,11 +1,22 @@ class RegistrantController < ApplicationController - before_action :authenticate_user! + before_action :authenticate_registrant_user! layout 'registrant/application' include Registrant::ApplicationHelper helper_method :head_title_sufix + def head_title_sufix t(:registrant_head_title_sufix) end -end + + private + + def current_ability + @current_ability ||= Ability.new(current_registrant_user, request.remote_ip) + end + + def user_for_paper_trail + current_registrant_user.present? ? current_registrant_user.id_role_username : 'public' + end +end \ No newline at end of file diff --git a/app/controllers/registrar/account_activities_controller.rb b/app/controllers/registrar/account_activities_controller.rb index 0b95d0122..baa0256af 100644 --- a/app/controllers/registrar/account_activities_controller.rb +++ b/app/controllers/registrar/account_activities_controller.rb @@ -4,7 +4,7 @@ class Registrar def index params[:q] ||= {} - account = current_user.registrar.cash_account + account = current_registrar_user.registrar.cash_account ca_cache = params[:q][:created_at_lteq] begin diff --git a/app/controllers/registrar/base_controller.rb b/app/controllers/registrar/base_controller.rb index 90f2f5210..2bd2eb492 100644 --- a/app/controllers/registrar/base_controller.rb +++ b/app/controllers/registrar/base_controller.rb @@ -2,7 +2,7 @@ class Registrar class BaseController < ApplicationController include Registrar::ApplicationHelper - before_action :authenticate_user! + before_action :authenticate_registrar_user! before_action :check_ip_restriction helper_method :depp_controller? helper_method :head_title_sufix @@ -10,21 +10,21 @@ class Registrar protected def current_ability - @current_ability ||= Ability.new(current_user, request.remote_ip) + @current_ability ||= Ability.new(current_registrar_user, request.remote_ip) end private def check_ip_restriction ip_restriction = Authorization::RestrictedIP.new(request.ip) - allowed = ip_restriction.can_access_registrar_area?(current_user.registrar) + allowed = ip_restriction.can_access_registrar_area?(current_registrar_user.registrar) return if allowed - sign_out current_user + sign_out current_registrar_user flash[:alert] = t('registrar.authorization.ip_not_allowed', ip: request.ip) - redirect_to registrar_login_url + redirect_to new_registrar_user_session_url end def depp_controller? @@ -34,5 +34,9 @@ class Registrar def head_title_sufix t(:registrar_head_title_sufix) end + + def user_for_paper_trail + current_registrar_user.present? ? current_registrar_user.id_role_username : 'public' + end end end diff --git a/app/controllers/registrar/bulk_change_controller.rb b/app/controllers/registrar/bulk_change_controller.rb index 562344a46..441127f6c 100644 --- a/app/controllers/registrar/bulk_change_controller.rb +++ b/app/controllers/registrar/bulk_change_controller.rb @@ -10,7 +10,7 @@ class Registrar private def available_contacts - current_user.registrar.contacts.order(:name).pluck(:name, :code) + current_registrar_user.registrar.contacts.order(:name).pluck(:name, :code) end def default_tab diff --git a/app/controllers/registrar/contacts_controller.rb b/app/controllers/registrar/contacts_controller.rb index cb059641e..f343f9bfb 100644 --- a/app/controllers/registrar/contacts_controller.rb +++ b/app/controllers/registrar/contacts_controller.rb @@ -21,11 +21,11 @@ class Registrar end if params[:statuses_contains] - contacts = current_user.registrar.contacts.includes(:registrar).where( + contacts = current_registrar_user.registrar.contacts.includes(:registrar).where( "contacts.statuses @> ?::varchar[]", "{#{params[:statuses_contains].join(',')}}" ) else - contacts = current_user.registrar.contacts.includes(:registrar) + contacts = current_registrar_user.registrar.contacts.includes(:registrar) end normalize_search_parameters do @@ -45,7 +45,7 @@ class Registrar @contacts = Contact.find_by(name: params[:q][:name_matches]) end - contacts = current_user.registrar.contacts.includes(:registrar) + contacts = current_registrar_user.registrar.contacts.includes(:registrar) contacts = contacts.filter_by_states(params[:statuses_contains]) if params[:statuses_contains] normalize_search_parameters do diff --git a/app/controllers/registrar/current_user_controller.rb b/app/controllers/registrar/current_user_controller.rb index 266e4b915..624ee294e 100644 --- a/app/controllers/registrar/current_user_controller.rb +++ b/app/controllers/registrar/current_user_controller.rb @@ -3,9 +3,9 @@ class Registrar skip_authorization_check def switch - raise 'Cannot switch to unlinked user' unless current_user.linked_with?(new_user) + raise 'Cannot switch to unlinked user' unless current_registrar_user.linked_with?(new_user) - sign_in(new_user) + sign_in(:registrar_user, new_user) redirect_to :back, notice: t('.switched', new_user: new_user) end diff --git a/app/controllers/registrar/deposits_controller.rb b/app/controllers/registrar/deposits_controller.rb index ec6d13977..6b10ccdd3 100644 --- a/app/controllers/registrar/deposits_controller.rb +++ b/app/controllers/registrar/deposits_controller.rb @@ -7,7 +7,7 @@ class Registrar end def create - @deposit = Deposit.new(deposit_params.merge(registrar: current_user.registrar)) + @deposit = Deposit.new(deposit_params.merge(registrar: current_registrar_user.registrar)) @invoice = @deposit.issue_prepayment_invoice if @invoice&.persisted? diff --git a/app/controllers/registrar/depp_controller.rb b/app/controllers/registrar/depp_controller.rb index 234ab40b7..87269b160 100644 --- a/app/controllers/registrar/depp_controller.rb +++ b/app/controllers/registrar/depp_controller.rb @@ -5,13 +5,13 @@ class Registrar rescue_from(Errno::ECONNRESET, Errno::ECONNREFUSED) do |exception| logger.error 'COULD NOT CONNECT TO REGISTRY' logger.error exception.backtrace.join("\n") - redirect_to registrar_login_url, alert: t(:no_connection_to_registry) + redirect_to new_registrar_user_session_url, alert: t(:no_connection_to_registry) end before_action :authenticate_user def authenticate_user - redirect_to registrar_login_url and return unless depp_current_user + redirect_to new_registrar_user_session_url and return unless depp_current_user end def depp_controller? @@ -19,10 +19,10 @@ class Registrar end def depp_current_user - return nil unless current_user + return nil unless current_registrar_user @depp_current_user ||= Depp::User.new( - tag: current_user.username, - password: current_user.password + tag: current_registrar_user.username, + password: current_registrar_user.password ) end diff --git a/app/controllers/registrar/domain_transfers_controller.rb b/app/controllers/registrar/domain_transfers_controller.rb index 7c0925f03..f65f3cece 100644 --- a/app/controllers/registrar/domain_transfers_controller.rb +++ b/app/controllers/registrar/domain_transfers_controller.rb @@ -21,7 +21,7 @@ class Registrar uri = URI.parse("#{ENV['repp_url']}domain_transfers") request = Net::HTTP::Post.new(uri, 'Content-Type' => 'application/json') request.body = { data: { domainTransfers: domain_transfers } }.to_json - request.basic_auth(current_user.username, current_user.password) + request.basic_auth(current_registrar_user.username, current_registrar_user.password) if Rails.env.test? diff --git a/app/controllers/registrar/domains_controller.rb b/app/controllers/registrar/domains_controller.rb index 7cb8fdfbe..d2969bb69 100644 --- a/app/controllers/registrar/domains_controller.rb +++ b/app/controllers/registrar/domains_controller.rb @@ -16,11 +16,11 @@ class Registrar end if params[:statuses_contains] - domains = current_user.registrar.domains.includes(:registrar, :registrant).where( + domains = current_registrar_user.registrar.domains.includes(:registrar, :registrant).where( "statuses @> ?::varchar[]", "{#{params[:statuses_contains].join(',')}}" ) else - domains = current_user.registrar.domains.includes(:registrar, :registrant) + domains = current_registrar_user.registrar.domains.includes(:registrar, :registrant) end normalize_search_parameters do @@ -142,7 +142,7 @@ class Registrar def search_contacts authorize! :create, Depp::Domain - scope = current_user.registrar.contacts.limit(10) + scope = current_registrar_user.registrar.contacts.limit(10) if params[:query].present? escaped_str = ActiveRecord::Base.connection.quote_string params[:query] scope = scope.where("name ilike '%#{escaped_str}%' OR code ilike '%#{escaped_str}%' ") @@ -159,7 +159,7 @@ class Registrar def contacts - current_user.registrar.contacts + current_registrar_user.registrar.contacts end def normalize_search_parameters diff --git a/app/controllers/registrar/invoices_controller.rb b/app/controllers/registrar/invoices_controller.rb index 735df91a3..548e47ebe 100644 --- a/app/controllers/registrar/invoices_controller.rb +++ b/app/controllers/registrar/invoices_controller.rb @@ -6,7 +6,7 @@ class Registrar def index params[:q] ||= {} - invoices = current_user.registrar.invoices.includes(:invoice_items, :account_activity) + invoices = current_registrar_user.registrar.invoices.includes(:invoice_items, :account_activity) normalize_search_parameters do @q = invoices.search(params[:q]) diff --git a/app/controllers/registrar/nameservers_controller.rb b/app/controllers/registrar/nameservers_controller.rb index b6f7af829..90dd5afb4 100644 --- a/app/controllers/registrar/nameservers_controller.rb +++ b/app/controllers/registrar/nameservers_controller.rb @@ -12,7 +12,7 @@ class Registrar attributes: { hostname: params[:new_hostname], ipv4: ipv4, ipv6: ipv6 } } }.to_json - request.basic_auth(current_user.username, current_user.password) + request.basic_auth(current_registrar_user.username, current_registrar_user.password) if Rails.env.test? response = Net::HTTP.start(uri.hostname, uri.port, diff --git a/app/controllers/registrar/profile_controller.rb b/app/controllers/registrar/profile_controller.rb index 5f202a894..1fe6d6a0b 100644 --- a/app/controllers/registrar/profile_controller.rb +++ b/app/controllers/registrar/profile_controller.rb @@ -5,13 +5,13 @@ class Registrar helper_method :linked_users def show - @user = current_user + @user = current_registrar_user end private def linked_users - current_user.linked_users + current_registrar_user.linked_users end end end diff --git a/app/controllers/registrar/sessions_controller.rb b/app/controllers/registrar/sessions_controller.rb index 1a8b195ee..d7a690752 100644 --- a/app/controllers/registrar/sessions_controller.rb +++ b/app/controllers/registrar/sessions_controller.rb @@ -3,7 +3,7 @@ class Registrar before_action :check_ip_restriction helper_method :depp_controller? - def login + def new @depp_user = Depp::User.new end @@ -30,7 +30,7 @@ class Registrar unless @api_user @depp_user.errors.add(:base, t(:no_such_user)) - render 'login' and return + render :new and return end if @depp_user.pki @@ -41,14 +41,13 @@ class Registrar if @depp_user.errors.none? if @api_user.active? - sign_in @api_user - redirect_to registrar_root_url + sign_in_and_redirect(:registrar_user, @api_user) else @depp_user.errors.add(:base, :not_active) - render 'login' + render :new end else - render 'login' + render :new end end @@ -56,11 +55,10 @@ class Registrar @user = ApiUser.find_by_idc_data_and_allowed(request.env['SSL_CLIENT_S_DN'], request.ip) if @user - sign_in(@user, event: :authentication) - redirect_to registrar_root_url + sign_in_and_redirect(:registrar_user, @user, event: :authentication) else flash[:alert] = t('no_such_user') - redirect_to registrar_login_url + redirect_to new_registrar_user_session_url end end @@ -91,7 +89,7 @@ class Registrar @user = find_user_by_idc_and_allowed(response.user_id_code) else @user = find_user_by_idc(response.user_id_code) - end + end if @user.persisted? session[:user_id_code] = response.user_id_code @@ -117,7 +115,7 @@ class Registrar render json: { message: t(:check_your_phone_for_confirmation_code) }, status: :ok when 'USER_AUTHENTICATED' @user = find_user_by_idc_and_allowed(session[:user_id_code]) - sign_in @user + sign_in(:registrar_user, @user) flash[:notice] = t(:welcome) flash.keep(:notice) render js: "window.location = '#{registrar_root_url}'" @@ -163,8 +161,6 @@ class Registrar end end - - def check_ip_restriction ip_restriction = Authorization::RestrictedIP.new(request.ip) allowed = ip_restriction.can_access_registrar_area_sign_in_page? @@ -173,5 +169,13 @@ class Registrar render text: t('registrar.authorization.ip_not_allowed', ip: request.ip) end + + def after_sign_in_path_for(resource_or_scope) + registrar_root_path + end + + def after_sign_out_path_for(resource_or_scope) + new_registrar_user_session_path + end end -end +end \ No newline at end of file diff --git a/app/controllers/registrar/tech_contacts_controller.rb b/app/controllers/registrar/tech_contacts_controller.rb index 9d4568ad6..fe3dd86da 100644 --- a/app/controllers/registrar/tech_contacts_controller.rb +++ b/app/controllers/registrar/tech_contacts_controller.rb @@ -8,7 +8,7 @@ class Registrar request = Net::HTTP::Patch.new(uri) request.set_form_data(current_contact_id: params[:current_contact_id], new_contact_id: params[:new_contact_id]) - request.basic_auth(current_user.username, current_user.password) + request.basic_auth(current_registrar_user.username, current_registrar_user.password) if Rails.env.test? response = Net::HTTP.start(uri.hostname, uri.port, diff --git a/app/views/admin/base/_menu.haml b/app/views/admin/base/_menu.haml index 7c813e43e..957b7826d 100644 --- a/app/views/admin/base/_menu.haml +++ b/app/views/admin/base/_menu.haml @@ -41,4 +41,4 @@ - if signed_in? %ul.nav.navbar-nav.navbar-right - %li= link_to t(:log_out, user: current_user), '/admin/logout' + %li= link_to t(:log_out, user: current_admin_user), destroy_admin_user_session_path, method: :delete, class: 'navbar-link' diff --git a/app/views/admin/sessions/login.haml b/app/views/admin/sessions/new.haml similarity index 84% rename from app/views/admin/sessions/login.haml rename to app/views/admin/sessions/new.haml index 1ecca10ae..d37461c85 100644 --- a/app/views/admin/sessions/login.haml +++ b/app/views/admin/sessions/new.haml @@ -3,7 +3,7 @@ %h2.form-signin-heading.text-center Eesti Interneti SA %hr .form-signin - = form_for(@admin_user, url: admin_sessions_path, method: :create, html: {class: 'form-signin'}) do |f| + = form_for(@admin_user, url: admin_user_session_path, html: {class: 'form-signin'}) do |f| = render 'admin/shared/errors', object: f.object - error_class = f.object.errors.any? ? 'has-error' : '' diff --git a/app/views/layouts/devise.haml b/app/views/layouts/devise.haml index aaa1c8e31..839290cef 100644 --- a/app/views/layouts/devise.haml +++ b/app/views/layouts/devise.haml @@ -18,7 +18,7 @@ %span.icon-bar %span.icon-bar %span.icon-bar - = link_to admin_login_path, class: 'navbar-brand' do + = link_to new_admin_user_session_path, class: 'navbar-brand' do = ENV['app_name'] - if unstable_env.present? .text-center diff --git a/app/views/layouts/registrant/application.html.erb b/app/views/layouts/registrant/application.html.erb index 075ac4652..6d47b72cf 100644 --- a/app/views/layouts/registrant/application.html.erb +++ b/app/views/layouts/registrant/application.html.erb @@ -37,7 +37,7 @@ <% end %> <% end %> - <% if current_user %> + <% if current_registrant_user %> -
<%= render 'form' %> -<%= render 'force_delete_dialog', domain: @domain, templates: force_delete_templates %> +<%= render 'force_delete_dialog', domain: @domain, templates: force_delete_templates %> \ No newline at end of file diff --git a/config/locales/admin/domains.en.yml b/config/locales/admin/domains.en.yml index 78f862ec4..415995f48 100644 --- a/config/locales/admin/domains.en.yml +++ b/config/locales/admin/domains.en.yml @@ -13,8 +13,8 @@ en: reset_btn: Reset edit: + header: "Edit: %{domain}" add_new_status_btn: Add new status - back_btn: Back to domain force_delete_dialog: title: Force delete From cc36e3cceafa5c551512a2b437b3527cd5a2a697 Mon Sep 17 00:00:00 2001 From: Artur Beljajev Date: Sun, 29 Jul 2018 20:42:29 +0300 Subject: [PATCH 52/72] Forbid cancelling force delete procedure when a domain is discarded --- app/models/concerns/domain/force_delete.rb | 4 +++- app/presenters/domain_presenter.rb | 7 ++++++- config/locales/admin/domains.en.yml | 2 ++ test/integration/admin/domains/force_delete_test.rb | 12 ++++++++++-- test/models/domain/force_delete_test.rb | 13 +------------ 5 files changed, 22 insertions(+), 16 deletions(-) diff --git a/app/models/concerns/domain/force_delete.rb b/app/models/concerns/domain/force_delete.rb index 45f45dab6..406b67924 100644 --- a/app/models/concerns/domain/force_delete.rb +++ b/app/models/concerns/domain/force_delete.rb @@ -16,7 +16,9 @@ module Concerns::Domain::ForceDelete end def cancel_force_delete - raise 'Domain must be discarded before cancelling force delete procedure' unless discarded? + if discarded? + raise StandardError, 'Force delete procedure cannot be cancelled while a domain is discarded' + end restore_statuses_before_force_delete remove_force_delete_statuses diff --git a/app/presenters/domain_presenter.rb b/app/presenters/domain_presenter.rb index f83febba7..40cd50c41 100644 --- a/app/presenters/domain_presenter.rb +++ b/app/presenters/domain_presenter.rb @@ -58,12 +58,17 @@ class DomainPresenter target: '.domain-edit-force-delete-dialog', } ) - else + elsif !domain.discarded? view.link_to(view.t('admin.domains.force_delete_toggle_btn.cancel'), view.admin_domain_force_delete_path(domain), method: :delete, data: { confirm: view.t('admin.domains.force_delete_toggle_btn.cancel_confirm') }, class: 'btn btn-primary') + else + view.content_tag(:button, view.t('admin.domains.force_delete_toggle_btn.cancel'), + class: 'btn btn-default ', + title: view.t('admin.domains.force_delete_toggle_btn.unable_to_cancel'), + disabled: true) end end diff --git a/config/locales/admin/domains.en.yml b/config/locales/admin/domains.en.yml index 415995f48..c569a22fa 100644 --- a/config/locales/admin/domains.en.yml +++ b/config/locales/admin/domains.en.yml @@ -47,3 +47,5 @@ en: schedule: Schedule force delete cancel: Cancel force delete cancel_confirm: Are you sure you want cancel force delete procedure? + unable_to_cancel: > + Force delete procedure cannot be cancelled while a domain has deleteCandidate status diff --git a/test/integration/admin/domains/force_delete_test.rb b/test/integration/admin/domains/force_delete_test.rb index d48444fb9..387394429 100644 --- a/test/integration/admin/domains/force_delete_test.rb +++ b/test/integration/admin/domains/force_delete_test.rb @@ -44,7 +44,6 @@ class AdminAreaDomainForceDeleteTest < ActionDispatch::IntegrationTest end def test_cancels_scheduled_domain_force_delete - @domain.discard @domain.schedule_force_delete visit edit_admin_domain_url(@domain) @@ -55,4 +54,13 @@ class AdminAreaDomainForceDeleteTest < ActionDispatch::IntegrationTest assert_current_path edit_admin_domain_path(@domain) assert_text 'Force delete procedure has been cancelled' end -end + + def test_force_delete_cannot_be_cancelled_when_a_domain_is_discarded + @domain.discard + @domain.schedule_force_delete + + visit edit_admin_domain_url(@domain) + assert_no_button 'Cancel force delete' + assert_no_link 'Cancel force delete' + end +end \ No newline at end of file diff --git a/test/models/domain/force_delete_test.rb b/test/models/domain/force_delete_test.rb index 535ad84d8..c353cc582 100644 --- a/test/models/domain/force_delete_test.rb +++ b/test/models/domain/force_delete_test.rb @@ -73,16 +73,8 @@ class DomainForceDeleteTest < ActiveSupport::TestCase assert @domain.force_delete_scheduled? end - def test_cancelling_force_delete_on_a_discarded_domain + def test_force_delete_cannot_be_cancelled_when_a_domain_is_discarded @domain.discard - @domain.schedule_force_delete - @domain.cancel_force_delete - @domain.reload - assert_not @domain.force_delete_scheduled? - assert_nil @domain.force_delete_at - end - - def test_cancelling_force_delete_requires_a_domain_to_be_discarded @domain.schedule_force_delete assert_raises StandardError do @domain.cancel_force_delete @@ -91,7 +83,6 @@ class DomainForceDeleteTest < ActiveSupport::TestCase def test_cancelling_force_delete_bypasses_validation @domain = domains(:invalid) - @domain.discard @domain.schedule_force_delete @domain.cancel_force_delete assert_not @domain.force_delete_scheduled? @@ -106,7 +97,6 @@ class DomainForceDeleteTest < ActiveSupport::TestCase DomainStatus::PENDING_DELETE, DomainStatus::SERVER_MANUAL_INZONE ] - @domain.discard @domain.statuses = @domain.statuses + statuses @domain.schedule_force_delete @@ -117,7 +107,6 @@ class DomainForceDeleteTest < ActiveSupport::TestCase end def test_cancelling_force_delete_restores_statuses_that_a_domain_had_before_force_delete - @domain.discard @domain.statuses_before_force_delete = ['test1', DomainStatus::DELETE_CANDIDATE] @domain.cancel_force_delete From 6de31605d99710d887bd84e7245a1ec66ed3c9c5 Mon Sep 17 00:00:00 2001 From: Artur Beljajev Date: Wed, 8 Aug 2018 19:36:14 +0300 Subject: [PATCH 53/72] Integrate master branch --- .../api_user => system/admin_area/api_users}/new_test.rb | 2 +- .../admin => system/admin_area}/protected_area_test.rb | 2 +- .../admin/login_test.rb => system/admin_area/sign_in_test.rb} | 2 +- .../logout_test.rb => system/admin_area/sign_out_test.rb} | 2 +- .../registrar_area}/protected_area_test.rb | 2 +- .../{sign_in_test.rb => sign_in/mobile_id_test.rb} | 4 ++-- .../registrar_area/sign_in/password_test.rb} | 2 +- .../logout_test.rb => system/registrar_area/sign_out_test.rb} | 2 +- 8 files changed, 9 insertions(+), 9 deletions(-) rename test/{integration/admin/api_user => system/admin_area/api_users}/new_test.rb (90%) rename test/{integration/admin => system/admin_area}/protected_area_test.rb (90%) rename test/{integration/admin/login_test.rb => system/admin_area/sign_in_test.rb} (95%) rename test/{integration/admin/logout_test.rb => system/admin_area/sign_out_test.rb} (79%) rename test/{integration/registrar => system/registrar_area}/protected_area_test.rb (90%) rename test/system/registrar_area/{sign_in_test.rb => sign_in/mobile_id_test.rb} (89%) rename test/{integration/registrar/login_test.rb => system/registrar_area/sign_in/password_test.rb} (93%) rename test/{integration/registrar/logout_test.rb => system/registrar_area/sign_out_test.rb} (79%) diff --git a/test/integration/admin/api_user/new_test.rb b/test/system/admin_area/api_users/new_test.rb similarity index 90% rename from test/integration/admin/api_user/new_test.rb rename to test/system/admin_area/api_users/new_test.rb index 32b2e1188..aed012fdc 100644 --- a/test/integration/admin/api_user/new_test.rb +++ b/test/system/admin_area/api_users/new_test.rb @@ -1,6 +1,6 @@ require 'test_helper' -class AdminAreaNewApiUserTest < ActionDispatch::IntegrationTest +class AdminAreaNewApiUserTest < ApplicationSystemTestCase setup do sign_in users(:admin) end diff --git a/test/integration/admin/protected_area_test.rb b/test/system/admin_area/protected_area_test.rb similarity index 90% rename from test/integration/admin/protected_area_test.rb rename to test/system/admin_area/protected_area_test.rb index 59edb04c3..8aea012f0 100644 --- a/test/integration/admin/protected_area_test.rb +++ b/test/system/admin_area/protected_area_test.rb @@ -1,6 +1,6 @@ require 'test_helper' -class AdminAreaProtectedAreaTest < ActionDispatch::IntegrationTest +class AdminAreaProtectedAreaTest < ApplicationSystemTestCase def test_anonymous_user_is_asked_to_authenticate_when_navigating_to_protected_area visit admin_domains_url assert_text 'You need to sign in before continuing' diff --git a/test/integration/admin/login_test.rb b/test/system/admin_area/sign_in_test.rb similarity index 95% rename from test/integration/admin/login_test.rb rename to test/system/admin_area/sign_in_test.rb index 364b6a0ba..dcef0e3aa 100644 --- a/test/integration/admin/login_test.rb +++ b/test/system/admin_area/sign_in_test.rb @@ -1,6 +1,6 @@ require 'test_helper' -class AdminAreaLoginTest < ActionDispatch::IntegrationTest +class AdminAreaSignInTest < ApplicationSystemTestCase def setup @user = users(:admin) end diff --git a/test/integration/admin/logout_test.rb b/test/system/admin_area/sign_out_test.rb similarity index 79% rename from test/integration/admin/logout_test.rb rename to test/system/admin_area/sign_out_test.rb index 159dc8de3..046abba95 100644 --- a/test/integration/admin/logout_test.rb +++ b/test/system/admin_area/sign_out_test.rb @@ -1,6 +1,6 @@ require 'test_helper' -class AdminAreaLogoutTest < ActionDispatch::IntegrationTest +class AdminAreaSignOutTest < ApplicationSystemTestCase def setup sign_in users(:admin) end diff --git a/test/integration/registrar/protected_area_test.rb b/test/system/registrar_area/protected_area_test.rb similarity index 90% rename from test/integration/registrar/protected_area_test.rb rename to test/system/registrar_area/protected_area_test.rb index dd7f46980..08dd6a63e 100644 --- a/test/integration/registrar/protected_area_test.rb +++ b/test/system/registrar_area/protected_area_test.rb @@ -1,6 +1,6 @@ require 'test_helper' -class RegistrarAreaProtectedAreaTest < ActionDispatch::IntegrationTest +class RegistrarAreaProtectedAreaTest < ApplicationSystemTestCase def test_anonymous_user_is_asked_to_authenticate_when_navigating_to_protected_area visit registrar_domains_url assert_text 'You need to sign in before continuing' diff --git a/test/system/registrar_area/sign_in_test.rb b/test/system/registrar_area/sign_in/mobile_id_test.rb similarity index 89% rename from test/system/registrar_area/sign_in_test.rb rename to test/system/registrar_area/sign_in/mobile_id_test.rb index 840839ccc..ecca00c56 100644 --- a/test/system/registrar_area/sign_in_test.rb +++ b/test/system/registrar_area/sign_in/mobile_id_test.rb @@ -1,6 +1,6 @@ require 'test_helper' -class RegistrarAreaSignInTest < JavaScriptApplicationSystemTestCase +class RegistrarAreaMobileIDSignInTest < JavaScriptApplicationSystemTestCase def setup super WebMock.allow_net_connect! @@ -10,7 +10,7 @@ class RegistrarAreaSignInTest < JavaScriptApplicationSystemTestCase @user.save end - def test_mobile_id_sign_in_page + def test_valid_phone_number mock_client = Minitest::Mock.new mock_client.expect(:authenticate, OpenStruct.new(user_id_code: '1234', challenge_id: '1234'), diff --git a/test/integration/registrar/login_test.rb b/test/system/registrar_area/sign_in/password_test.rb similarity index 93% rename from test/integration/registrar/login_test.rb rename to test/system/registrar_area/sign_in/password_test.rb index a70a9cf25..6878cd119 100644 --- a/test/integration/registrar/login_test.rb +++ b/test/system/registrar_area/sign_in/password_test.rb @@ -1,6 +1,6 @@ require 'test_helper' -class RegistrarAreaLoginTest < ActionDispatch::IntegrationTest +class RegistrarAreaPasswordSignInTest < ApplicationSystemTestCase def setup @user = users(:api_bestnames) end diff --git a/test/integration/registrar/logout_test.rb b/test/system/registrar_area/sign_out_test.rb similarity index 79% rename from test/integration/registrar/logout_test.rb rename to test/system/registrar_area/sign_out_test.rb index 9f2bba9dd..029167d48 100644 --- a/test/integration/registrar/logout_test.rb +++ b/test/system/registrar_area/sign_out_test.rb @@ -1,6 +1,6 @@ require 'test_helper' -class RegistrarAreaLogoutTest < ActionDispatch::IntegrationTest +class RegistrarAreaSignOutTest < ApplicationSystemTestCase def setup sign_in users(:api_bestnames) end From 096035ae115e77e517daae6184cb0a79c52547f1 Mon Sep 17 00:00:00 2001 From: Artur Beljajev Date: Wed, 8 Aug 2018 19:50:50 +0300 Subject: [PATCH 54/72] Revert old behaviour --- app/controllers/admin/sessions_controller.rb | 2 +- test/system/admin_area/protected_area_test.rb | 2 +- test/system/admin_area/sign_in_test.rb | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/app/controllers/admin/sessions_controller.rb b/app/controllers/admin/sessions_controller.rb index f4feefc3a..57d702059 100644 --- a/app/controllers/admin/sessions_controller.rb +++ b/app/controllers/admin/sessions_controller.rb @@ -3,7 +3,7 @@ module Admin private def after_sign_in_path_for(_resource_or_scope) - admin_root_path + admin_domains_path end def after_sign_out_path_for(_resource_or_scope) diff --git a/test/system/admin_area/protected_area_test.rb b/test/system/admin_area/protected_area_test.rb index 8aea012f0..9390348f0 100644 --- a/test/system/admin_area/protected_area_test.rb +++ b/test/system/admin_area/protected_area_test.rb @@ -17,6 +17,6 @@ class AdminAreaProtectedAreaTest < ApplicationSystemTestCase sign_in users(:admin) visit new_admin_user_session_url assert_text 'You are already signed in' - assert_current_path admin_root_path + assert_current_path admin_domains_path end end \ No newline at end of file diff --git a/test/system/admin_area/sign_in_test.rb b/test/system/admin_area/sign_in_test.rb index dcef0e3aa..09c1f7549 100644 --- a/test/system/admin_area/sign_in_test.rb +++ b/test/system/admin_area/sign_in_test.rb @@ -12,7 +12,7 @@ class AdminAreaSignInTest < ApplicationSystemTestCase click_button 'Sign in' assert_text 'Signed in successfully' - assert_current_path admin_root_path + assert_current_path admin_domains_path end def test_wrong_password @@ -39,6 +39,6 @@ class AdminAreaSignInTest < ApplicationSystemTestCase click_button 'Sign in' assert_text 'Signed in successfully' - assert_current_path admin_root_path + assert_current_path admin_domains_path end end \ No newline at end of file From 0d770137b604cec14905a584e2800edf3f242a46 Mon Sep 17 00:00:00 2001 From: Artur Beljajev Date: Wed, 8 Aug 2018 22:47:51 +0300 Subject: [PATCH 55/72] Convert HAML to ERB --- app/views/registrar/sessions/new.haml | 22 ------------------- app/views/registrar/sessions/new.html.erb | 26 +++++++++++++++++++++++ 2 files changed, 26 insertions(+), 22 deletions(-) delete mode 100644 app/views/registrar/sessions/new.haml create mode 100644 app/views/registrar/sessions/new.html.erb diff --git a/app/views/registrar/sessions/new.haml b/app/views/registrar/sessions/new.haml deleted file mode 100644 index 4d273c9f4..000000000 --- a/app/views/registrar/sessions/new.haml +++ /dev/null @@ -1,22 +0,0 @@ -.row - .form-signin.col-md-6.center-block.text-center - %h2.form-signin-heading.text-center= t(:log_in) - %hr - = form_for @depp_user, url: registrar_user_session_path, html: {class: 'form-signin'} do |f| - = render 'registrar/shared/errors', object: f.object - - - error_class = f.object.errors.any? ? 'has-error' : '' - %div{class: error_class} - = f.text_field :tag, class: 'form-control', placeholder: t(:username), required: true - = f.password_field :password, class: 'form-control', - autocomplete: 'off', placeholder: t(:password), required: true - - %button.btn.btn-lg.btn-primary.btn-block{:type => 'submit'}= t('.login_btn') - - %hr - = link_to '/registrar/login/mid', id: 'login-with-mobile-id-btn' do - = image_tag 'mid.gif' - = link_to '/registrar/id', method: :post do - = image_tag 'id_card.gif' - - diff --git a/app/views/registrar/sessions/new.html.erb b/app/views/registrar/sessions/new.html.erb new file mode 100644 index 000000000..e3f8d6128 --- /dev/null +++ b/app/views/registrar/sessions/new.html.erb @@ -0,0 +1,26 @@ +
+ +
\ No newline at end of file From 080defa228e240ff57155d2551acff2a721e89ca Mon Sep 17 00:00:00 2001 From: Artur Beljajev Date: Thu, 9 Aug 2018 13:39:48 +0300 Subject: [PATCH 56/72] Fix home page URL for anonymous users of registrar area --- app/views/layouts/registrar/sessions.html.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/layouts/registrar/sessions.html.erb b/app/views/layouts/registrar/sessions.html.erb index 4632e477c..985b6ccea 100644 --- a/app/views/layouts/registrar/sessions.html.erb +++ b/app/views/layouts/registrar/sessions.html.erb @@ -17,7 +17,7 @@