mirror of
https://github.com/internetee/registry.git
synced 2025-07-23 03:06:14 +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
|
||||
|
||||
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
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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,
|
||||
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');
|
||||
|
||||
|
|
6
test/fixtures/notifications.yml
vendored
6
test/fixtures/notifications.yml
vendored
|
@ -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
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
Loading…
Add table
Add a link
Reference in a new issue