diff --git a/app/models/actions/contact_create.rb b/app/models/actions/contact_create.rb deleted file mode 100644 index 22fabc7b9..000000000 --- a/app/models/actions/contact_create.rb +++ /dev/null @@ -1,81 +0,0 @@ -module Actions - class ContactCreate - attr_reader :contact, :legal_document, :ident - - def initialize(contact, legal_document, ident) - @contact = contact - @legal_document = legal_document - @ident = ident - end - - def call - maybe_remove_address - maybe_attach_legal_doc - validate_ident - commit - end - - def maybe_remove_address - return if Contact.address_processing? - - contact.city = nil - contact.zip = nil - contact.street = nil - contact.state = nil - contact.country_code = nil - end - - def validate_ident - validate_ident_integrity - validate_ident_birthday - - identifier = ::Contact::Ident.new(code: ident[:ident], type: ident[:ident_type], - country_code: ident[:ident_country_code]) - - identifier.validate - contact.identifier = identifier - end - - def validate_ident_integrity - return if ident.blank? - - if ident[:ident_type].blank? - contact.add_epp_error('2003', nil, 'ident_type', - I18n.t('errors.messages.required_ident_attribute_missing')) - @error = true - elsif !%w[priv org birthday].include?(ident[:ident_type]) - contact.add_epp_error('2003', nil, 'ident_type', 'Invalid ident type') - @error = true - end - end - - def validate_ident_birthday - return if ident.blank? - return unless ident[:ident_type] != 'birthday' && ident[:ident_country_code].blank? - - contact.add_epp_error('2003', nil, 'ident_country_code', - I18n.t('errors.messages.required_ident_attribute_missing')) - @error = true - end - - def maybe_attach_legal_doc - return unless legal_document - - doc = LegalDocument.create( - documentable_type: Contact, - document_type: legal_document[:type], body: legal_document[:body] - ) - - contact.legal_documents = [doc] - contact.legal_document_id = doc.id - end - - def commit - contact.id = nil # new record - return false if @error - - contact.generate_code - contact.save - end - end -end diff --git a/app/models/actions/contact_delete.rb b/app/models/actions/contact_delete.rb deleted file mode 100644 index 6543cd191..000000000 --- a/app/models/actions/contact_delete.rb +++ /dev/null @@ -1,42 +0,0 @@ -module Actions - class ContactDelete - attr_reader :contact, :new_attributes, :legal_document, :ident, :user - - def initialize(contact, legal_document = nil) - @legal_document = legal_document - @contact = contact - end - - def call - maybe_attach_legal_doc - - if contact.linked? - contact.errors.add(:domains, :exist) - return - end - - if contact.delete_prohibited? - contact.errors.add(:statuses, :delete_prohibited) - return - end - - commit - end - - def maybe_attach_legal_doc - return unless legal_document - - document = contact.legal_documents.create( - document_type: legal_document[:type], - body: legal_document[:body] - ) - - contact.legal_document_id = document.id - contact.save - end - - def commit - contact.destroy - end - end -end diff --git a/app/models/actions/contact_update.rb b/app/models/actions/contact_update.rb deleted file mode 100644 index 929235c69..000000000 --- a/app/models/actions/contact_update.rb +++ /dev/null @@ -1,105 +0,0 @@ -module Actions - class ContactUpdate - attr_reader :contact, :new_attributes, :legal_document, :ident, :user - - def initialize(contact, new_attributes, legal_document, ident, user) - @contact = contact - @new_attributes = new_attributes - @legal_document = legal_document - @ident = ident - @user = user - end - - def call - maybe_remove_address - maybe_update_statuses - maybe_update_ident if ident.present? - maybe_attach_legal_doc - commit - end - - def maybe_remove_address - return if Contact.address_processing? - - new_attributes.delete(:city) - new_attributes.delete(:zip) - new_attributes.delete(:street) - new_attributes.delete(:state) - new_attributes.delete(:country_code) - end - - def maybe_update_statuses - return unless Setting.client_status_editing_enabled - - new_statuses = - contact.statuses - new_attributes[:statuses_to_remove] + new_attributes[:statuses_to_add] - - new_attributes[:statuses] = new_statuses - end - - def maybe_attach_legal_doc - return unless legal_document - - document = contact.legal_documents.create( - document_type: legal_document[:type], - body: legal_document[:body] - ) - - contact.legal_document_id = document.id - end - - def maybe_update_ident - unless ident.is_a?(Hash) - contact.add_epp_error('2308', nil, nil, I18n.t('epp.contacts.errors.valid_ident')) - @error = true - return - end - - if contact.identifier.valid? - submitted_ident = ::Contact::Ident.new(code: ident[:ident], - type: ident[:ident_type], - country_code: ident[:ident_country_code]) - - if submitted_ident != contact.identifier - contact.add_epp_error('2308', nil, nil, I18n.t('epp.contacts.errors.valid_ident')) - @error = true - end - else - ident_update_attempt = ident[:ident] != contact.ident - - if ident_update_attempt - contact.add_epp_error('2308', nil, nil, I18n.t('epp.contacts.errors.ident_update')) - @error = true - end - - identifier = ::Contact::Ident.new(code: ident[:ident], - type: ident[:ident_type], - country_code: ident[:ident_country_code]) - - identifier.validate - - contact.identifier = identifier - contact.ident_updated_at ||= Time.zone.now - end - end - - def commit - return false if @error - - contact.upid = user.registrar&.id - contact.up_date = Time.zone.now - - contact.attributes = new_attributes - - email_changed = contact.will_save_change_to_email? - old_email = contact.email_was - updated = contact.save - - if updated && email_changed && contact.registrant? - ContactMailer.email_changed(contact: contact, old_email: old_email).deliver_now - end - - updated - end - end -end diff --git a/app/models/actions/domain_transfer.rb b/app/models/actions/domain_transfer.rb deleted file mode 100644 index 75bb251c4..000000000 --- a/app/models/actions/domain_transfer.rb +++ /dev/null @@ -1,70 +0,0 @@ -module Actions - class DomainTransfer - attr_reader :domain, :transfer_code, :legal_document, :ident, :user - - def initialize(domain, transfer_code, user) - @domain = domain - @transfer_code = transfer_code - @user = user - end - - def call - return unless domain_exists? - return unless valid_transfer_code? - - run_validations - - # return domain.pending_transfer if domain.pending_transfer - # attach_legal_document(::Deserializers::Xml::LegalDocument.new(frame).call) - - return if domain.errors[:epp_errors].any? - - commit - end - - def domain_exists? - return true if domain.persisted? - - domain.add_epp_error('2303', nil, nil, 'Object does not exist') - - false - end - - def run_validations - validate_registrar - validate_eligilibty - validate_not_discarded - end - - def valid_transfer_code? - return true if transfer_code == domain.transfer_code - - domain.add_epp_error('2202', nil, nil, 'Invalid authorization information') - false - end - - def validate_registrar - return unless user == domain.registrar - - domain.add_epp_error('2002', nil, nil, - I18n.t(:domain_already_belongs_to_the_querying_registrar)) - end - - def validate_eligilibty - return unless domain.non_transferable? - - domain.add_epp_error('2304', nil, nil, 'Object status prohibits operation') - end - - def validate_not_discarded - return unless domain.discarded? - - domain.add_epp_error('2106', nil, nil, 'Object is not eligible for transfer') - end - - def commit - bare_domain = Domain.find(domain.id) - ::DomainTransfer.request(bare_domain, user) - end - end -end