mirror of
https://github.com/internetee/registry.git
synced 2025-08-04 00:42:04 +02:00
Moved notifications about automatic contact name update to bulk change poll message
This commit is contained in:
parent
e4d56fe576
commit
216048463d
18 changed files with 201 additions and 96 deletions
|
@ -12,7 +12,7 @@ class Ability
|
|||
@user.roles&.each { |role| send(role) }
|
||||
when 'ApiUser'
|
||||
@user.roles&.each { |role| send(role) }
|
||||
when 'RegistrantUser'
|
||||
when 'RegistrantUser'
|
||||
static_registrant
|
||||
end
|
||||
|
||||
|
|
|
@ -2,18 +2,37 @@ class Action < ApplicationRecord
|
|||
has_paper_trail versions: { class_name: 'Version::ActionVersion' }
|
||||
|
||||
belongs_to :user
|
||||
belongs_to :contact
|
||||
belongs_to :contact, optional: true
|
||||
has_many :subactions, class_name: 'Action', foreign_key: 'bulk_action_id', dependent: :destroy
|
||||
belongs_to :bulk_action, class_name: 'Action', optional: true
|
||||
|
||||
validates :operation, inclusion: { in: proc { |action| action.class.valid_operations } }
|
||||
|
||||
class << self
|
||||
def valid_operations
|
||||
%w[update]
|
||||
%w[update bulk_update]
|
||||
end
|
||||
end
|
||||
|
||||
def notification_key
|
||||
raise 'Action object is missing' unless contact
|
||||
raise 'Action object is missing' unless bulk_action? || contact
|
||||
|
||||
"contact_#{operation}".to_sym
|
||||
end
|
||||
|
||||
def bulk_action?
|
||||
!!subactions.exists?
|
||||
end
|
||||
|
||||
def to_non_available_contact_codes
|
||||
return [] unless bulk_action?
|
||||
|
||||
subactions.map do |a|
|
||||
{
|
||||
code: a.contact&.code,
|
||||
avail: 0,
|
||||
reason: 'in use',
|
||||
}
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
2
app/models/bulk_action.rb
Normal file
2
app/models/bulk_action.rb
Normal file
|
@ -0,0 +1,2 @@
|
|||
class BulkAction < Action
|
||||
end
|
|
@ -47,7 +47,7 @@ class Epp::Contact < Contact
|
|||
codes = codes.map { |c| c.include?(':') ? c : "#{reg}:#{c}" }
|
||||
|
||||
res = []
|
||||
codes.map { |c| c.include?(':') ? c : "#{reg}:#{c}" }.map { |c| c.strip.upcase }.each do |x|
|
||||
codes.map { |c| c.strip.upcase }.each do |x|
|
||||
c = find_by_epp_code(x)
|
||||
res << (c ? { code: c.code, avail: 0, reason: 'in use' } : { code: x, avail: 1 })
|
||||
end
|
||||
|
|
|
@ -2,7 +2,7 @@ class Notification < ApplicationRecord
|
|||
include Versions # version/notification_version.rb
|
||||
|
||||
belongs_to :registrar
|
||||
belongs_to :action
|
||||
belongs_to :action, optional: true
|
||||
|
||||
scope :unread, -> { where(read: false) }
|
||||
|
||||
|
|
|
@ -112,13 +112,17 @@ class RegistrantUser < User
|
|||
end
|
||||
|
||||
def update_related_contacts
|
||||
contacts = Contact.where(ident: ident, ident_country_code: country.alpha2)
|
||||
grouped_contacts = Contact.where(ident: ident, ident_country_code: country.alpha2)
|
||||
.where('UPPER(name) != UPPER(?)', username)
|
||||
|
||||
contacts.each do |contact|
|
||||
contact.update(name: username)
|
||||
action = actions.create!(contact: contact, operation: :update)
|
||||
contact.registrar.notify(action)
|
||||
.includes(:registrar).group_by { |c| c.registrar }
|
||||
grouped_contacts.each do |registrar, contacts|
|
||||
bulk_action, action = actions.create!(operation: :bulk_update) if contacts.size > 1
|
||||
contacts.each do |c|
|
||||
if c.update(name: username)
|
||||
action = actions.create!(contact: c, operation: :update, bulk_action_id: bulk_action&.id)
|
||||
end
|
||||
end
|
||||
registrar.notify(bulk_action || action)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -218,8 +218,15 @@ class Registrar < ApplicationRecord
|
|||
end
|
||||
|
||||
def notify(action)
|
||||
text = I18n.t("notifications.texts.#{action.notification_key}", contact: action.contact.code)
|
||||
notifications.create!(text: text)
|
||||
text = I18n.t("notifications.texts.#{action.notification_key}", contact: action.contact&.code,
|
||||
count: action.subactions&.count)
|
||||
if action.bulk_action?
|
||||
notifications.create!(text: text, action_id: action.id,
|
||||
attached_obj_type: 'BulkAction',
|
||||
attached_obj_id: action.id)
|
||||
else
|
||||
notifications.create!(text: text)
|
||||
end
|
||||
end
|
||||
|
||||
def e_invoice_iban
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue