From 7a9a7c052f17530527ccf284fe88ae14a1f6b0ed Mon Sep 17 00:00:00 2001 From: Artur Beljajev Date: Fri, 24 Aug 2018 00:36:58 +0300 Subject: [PATCH] Rename `notifications.queued` to `read` --- app/controllers/epp/polls_controller.rb | 6 +++--- app/models/api_user.rb | 4 ++-- app/models/notification.rb | 8 ++++---- app/views/epp/poll/poll_ack.xml.builder | 2 +- app/views/epp/poll/poll_keyrelay.xml.builder | 2 +- app/views/epp/poll/poll_req.xml.builder | 2 +- .../20180823212823_rename_notifications_queued_to_read.rb | 5 +++++ db/structure.sql | 4 +++- test/fixtures/notifications.yml | 6 +++--- test/integration/epp/poll_test.rb | 8 ++++---- test/models/notification_test.rb | 6 +++--- 11 files changed, 30 insertions(+), 23 deletions(-) create mode 100644 db/migrate/20180823212823_rename_notifications_queued_to_read.rb diff --git a/app/controllers/epp/polls_controller.rb b/app/controllers/epp/polls_controller.rb index ef41bfaf7..0ce1ff5c7 100644 --- a/app/controllers/epp/polls_controller.rb +++ b/app/controllers/epp/polls_controller.rb @@ -9,7 +9,7 @@ class Epp::PollsController < EppController private def req_poll - @notification = current_user.queued_notifications.last + @notification = current_user.unread_notifications.last render_epp_response 'epp/poll/poll_no_messages' and return unless @notification if @notification.attached_obj_type && @notification.attached_obj_id @@ -36,7 +36,7 @@ class Epp::PollsController < EppController end def ack_poll - @notification = current_user.queued_notifications.find_by(id: params[:parsed_frame].css('poll').first['msgID']) + @notification = current_user.unread_notifications.find_by(id: params[:parsed_frame].css('poll').first['msgID']) unless @notification epp_errors << { @@ -47,7 +47,7 @@ class Epp::PollsController < EppController handle_errors and return end - handle_errors(@notification) and return unless @notification.dequeue + handle_errors(@notification) and return unless @notification.mark_as_read render_epp_response 'epp/poll/poll_ack' end diff --git a/app/models/api_user.rb b/app/models/api_user.rb index 8d5018568..850e92730 100644 --- a/app/models/api_user.rb +++ b/app/models/api_user.rb @@ -79,8 +79,8 @@ class ApiUser < User username end - def queued_notifications - registrar.notifications.queued + def unread_notifications + registrar.notifications.unread end def registrar_pki_ok?(crt, cn) diff --git a/app/models/notification.rb b/app/models/notification.rb index 5fbdeccb5..1819e86dc 100644 --- a/app/models/notification.rb +++ b/app/models/notification.rb @@ -2,14 +2,14 @@ class Notification < ActiveRecord::Base include Versions # version/notification_version.rb belongs_to :registrar, required: true - before_create -> { self.queued = true } + before_create -> { self.read = false } - scope :queued, -> { where(queued: true) } + scope :unread, -> { where(read: false) } validates :text, presence: true - def dequeue - self.queued = false + def mark_as_read + self.read = true save end diff --git a/app/views/epp/poll/poll_ack.xml.builder b/app/views/epp/poll/poll_ack.xml.builder index 1ee6fa315..835f13b86 100644 --- a/app/views/epp/poll/poll_ack.xml.builder +++ b/app/views/epp/poll/poll_ack.xml.builder @@ -4,7 +4,7 @@ xml.epp_head do xml.msg 'Command completed successfully' end - xml.tag!('msgQ', 'count' => current_user.queued_notifications.count, 'id' => @notification.id) + xml.tag!('msgQ', 'count' => current_user.unread_notifications.count, 'id' => @notification.id) render('epp/shared/trID', builder: xml) end diff --git a/app/views/epp/poll/poll_keyrelay.xml.builder b/app/views/epp/poll/poll_keyrelay.xml.builder index 606f03936..c5415273a 100644 --- a/app/views/epp/poll/poll_keyrelay.xml.builder +++ b/app/views/epp/poll/poll_keyrelay.xml.builder @@ -10,7 +10,7 @@ xml.epp( xml.msg 'Command completed successfully; ack to dequeue' end - xml.tag!('msgQ', 'count' => current_user.queued_notifications.count, 'id' => @notification.id) do + xml.tag!('msgQ', 'count' => current_user.unread_notifications.count, 'id' => @notification.id) do xml.qDate @notification.created_at.try(:iso8601) xml.msg @notification.text end diff --git a/app/views/epp/poll/poll_req.xml.builder b/app/views/epp/poll/poll_req.xml.builder index 3eb78f7a1..6a3893c69 100644 --- a/app/views/epp/poll/poll_req.xml.builder +++ b/app/views/epp/poll/poll_req.xml.builder @@ -4,7 +4,7 @@ xml.epp_head do xml.msg 'Command completed successfully; ack to dequeue' end - xml.tag!('msgQ', 'count' => current_user.queued_notifications.count, 'id' => @notification.id) do + xml.tag!('msgQ', 'count' => current_user.unread_notifications.count, 'id' => @notification.id) do xml.qDate @notification.created_at.try(:iso8601) xml.msg @notification.text end diff --git a/db/migrate/20180823212823_rename_notifications_queued_to_read.rb b/db/migrate/20180823212823_rename_notifications_queued_to_read.rb new file mode 100644 index 000000000..e0cc8f7bd --- /dev/null +++ b/db/migrate/20180823212823_rename_notifications_queued_to_read.rb @@ -0,0 +1,5 @@ +class RenameNotificationsQueuedToRead < ActiveRecord::Migration + def change + rename_column :notifications, :queued, :read + end +end diff --git a/db/structure.sql b/db/structure.sql index 355b5ef63..cc4f2e29c 100644 --- a/db/structure.sql +++ b/db/structure.sql @@ -2002,7 +2002,7 @@ CREATE TABLE public.notifications ( text character varying NOT NULL, attached_obj_type character varying, attached_obj_id integer, - queued boolean, + read boolean, created_at timestamp without time zone, updated_at timestamp without time zone, creator_str character varying, @@ -4765,3 +4765,5 @@ INSERT INTO schema_migrations (version) VALUES ('20180823163548'); INSERT INTO schema_migrations (version) VALUES ('20180823174331'); +INSERT INTO schema_migrations (version) VALUES ('20180823212823'); + diff --git a/test/fixtures/notifications.yml b/test/fixtures/notifications.yml index aaa601a61..37a69d443 100644 --- a/test/fixtures/notifications.yml +++ b/test/fixtures/notifications.yml @@ -1,15 +1,15 @@ greeting: text: Welcome! - queued: true + read: false registrar: bestnames domain_deleted: text: Your domain has been deleted - queued: true + read: false registrar: bestnames created_at: <%= Time.zone.parse('2010-07-05').to_s(:db) %> farewell: text: Good bye! - queued: true + read: false registrar: goodnames \ No newline at end of file diff --git a/test/integration/epp/poll_test.rb b/test/integration/epp/poll_test.rb index 71d74d622..30f7a2891 100644 --- a/test/integration/epp/poll_test.rb +++ b/test/integration/epp/poll_test.rb @@ -44,7 +44,7 @@ class EppPollTest < ApplicationIntegrationTest assert_equal 1, response_xml.css('result').size end - def test_dequeue_notification + def test_mark_as_read notification = notifications(:greeting) request_xml = <<-XML @@ -60,14 +60,14 @@ class EppPollTest < ApplicationIntegrationTest notification.reload response_xml = Nokogiri::XML(response.body) - assert_not notification.queued? + assert notification.read? assert_equal 1000.to_s, response_xml.at_css('result')[:code] assert_equal 1, response_xml.css('result').size assert_equal 1.to_s, response_xml.at_css('msgQ')[:count] assert_equal notification.id.to_s, response_xml.at_css('msgQ')[:id] end - def test_notification_of_other_registrars_cannot_be_dequeued + def test_notification_of_other_registrars_cannot_be_marked_as_read notification = notifications(:farewell) request_xml = <<-XML @@ -82,7 +82,7 @@ class EppPollTest < ApplicationIntegrationTest response_xml = Nokogiri::XML(response.body) notification.reload - assert notification.queued? + assert_not notification.read? assert_equal 2303.to_s, response_xml.at_css('result')[:code] end diff --git a/test/models/notification_test.rb b/test/models/notification_test.rb index c9ee91a8e..da8f3bdec 100644 --- a/test/models/notification_test.rb +++ b/test/models/notification_test.rb @@ -19,9 +19,9 @@ class NotificationTest < ActiveSupport::TestCase assert @notification.invalid? end - def test_dequeue - @notification.dequeue + def test_mark_as_read + @notification.mark_as_read @notification.reload - assert_not @notification.queued? + assert @notification.read? end end \ No newline at end of file