Add Registrant API contact update action

Closes #849
This commit is contained in:
Artur Beljajev 2018-08-20 17:19:54 +03:00
parent 90ed23f64d
commit b6ecae6a35
41 changed files with 1239 additions and 61 deletions

17
app/models/action.rb Normal file
View file

@ -0,0 +1,17 @@
class Action < ActiveRecord::Base
belongs_to :user
belongs_to :contact
validates :operation, inclusion: { in: proc { |action| action.class.valid_operations } }
class << self
def valid_operations
%w[update]
end
end
def notification_key
raise 'Action object is missing' unless contact
"contact_#{operation}".to_sym
end
end

View file

@ -526,4 +526,20 @@ class Contact < ActiveRecord::Base
domain_names
end
def address=(address)
self.street = address.street
self.zip = address.zip
self.city = address.city
self.state = address.state
self.country_code = address.country_code
end
def address
Address.new(street, zip, city, state, country_code)
end
def managed_by?(registrant_user)
ident == registrant_user.ident
end
end

View file

@ -0,0 +1,25 @@
class Contact
class Address
attr_reader :street
attr_reader :zip
attr_reader :city
attr_reader :state
attr_reader :country_code
def initialize(street, zip, city, state, country_code)
@street = street
@zip = zip
@city = city
@state = state
@country_code = country_code
end
def ==(other)
(street == other.street) &&
(zip == other.zip) &&
(city == other.city) &&
(state == other.state) &&
(country_code == other.country_code)
end
end
end

View file

@ -1,6 +1,8 @@
class Notification < ActiveRecord::Base
include Versions # version/notification_version.rb
belongs_to :registrar
belongs_to :action
scope :unread, -> { where(read: false) }
@ -20,7 +22,7 @@ class Notification < ActiveRecord::Base
# Needed for EPP log
def name
"-"
''
end
private

View file

@ -56,6 +56,14 @@ class RegistrantUser < User
username
end
def first_name
username.split.first
end
def last_name
username.split.second
end
class << self
def find_or_create_by_idc_data(idc_data, issuer_organization)
return false if idc_data.blank?

View file

@ -157,6 +157,11 @@ class Registrar < ActiveRecord::Base
end
end
def notify(action)
text = I18n.t("notifications.texts.#{action.notification_key}", contact: action.contact.code)
notifications.create!(text: text)
end
private
def set_defaults

View file

@ -1,6 +1,8 @@
class User < ActiveRecord::Base
include Versions # version/user_version.rb
has_many :actions, dependent: :restrict_with_exception
attr_accessor :phone
def id_role_username