mirror of
https://github.com/internetee/registry.git
synced 2025-07-23 19:20:37 +02:00
Rename notifications.queued
to read
This commit is contained in:
parent
dfff6f6d12
commit
7a9a7c052f
11 changed files with 30 additions and 23 deletions
|
@ -9,7 +9,7 @@ class Epp::PollsController < EppController
|
||||||
private
|
private
|
||||||
|
|
||||||
def req_poll
|
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
|
render_epp_response 'epp/poll/poll_no_messages' and return unless @notification
|
||||||
if @notification.attached_obj_type && @notification.attached_obj_id
|
if @notification.attached_obj_type && @notification.attached_obj_id
|
||||||
|
@ -36,7 +36,7 @@ class Epp::PollsController < EppController
|
||||||
end
|
end
|
||||||
|
|
||||||
def ack_poll
|
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
|
unless @notification
|
||||||
epp_errors << {
|
epp_errors << {
|
||||||
|
@ -47,7 +47,7 @@ class Epp::PollsController < EppController
|
||||||
handle_errors and return
|
handle_errors and return
|
||||||
end
|
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'
|
render_epp_response 'epp/poll/poll_ack'
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -79,8 +79,8 @@ class ApiUser < User
|
||||||
username
|
username
|
||||||
end
|
end
|
||||||
|
|
||||||
def queued_notifications
|
def unread_notifications
|
||||||
registrar.notifications.queued
|
registrar.notifications.unread
|
||||||
end
|
end
|
||||||
|
|
||||||
def registrar_pki_ok?(crt, cn)
|
def registrar_pki_ok?(crt, cn)
|
||||||
|
|
|
@ -2,14 +2,14 @@ class Notification < ActiveRecord::Base
|
||||||
include Versions # version/notification_version.rb
|
include Versions # version/notification_version.rb
|
||||||
belongs_to :registrar, required: true
|
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
|
validates :text, presence: true
|
||||||
|
|
||||||
def dequeue
|
def mark_as_read
|
||||||
self.queued = false
|
self.read = true
|
||||||
save
|
save
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,7 @@ xml.epp_head do
|
||||||
xml.msg 'Command completed successfully'
|
xml.msg 'Command completed successfully'
|
||||||
end
|
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)
|
render('epp/shared/trID', builder: xml)
|
||||||
end
|
end
|
||||||
|
|
|
@ -10,7 +10,7 @@ xml.epp(
|
||||||
xml.msg 'Command completed successfully; ack to dequeue'
|
xml.msg 'Command completed successfully; ack to dequeue'
|
||||||
end
|
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.qDate @notification.created_at.try(:iso8601)
|
||||||
xml.msg @notification.text
|
xml.msg @notification.text
|
||||||
end
|
end
|
||||||
|
|
|
@ -4,7 +4,7 @@ xml.epp_head do
|
||||||
xml.msg 'Command completed successfully; ack to dequeue'
|
xml.msg 'Command completed successfully; ack to dequeue'
|
||||||
end
|
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.qDate @notification.created_at.try(:iso8601)
|
||||||
xml.msg @notification.text
|
xml.msg @notification.text
|
||||||
end
|
end
|
||||||
|
|
|
@ -0,0 +1,5 @@
|
||||||
|
class RenameNotificationsQueuedToRead < ActiveRecord::Migration
|
||||||
|
def change
|
||||||
|
rename_column :notifications, :queued, :read
|
||||||
|
end
|
||||||
|
end
|
|
@ -2002,7 +2002,7 @@ CREATE TABLE public.notifications (
|
||||||
text character varying NOT NULL,
|
text character varying NOT NULL,
|
||||||
attached_obj_type character varying,
|
attached_obj_type character varying,
|
||||||
attached_obj_id integer,
|
attached_obj_id integer,
|
||||||
queued boolean,
|
read boolean,
|
||||||
created_at timestamp without time zone,
|
created_at timestamp without time zone,
|
||||||
updated_at timestamp without time zone,
|
updated_at timestamp without time zone,
|
||||||
creator_str character varying,
|
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 ('20180823174331');
|
||||||
|
|
||||||
|
INSERT INTO schema_migrations (version) VALUES ('20180823212823');
|
||||||
|
|
||||||
|
|
6
test/fixtures/notifications.yml
vendored
6
test/fixtures/notifications.yml
vendored
|
@ -1,15 +1,15 @@
|
||||||
greeting:
|
greeting:
|
||||||
text: Welcome!
|
text: Welcome!
|
||||||
queued: true
|
read: false
|
||||||
registrar: bestnames
|
registrar: bestnames
|
||||||
|
|
||||||
domain_deleted:
|
domain_deleted:
|
||||||
text: Your domain has been deleted
|
text: Your domain has been deleted
|
||||||
queued: true
|
read: false
|
||||||
registrar: bestnames
|
registrar: bestnames
|
||||||
created_at: <%= Time.zone.parse('2010-07-05').to_s(:db) %>
|
created_at: <%= Time.zone.parse('2010-07-05').to_s(:db) %>
|
||||||
|
|
||||||
farewell:
|
farewell:
|
||||||
text: Good bye!
|
text: Good bye!
|
||||||
queued: true
|
read: false
|
||||||
registrar: goodnames
|
registrar: goodnames
|
|
@ -44,7 +44,7 @@ class EppPollTest < ApplicationIntegrationTest
|
||||||
assert_equal 1, response_xml.css('result').size
|
assert_equal 1, response_xml.css('result').size
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_dequeue_notification
|
def test_mark_as_read
|
||||||
notification = notifications(:greeting)
|
notification = notifications(:greeting)
|
||||||
|
|
||||||
request_xml = <<-XML
|
request_xml = <<-XML
|
||||||
|
@ -60,14 +60,14 @@ class EppPollTest < ApplicationIntegrationTest
|
||||||
notification.reload
|
notification.reload
|
||||||
response_xml = Nokogiri::XML(response.body)
|
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 1000.to_s, response_xml.at_css('result')[:code]
|
||||||
assert_equal 1, response_xml.css('result').size
|
assert_equal 1, response_xml.css('result').size
|
||||||
assert_equal 1.to_s, response_xml.at_css('msgQ')[:count]
|
assert_equal 1.to_s, response_xml.at_css('msgQ')[:count]
|
||||||
assert_equal notification.id.to_s, response_xml.at_css('msgQ')[:id]
|
assert_equal notification.id.to_s, response_xml.at_css('msgQ')[:id]
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_notification_of_other_registrars_cannot_be_dequeued
|
def test_notification_of_other_registrars_cannot_be_marked_as_read
|
||||||
notification = notifications(:farewell)
|
notification = notifications(:farewell)
|
||||||
|
|
||||||
request_xml = <<-XML
|
request_xml = <<-XML
|
||||||
|
@ -82,7 +82,7 @@ class EppPollTest < ApplicationIntegrationTest
|
||||||
response_xml = Nokogiri::XML(response.body)
|
response_xml = Nokogiri::XML(response.body)
|
||||||
notification.reload
|
notification.reload
|
||||||
|
|
||||||
assert notification.queued?
|
assert_not notification.read?
|
||||||
assert_equal 2303.to_s, response_xml.at_css('result')[:code]
|
assert_equal 2303.to_s, response_xml.at_css('result')[:code]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -19,9 +19,9 @@ class NotificationTest < ActiveSupport::TestCase
|
||||||
assert @notification.invalid?
|
assert @notification.invalid?
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_dequeue
|
def test_mark_as_read
|
||||||
@notification.dequeue
|
@notification.mark_as_read
|
||||||
@notification.reload
|
@notification.reload
|
||||||
assert_not @notification.queued?
|
assert @notification.read?
|
||||||
end
|
end
|
||||||
end
|
end
|
Loading…
Add table
Add a link
Reference in a new issue