Fixed issue #2405 - Unable to load Zammad in web browser, because of online notification of ticket which was already deleted in the meantime.
This commit is contained in:
parent
5e05fadbb8
commit
7326122e28
6 changed files with 94 additions and 10 deletions
|
@ -49,6 +49,9 @@ add a new activity entry for an object
|
||||||
permission_id = permission.id
|
permission_id = permission.id
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# check if object for online notification exists
|
||||||
|
exists_by_object_and_id?(data[:object], data[:o_id])
|
||||||
|
|
||||||
# check newest entry - is needed
|
# check newest entry - is needed
|
||||||
result = ActivityStream.where(
|
result = ActivityStream.where(
|
||||||
o_id: data[:o_id],
|
o_id: data[:o_id],
|
||||||
|
|
|
@ -18,6 +18,7 @@ class ApplicationModel < ActiveRecord::Base
|
||||||
include ApplicationModel::ChecksImport
|
include ApplicationModel::ChecksImport
|
||||||
include ApplicationModel::CanTouchReferences
|
include ApplicationModel::CanTouchReferences
|
||||||
include ApplicationModel::CanQueryCaseInsensitiveWhereOrSql
|
include ApplicationModel::CanQueryCaseInsensitiveWhereOrSql
|
||||||
|
include ApplicationModel::HasExistsCheckByObjectAndId
|
||||||
|
|
||||||
self.abstract_class = true
|
self.abstract_class = true
|
||||||
end
|
end
|
||||||
|
|
|
@ -0,0 +1,35 @@
|
||||||
|
# Copyright (C) 2012-2016 Zammad Foundation, http://zammad-foundation.org/
|
||||||
|
module ApplicationModel::HasExistsCheckByObjectAndId
|
||||||
|
extend ActiveSupport::Concern
|
||||||
|
|
||||||
|
class_methods do
|
||||||
|
|
||||||
|
=begin
|
||||||
|
|
||||||
|
verify if referenced object exists
|
||||||
|
|
||||||
|
success = Model.exists_by_object_and_id('Ticket', 123)
|
||||||
|
|
||||||
|
returns
|
||||||
|
|
||||||
|
# true or will raise an exception
|
||||||
|
|
||||||
|
=end
|
||||||
|
|
||||||
|
def exists_by_object_and_id?(object, o_id)
|
||||||
|
|
||||||
|
begin
|
||||||
|
local_class = object.constantize
|
||||||
|
rescue => e
|
||||||
|
raise "Unable for get an instance of '#{object}': #{e.inspect}"
|
||||||
|
end
|
||||||
|
if !local_class.exists?(o_id)
|
||||||
|
raise ActiveRecord::RecordNotFound, "Unable for find reference object '#{object}.exists?(#{o_id})!"
|
||||||
|
end
|
||||||
|
|
||||||
|
true
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
|
@ -41,6 +41,9 @@ add a new online notification for this user
|
||||||
object_id = ObjectLookup.by_name(data[:object])
|
object_id = ObjectLookup.by_name(data[:object])
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# check if object for online notification exists
|
||||||
|
exists_by_object_and_id?(data[:object], data[:o_id])
|
||||||
|
|
||||||
record = {
|
record = {
|
||||||
o_id: data[:o_id],
|
o_id: data[:o_id],
|
||||||
object_lookup_id: object_id,
|
object_lookup_id: object_id,
|
||||||
|
|
|
@ -15,9 +15,11 @@ class RecentView < ApplicationModel
|
||||||
def self.log(object, o_id, user)
|
def self.log(object, o_id, user)
|
||||||
return if !access(object, o_id, user)
|
return if !access(object, o_id, user)
|
||||||
|
|
||||||
RecentView.create(o_id: o_id,
|
exists_by_object_and_id?(object, o_id)
|
||||||
recent_view_object_id: ObjectLookup.by_name(object),
|
|
||||||
created_by_id: user.id)
|
RecentView.create!(o_id: o_id,
|
||||||
|
recent_view_object_id: ObjectLookup.by_name(object),
|
||||||
|
created_by_id: user.id)
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.log_destroy(requested_object, requested_object_id)
|
def self.log_destroy(requested_object, requested_object_id)
|
||||||
|
|
|
@ -538,10 +538,22 @@ class OnlineNotificationTest < ActiveSupport::TestCase
|
||||||
end
|
end
|
||||||
|
|
||||||
test 'cleanup check' do
|
test 'cleanup check' do
|
||||||
|
|
||||||
|
ticket1 = Ticket.create(
|
||||||
|
group: @group,
|
||||||
|
customer_id: @customer_user.id,
|
||||||
|
owner_id: User.lookup(login: '-').id,
|
||||||
|
title: 'Unit Test 1 (äöüß)!',
|
||||||
|
state_id: Ticket::State.lookup(name: 'closed').id,
|
||||||
|
priority_id: Ticket::Priority.lookup(name: '2 normal').id,
|
||||||
|
updated_by_id: @agent_user1.id,
|
||||||
|
created_by_id: @agent_user1.id,
|
||||||
|
)
|
||||||
|
|
||||||
online_notification1 = OnlineNotification.add(
|
online_notification1 = OnlineNotification.add(
|
||||||
type: 'create',
|
type: 'create',
|
||||||
object: 'Ticket',
|
object: 'Ticket',
|
||||||
o_id: 123,
|
o_id: ticket1.id,
|
||||||
seen: false,
|
seen: false,
|
||||||
user_id: @agent_user1.id,
|
user_id: @agent_user1.id,
|
||||||
created_by_id: 1,
|
created_by_id: 1,
|
||||||
|
@ -552,7 +564,7 @@ class OnlineNotificationTest < ActiveSupport::TestCase
|
||||||
online_notification2 = OnlineNotification.add(
|
online_notification2 = OnlineNotification.add(
|
||||||
type: 'create',
|
type: 'create',
|
||||||
object: 'Ticket',
|
object: 'Ticket',
|
||||||
o_id: 123,
|
o_id: ticket1.id,
|
||||||
seen: true,
|
seen: true,
|
||||||
user_id: @agent_user1.id,
|
user_id: @agent_user1.id,
|
||||||
created_by_id: 1,
|
created_by_id: 1,
|
||||||
|
@ -563,7 +575,7 @@ class OnlineNotificationTest < ActiveSupport::TestCase
|
||||||
online_notification3 = OnlineNotification.add(
|
online_notification3 = OnlineNotification.add(
|
||||||
type: 'create',
|
type: 'create',
|
||||||
object: 'Ticket',
|
object: 'Ticket',
|
||||||
o_id: 123,
|
o_id: ticket1.id,
|
||||||
seen: false,
|
seen: false,
|
||||||
user_id: @agent_user1.id,
|
user_id: @agent_user1.id,
|
||||||
created_by_id: 1,
|
created_by_id: 1,
|
||||||
|
@ -574,7 +586,7 @@ class OnlineNotificationTest < ActiveSupport::TestCase
|
||||||
online_notification4 = OnlineNotification.add(
|
online_notification4 = OnlineNotification.add(
|
||||||
type: 'create',
|
type: 'create',
|
||||||
object: 'Ticket',
|
object: 'Ticket',
|
||||||
o_id: 123,
|
o_id: ticket1.id,
|
||||||
seen: true,
|
seen: true,
|
||||||
user_id: @agent_user1.id,
|
user_id: @agent_user1.id,
|
||||||
created_by_id: @agent_user1.id,
|
created_by_id: @agent_user1.id,
|
||||||
|
@ -585,7 +597,7 @@ class OnlineNotificationTest < ActiveSupport::TestCase
|
||||||
online_notification5 = OnlineNotification.add(
|
online_notification5 = OnlineNotification.add(
|
||||||
type: 'create',
|
type: 'create',
|
||||||
object: 'Ticket',
|
object: 'Ticket',
|
||||||
o_id: 123,
|
o_id: ticket1.id,
|
||||||
seen: true,
|
seen: true,
|
||||||
user_id: @agent_user1.id,
|
user_id: @agent_user1.id,
|
||||||
created_by_id: @agent_user2.id,
|
created_by_id: @agent_user2.id,
|
||||||
|
@ -596,7 +608,7 @@ class OnlineNotificationTest < ActiveSupport::TestCase
|
||||||
online_notification6 = OnlineNotification.add(
|
online_notification6 = OnlineNotification.add(
|
||||||
type: 'create',
|
type: 'create',
|
||||||
object: 'Ticket',
|
object: 'Ticket',
|
||||||
o_id: 123,
|
o_id: ticket1.id,
|
||||||
seen: true,
|
seen: true,
|
||||||
user_id: @agent_user1.id,
|
user_id: @agent_user1.id,
|
||||||
created_by_id: @agent_user1.id,
|
created_by_id: @agent_user1.id,
|
||||||
|
@ -607,7 +619,7 @@ class OnlineNotificationTest < ActiveSupport::TestCase
|
||||||
online_notification7 = OnlineNotification.add(
|
online_notification7 = OnlineNotification.add(
|
||||||
type: 'create',
|
type: 'create',
|
||||||
object: 'Ticket',
|
object: 'Ticket',
|
||||||
o_id: 123,
|
o_id: ticket1.id,
|
||||||
seen: true,
|
seen: true,
|
||||||
user_id: @agent_user1.id,
|
user_id: @agent_user1.id,
|
||||||
created_by_id: @agent_user2.id,
|
created_by_id: @agent_user2.id,
|
||||||
|
@ -628,4 +640,32 @@ class OnlineNotificationTest < ActiveSupport::TestCase
|
||||||
OnlineNotification.destroy_all
|
OnlineNotification.destroy_all
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test 'not existing object ref' do
|
||||||
|
assert_raises(RuntimeError) do
|
||||||
|
OnlineNotification.add(
|
||||||
|
type: 'create',
|
||||||
|
object: 'TicketNotExisting',
|
||||||
|
o_id: 123,
|
||||||
|
seen: false,
|
||||||
|
user_id: @agent_user1.id,
|
||||||
|
created_by_id: 1,
|
||||||
|
updated_by_id: 1,
|
||||||
|
created_at: Time.zone.now - 10.months,
|
||||||
|
updated_at: Time.zone.now - 10.months,
|
||||||
|
)
|
||||||
|
end
|
||||||
|
assert_raises(ActiveRecord::RecordNotFound) do
|
||||||
|
OnlineNotification.add(
|
||||||
|
type: 'create',
|
||||||
|
object: 'Ticket',
|
||||||
|
o_id: 123,
|
||||||
|
seen: false,
|
||||||
|
user_id: @agent_user1.id,
|
||||||
|
created_by_id: 1,
|
||||||
|
updated_by_id: 1,
|
||||||
|
created_at: Time.zone.now - 10.months,
|
||||||
|
updated_at: Time.zone.now - 10.months,
|
||||||
|
)
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue