feat(admin): notify registrar about domain status changes

- Add inform_registrar_about_status_changes method to detect added and removed statuses after domain update.
- Send notification to registrar with details of which statuses were set and which were removed.
- Integrate notification logic into domain update action.
This commit is contained in:
oleghasjanov 2025-07-17 15:04:48 +03:00
parent fa03ab92dd
commit a864056fbd
2 changed files with 37 additions and 0 deletions

View file

@ -31,6 +31,7 @@ module Admin
if @domain.update(dp)
flash[:notice] = I18n.t('domain_updated')
inform_registrar_about_status_changes
redirect_to [:admin, @domain]
else
@domain.reload
@ -111,6 +112,20 @@ module Admin
end
end
def inform_registrar_about_status_changes
return unless @domain.saved_change_to_statuses?
old_statuses, new_statuses = @domain.saved_change_to_statuses
removed = old_statuses - new_statuses
added = new_statuses - old_statuses
msg = []
msg << "Set on #{@domain.name}: #{added.join(', ')}" unless added.empty?
msg << "Removed from #{@domain.name}: #{removed.join(', ')}" unless removed.empty?
@domain.registrar.notifications.create!(text: msg.join('. ')) if msg.any?
end
def build_associations
@server_statuses = @domain.statuses.select { |x| DomainStatus::SERVER_STATUSES.include?(x) }
@server_statuses = [nil] if @server_statuses.empty?