From 53a0ee3eab9807b3e6a0bfea0c3ebb0154226163 Mon Sep 17 00:00:00 2001 From: Martin Edenhofer Date: Sat, 29 Jun 2013 02:13:03 +0200 Subject: [PATCH] Moved to support client notify via module application base. --- app/models/observer/web_socket_notify.rb | 29 ------------------------ app/models/ticket.rb | 3 +++ app/models/ticket/article.rb | 3 +++ app/models/user.rb | 7 ++++-- config/application.rb | 3 +-- 5 files changed, 12 insertions(+), 33 deletions(-) delete mode 100644 app/models/observer/web_socket_notify.rb diff --git a/app/models/observer/web_socket_notify.rb b/app/models/observer/web_socket_notify.rb deleted file mode 100644 index d043d4ba9..000000000 --- a/app/models/observer/web_socket_notify.rb +++ /dev/null @@ -1,29 +0,0 @@ -# Copyright (C) 2012-2013 Zammad Foundation, http://zammad-foundation.org/ - -require 'session' - -class Observer::WebSocketNotify < ActiveRecord::Observer - observe :ticket, :user, 'ticket::_article' - - def after_create(record) - - # return if we run import mode - return if Setting.get('import_mode') - - Session.broadcast( - :event => record.class.name.downcase + ':created', - :data => { :id => record.id, :updated_at => record.updated_at } - ) - end - - def after_update(record) - - # return if we run import mode - return if Setting.get('import_mode') - puts "#{record.class.name.downcase} UPDATED " + record.updated_at.to_s - Session.broadcast( - :event => record.class.name.downcase + ':updated', - :data => { :id => record.id, :updated_at => record.updated_at } - ) - end -end diff --git a/app/models/ticket.rb b/app/models/ticket.rb index 732caf3c3..7f9c1b61a 100644 --- a/app/models/ticket.rb +++ b/app/models/ticket.rb @@ -7,6 +7,9 @@ class Ticket < ApplicationModel before_create :number_generate, :check_defaults before_update :check_defaults before_destroy :destroy_dependencies + after_create :notify_clients_after_create + after_update :notify_clients_after_update + after_destroy :notify_clients_after_destroy belongs_to :group has_many :articles, :class_name => 'Ticket::Article', :after_add => :cache_update, :after_remove => :cache_update diff --git a/app/models/ticket/article.rb b/app/models/ticket/article.rb index c51884aab..dd4c97855 100644 --- a/app/models/ticket/article.rb +++ b/app/models/ticket/article.rb @@ -6,6 +6,9 @@ class Ticket::Article < ApplicationModel belongs_to :ticket_article_type, :class_name => 'Ticket::Article::Type' belongs_to :ticket_article_sender, :class_name => 'Ticket::Article::Sender' belongs_to :created_by, :class_name => 'User' + after_create :notify_clients_after_create + after_update :notify_clients_after_update + after_destroy :notify_clients_after_destroy attr_accessor :attachments diff --git a/app/models/user.rb b/app/models/user.rb index b5744595d..3548e40c2 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -6,8 +6,11 @@ require 'organization' class User < ApplicationModel include Gmaps - before_create :check_name, :check_email, :check_login, :check_image, :check_geo, :check_password - before_update :check_password, :check_image, :check_geo, :check_email, :check_login_update + before_create :check_name, :check_email, :check_login, :check_image, :check_geo, :check_password + before_update :check_password, :check_image, :check_geo, :check_email, :check_login_update + after_create :notify_clients_after_create + after_update :notify_clients_after_update + after_destroy :notify_clients_after_destroy has_and_belongs_to_many :groups, :after_add => :cache_update, :after_remove => :cache_update has_and_belongs_to_many :roles, :after_add => :cache_update, :after_remove => :cache_update diff --git a/config/application.rb b/config/application.rb index e06424147..5591236e0 100644 --- a/config/application.rb +++ b/config/application.rb @@ -41,8 +41,7 @@ module Zammad 'observer::_ticket::_notification', 'observer::_tag::_ticket_history', 'observer::_ticket::_reset_new_state', - 'observer::_ticket::_escalation_calculation', - 'observer::_web_socket_notify' + 'observer::_ticket::_escalation_calculation' # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded. # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]