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
|
||||
|
||||
OnlineNotification.seen(
|
||||
:id => 2,
|
||||
:user => UserObject, # optional, if passed all
|
||||
# notfications for the given user are marked as seen
|
||||
:id => 2,
|
||||
)
|
||||
|
||||
=end
|
||||
|
@ -108,18 +106,33 @@ return all online notifications of an user
|
|||
|
||||
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
|
||||
|
||||
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 )
|
||||
notifications = OnlineNotification.where(
|
||||
:object_lookup_id => object_id,
|
||||
:o_id => o_id,
|
||||
).
|
||||
order( 'created_at DESC, id DESC' ).
|
||||
limit( 10_000 )
|
||||
if seen == nil
|
||||
notifications = OnlineNotification.where(
|
||||
:object_lookup_id => object_id,
|
||||
:o_id => o_id,
|
||||
).
|
||||
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 = []
|
||||
notifications.each do |item|
|
||||
data = item.attributes
|
||||
|
@ -134,6 +147,27 @@ return all online notifications of an object
|
|||
|
||||
=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
|
||||
|
||||
OnlineNotification.list_full( user )
|
||||
|
|
|
@ -116,6 +116,7 @@ merge tickets
|
|||
ticket = Ticket.find(123)
|
||||
result = ticket.merge_to(
|
||||
:ticket_id => 123,
|
||||
:user_id => 123,
|
||||
)
|
||||
|
||||
returns
|
||||
|
@ -141,11 +142,13 @@ returns
|
|||
|
||||
# create new merge article
|
||||
Ticket::Article.create(
|
||||
:ticket_id => self.id,
|
||||
:type_id => Ticket::Article::Type.lookup( :name => 'note' ).id,
|
||||
:sender_id => Ticket::Article::Sender.lookup( :name => Z_ROLENAME_AGENT ).id,
|
||||
:body => 'merged',
|
||||
:internal => false
|
||||
:ticket_id => self.id,
|
||||
:type_id => Ticket::Article::Type.lookup( :name => 'note' ).id,
|
||||
:sender_id => Ticket::Article::Sender.lookup( :name => Z_ROLENAME_AGENT ).id,
|
||||
:body => 'merged',
|
||||
:internal => false,
|
||||
:created_by_id => data[:user_id],
|
||||
:updated_by_id => data[:user_id],
|
||||
)
|
||||
|
||||
# add history to both
|
||||
|
@ -167,6 +170,11 @@ returns
|
|||
|
||||
# save ticket
|
||||
self.save
|
||||
|
||||
# set all online notifications to seen
|
||||
OnlineNotification.seen_by_object( 'Ticket', self.id )
|
||||
|
||||
true
|
||||
end
|
||||
|
||||
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 = []
|
||||
tests.each { |test|
|
||||
|
@ -112,6 +157,18 @@ class OnlineNotificationTest < ActiveSupport::TestCase
|
|||
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
|
||||
tickets.each { |ticket|
|
||||
ticket_id = ticket.id
|
||||
|
@ -120,7 +177,7 @@ class OnlineNotificationTest < ActiveSupport::TestCase
|
|||
assert( !found, "Ticket destroyed")
|
||||
|
||||
# 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")
|
||||
}
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue