Set all notifications of merged ticket to seen.
This commit is contained in:
parent
045cf492c2
commit
e43f9a81e4
3 changed files with 116 additions and 17 deletions
|
@ -50,9 +50,7 @@ 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
|
|
||||||
# notfications for the given user are marked as seen
|
|
||||||
)
|
)
|
||||||
|
|
||||||
=end
|
=end
|
||||||
|
@ -108,18 +106,33 @@ return all online notifications of an user
|
||||||
|
|
||||||
return all online notifications of an object
|
return all online notifications of an object
|
||||||
|
|
||||||
notifications = OnlineNotification.by_object( 'Ticket', 123 )
|
notifications = OnlineNotification.list_by_object( 'Ticket', 123 )
|
||||||
|
|
||||||
|
optional with seend attribute
|
||||||
|
|
||||||
|
notifications = OnlineNotification.list_by_object( 'Ticket', 123, false )
|
||||||
|
|
||||||
|
|
||||||
=end
|
=end
|
||||||
|
|
||||||
def self.by_object( object_name, o_id )
|
def self.list_by_object( object_name, o_id, seen = nil)
|
||||||
object_id = ObjectLookup.by_name( object_name )
|
object_id = ObjectLookup.by_name( object_name )
|
||||||
notifications = OnlineNotification.where(
|
if seen == nil
|
||||||
:object_lookup_id => object_id,
|
notifications = OnlineNotification.where(
|
||||||
:o_id => o_id,
|
:object_lookup_id => object_id,
|
||||||
).
|
:o_id => o_id,
|
||||||
order( 'created_at DESC, id DESC' ).
|
).
|
||||||
limit( 10_000 )
|
order( 'created_at DESC, id DESC' ).
|
||||||
|
limit( 10_000 )
|
||||||
|
else
|
||||||
|
notifications = OnlineNotification.where(
|
||||||
|
:object_lookup_id => object_id,
|
||||||
|
:o_id => o_id,
|
||||||
|
:seen => seen,
|
||||||
|
).
|
||||||
|
order( 'created_at DESC, id DESC' ).
|
||||||
|
limit( 10_000 )
|
||||||
|
end
|
||||||
list = []
|
list = []
|
||||||
notifications.each do |item|
|
notifications.each do |item|
|
||||||
data = item.attributes
|
data = item.attributes
|
||||||
|
@ -134,6 +147,27 @@ return all online notifications of an object
|
||||||
|
|
||||||
=begin
|
=begin
|
||||||
|
|
||||||
|
mark online notification as seen by object
|
||||||
|
|
||||||
|
OnlineNotification.seen_by_object( 'Ticket', 123 )
|
||||||
|
|
||||||
|
=end
|
||||||
|
|
||||||
|
def self.seen_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,
|
||||||
|
:seen => false,
|
||||||
|
)
|
||||||
|
notifications.each do |notification|
|
||||||
|
notification.seen = true
|
||||||
|
notification.save
|
||||||
|
end
|
||||||
|
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 )
|
||||||
|
|
|
@ -116,6 +116,7 @@ merge tickets
|
||||||
ticket = Ticket.find(123)
|
ticket = Ticket.find(123)
|
||||||
result = ticket.merge_to(
|
result = ticket.merge_to(
|
||||||
:ticket_id => 123,
|
:ticket_id => 123,
|
||||||
|
:user_id => 123,
|
||||||
)
|
)
|
||||||
|
|
||||||
returns
|
returns
|
||||||
|
@ -141,11 +142,13 @@ returns
|
||||||
|
|
||||||
# create new merge article
|
# create new merge article
|
||||||
Ticket::Article.create(
|
Ticket::Article.create(
|
||||||
:ticket_id => self.id,
|
:ticket_id => self.id,
|
||||||
:type_id => Ticket::Article::Type.lookup( :name => 'note' ).id,
|
:type_id => Ticket::Article::Type.lookup( :name => 'note' ).id,
|
||||||
:sender_id => Ticket::Article::Sender.lookup( :name => Z_ROLENAME_AGENT ).id,
|
:sender_id => Ticket::Article::Sender.lookup( :name => Z_ROLENAME_AGENT ).id,
|
||||||
:body => 'merged',
|
:body => 'merged',
|
||||||
:internal => false
|
:internal => false,
|
||||||
|
:created_by_id => data[:user_id],
|
||||||
|
:updated_by_id => data[:user_id],
|
||||||
)
|
)
|
||||||
|
|
||||||
# add history to both
|
# add history to both
|
||||||
|
@ -167,6 +170,11 @@ returns
|
||||||
|
|
||||||
# save ticket
|
# save ticket
|
||||||
self.save
|
self.save
|
||||||
|
|
||||||
|
# set all online notifications to seen
|
||||||
|
OnlineNotification.seen_by_object( 'Ticket', self.id )
|
||||||
|
|
||||||
|
true
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
|
@ -77,6 +77,51 @@ class OnlineNotificationTest < ActiveSupport::TestCase
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
|
||||||
|
# test 2
|
||||||
|
{
|
||||||
|
:create => {
|
||||||
|
:ticket => {
|
||||||
|
:group_id => Group.lookup( :name => 'Users' ).id,
|
||||||
|
:customer_id => customer_user.id,
|
||||||
|
:owner_id => User.lookup( :login => '-' ).id,
|
||||||
|
:title => 'Unit Test 2 (äöüß)!',
|
||||||
|
:state_id => Ticket::State.lookup( :name => 'new' ).id,
|
||||||
|
:priority_id => Ticket::Priority.lookup( :name => '2 normal' ).id,
|
||||||
|
:updated_by_id => agent_user1.id,
|
||||||
|
:created_by_id => agent_user1.id,
|
||||||
|
},
|
||||||
|
:article => {
|
||||||
|
:updated_by_id => agent_user1.id,
|
||||||
|
:created_by_id => agent_user1.id,
|
||||||
|
:type_id => Ticket::Article::Type.lookup( :name => 'phone' ).id,
|
||||||
|
:sender_id => Ticket::Article::Sender.lookup( :name => 'Customer' ).id,
|
||||||
|
:from => 'Unit Test <unittest@example.com>',
|
||||||
|
:body => 'Unit Test 123',
|
||||||
|
:internal => false
|
||||||
|
},
|
||||||
|
},
|
||||||
|
:update => {
|
||||||
|
:ticket => {
|
||||||
|
:title => 'Unit Test 2 (äöüß) - update!',
|
||||||
|
:state_id => Ticket::State.lookup( :name => 'open' ).id,
|
||||||
|
:priority_id => Ticket::Priority.lookup( :name => '1 low' ).id,
|
||||||
|
:updated_by_id => customer_user.id,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
:check => [
|
||||||
|
{
|
||||||
|
:type => 'create',
|
||||||
|
:object => 'Ticket',
|
||||||
|
:created_by_id => agent_user1.id,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
:type => 'update',
|
||||||
|
:object => 'Ticket',
|
||||||
|
:created_by_id => customer_user.id,
|
||||||
|
},
|
||||||
|
]
|
||||||
|
},
|
||||||
]
|
]
|
||||||
tickets = []
|
tickets = []
|
||||||
tests.each { |test|
|
tests.each { |test|
|
||||||
|
@ -112,6 +157,18 @@ class OnlineNotificationTest < ActiveSupport::TestCase
|
||||||
notification_check( OnlineNotification.list(agent_user2, 10), test[:check] )
|
notification_check( OnlineNotification.list(agent_user2, 10), test[:check] )
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# merge tickets - also remove notifications of merged tickets
|
||||||
|
tickets[0].merge_to(
|
||||||
|
:ticket_id => tickets[1].id,
|
||||||
|
:user_id => 1,
|
||||||
|
)
|
||||||
|
notifications = OnlineNotification.list_by_object( 'Ticket', tickets[0].id, false )
|
||||||
|
assert( notifications.empty?, "still not seen notifications for merged ticket available")
|
||||||
|
|
||||||
|
notifications = OnlineNotification.list_by_object( 'Ticket', tickets[1].id, true )
|
||||||
|
assert( notifications.empty?, "no notifications for master ticket available")
|
||||||
|
|
||||||
|
|
||||||
# delete tickets
|
# delete tickets
|
||||||
tickets.each { |ticket|
|
tickets.each { |ticket|
|
||||||
ticket_id = ticket.id
|
ticket_id = ticket.id
|
||||||
|
@ -120,7 +177,7 @@ class OnlineNotificationTest < ActiveSupport::TestCase
|
||||||
assert( !found, "Ticket destroyed")
|
assert( !found, "Ticket destroyed")
|
||||||
|
|
||||||
# check if notifications for ticket still exist
|
# check if notifications for ticket still exist
|
||||||
notifications = OnlineNotification.by_object( 'Ticket', ticket_id )
|
notifications = OnlineNotification.list_by_object( 'Ticket', ticket_id )
|
||||||
assert( notifications.empty?, "still notifications for destroyed ticket available")
|
assert( notifications.empty?, "still notifications for destroyed ticket available")
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue