Check if online notifications are deleted after ticket destroy.

This commit is contained in:
Martin Edenhofer 2015-04-01 13:14:46 +02:00
parent 95ad1ff355
commit 11edfc8780
3 changed files with 46 additions and 11 deletions

View file

@ -13,12 +13,12 @@ class OnlineNotification < ApplicationModel
add a new online notification for this user add a new online notification for this user
OnlineNotification.add( OnlineNotification.add(
:type => 'Assigned to you', :type => 'Assigned to you',
:object => 'Ticket', :object => 'Ticket',
:o_id => ticket.id, :o_id => ticket.id,
:seen => false, :seen => false,
:created_by_id => 1, :created_by_id => 1,
:user_id => 2, :user_id => 2,
) )
=end =end
@ -50,9 +50,9 @@ add a new online notification for this user
mark online notification as seen mark online notification as seen
OnlineNotification.seen( OnlineNotification.seen(
:id => 2, :id => 2,
:user => UserObject, #optional, if passed all :user => UserObject, # optional, if passed all
#notfications for the given user are marked as seen # notfications for the given user are marked as seen
) )
=end =end
@ -106,6 +106,34 @@ return all online notifications of an user
=begin =begin
return all online notifications of an object
notifications = OnlineNotification.by_object( 'Ticket', 123 )
=end
def self.by_object( object_name, o_id )
object_id = ObjectLookup.by_name( object_name )
notifications = OnlineNotification.where(
:object_lookup_id => object_id,
:o_id => o_id,
).
order( 'created_at DESC, id DESC' ).
limit( 10_000 )
list = []
notifications.each do |item|
data = item.attributes
data['object'] = ObjectLookup.by_id( data['object_lookup_id'] )
data['type'] = TypeLookup.by_id( data['type_lookup_id'] )
data.delete('object_lookup_id')
data.delete('type_lookup_id')
list.push data
end
list
end
=begin
return all online notifications of an user with assets return all online notifications of an user with assets
OnlineNotification.list_full( user ) OnlineNotification.list_full( user )

View file

@ -213,6 +213,9 @@ returns
# delete articles # delete articles
self.articles.destroy_all self.articles.destroy_all
# destroy online notifications
OnlineNotification.remove( self.class.to_s, self.id )
end end
end end

View file

@ -2,8 +2,8 @@
require 'test_helper' require 'test_helper'
class OnlineNotificationTest < ActiveSupport::TestCase class OnlineNotificationTest < ActiveSupport::TestCase
role = Role.lookup( :name => 'Agent' ) role = Role.lookup( :name => 'Agent' )
group = Group.lookup( :name => 'Users' ) group = Group.lookup( :name => 'Users' )
agent_user1 = User.create_or_update( agent_user1 = User.create_or_update(
:login => 'agent_online_notify1', :login => 'agent_online_notify1',
:firstname => 'Bob', :firstname => 'Bob',
@ -118,6 +118,10 @@ class OnlineNotificationTest < ActiveSupport::TestCase
ticket.destroy ticket.destroy
found = Ticket.where( :id => ticket_id ).first found = Ticket.where( :id => ticket_id ).first
assert( !found, "Ticket destroyed") assert( !found, "Ticket destroyed")
# check if notifications for ticket still exist
notifications = OnlineNotification.by_object( 'Ticket', ticket_id )
assert( notifications.empty?, "still notifications for destroyed ticket available")
} }
end end