Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tech contacts bulk change blocked if domain UpdateProhibited #1820

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions app/models/concerns/domain/bulk_updatable.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
module Concerns
module Domain
module BulkUpdatable
extend ActiveSupport::Concern

def bulk_update_prohibited?
discarded? || statuses_blocks_update?
end

def statuses_blocks_update?
prohibited_array = [DomainStatus::SERVER_UPDATE_PROHIBITED,
DomainStatus::CLIENT_UPDATE_PROHIBITED]
prohibited_array.any? { |block_status| statuses.include?(block_status) }
end
end
end
end
1 change: 1 addition & 0 deletions app/models/domain.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ class Domain < ApplicationRecord
include Concerns::Domain::RegistryLockable
include Concerns::Domain::Releasable
include Concerns::Domain::Disputable
include Concerns::Domain::BulkUpdatable

attr_accessor :roles

Expand Down
3 changes: 1 addition & 2 deletions app/models/tech_domain_contact.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ def self.replace(current_contact, new_contact)
tech_contacts = where(contact: current_contact)

tech_contacts.each do |tech_contact|
if tech_contact.domain.discarded?
if tech_contact.domain.bulk_update_prohibited?
skipped_domains << tech_contact.domain.name
next
end
Expand All @@ -18,7 +18,6 @@ def self.replace(current_contact, new_contact)
skipped_domains << tech_contact.domain.name
end
end

[affected_domains.sort, skipped_domains.sort]
end
end
18 changes: 18 additions & 0 deletions test/integration/api/domain_contacts_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,24 @@ def test_disallow_self_replacement
JSON.parse(response.body, symbolize_names: true)
end

def test_tech_bulk_changed_when_domain_update_prohibited
domains(:shop).update!(statuses: [DomainStatus::SERVER_UPDATE_PROHIBITED])

shop_tech_contact = Contact.find_by(code: 'william-001')
assert domains(:shop).tech_contacts.include?(shop_tech_contact)

patch '/repp/v1/domains/contacts', params: { current_contact_id: 'william-001',
new_contact_id: 'john-001' },
headers: { 'HTTP_AUTHORIZATION' => http_auth_key }

assert_response :ok
assert_equal ({ code: 1000,
message: 'Command completed successfully',
data: { affected_domains: ["airport.test"],
skipped_domains: ["shop.test"] }}),
JSON.parse(response.body, symbolize_names: true)
end

private

def http_auth_key
Expand Down