[#593] Generate wiki content notifications in the JournalObserver - backported for 2.7

This will prevent the usage of the wrong wiki_content status.

The code is not overly pretty and deserves a thorough refactoring, but at
least it solves the problem at hand.
This commit is contained in:
Holger Just 2012-02-06 14:31:06 +01:00 committed by Holger Just
parent 6fd9bc490f
commit aa5be5132d
3 changed files with 19 additions and 28 deletions

View File

@ -16,8 +16,24 @@ class JournalObserver < ActiveRecord::Observer
attr_accessor :send_notification
def after_create(journal)
if journal.type == "IssueJournal" and !journal.initial? and send_notification
after_create_issue_journal(journal)
case journal.type
when "IssueJournal"
if !journal.initial? && send_notification
after_create_issue_journal(journal)
end
when "WikiContentJournal"
wiki_content = journal.journaled
wiki_page = wiki_content.page
if journal.initial?
if Setting.notified_events.include?('wiki_content_added')
Mailer.deliver_wiki_content_added(wiki_content)
end
else
if Setting.notified_events.include?('wiki_content_updated')
Mailer.deliver_wiki_content_updated(wiki_content)
end
end
end
clear_notification
end

View File

@ -1,25 +0,0 @@
#-- encoding: UTF-8
#-- copyright
# ChiliProject is a project management system.
#
# Copyright (C) 2010-2012 the ChiliProject Team
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# See doc/COPYRIGHT.rdoc for more details.
#++
class WikiContentObserver < ActiveRecord::Observer
def after_create(wiki_content)
Mailer.deliver_wiki_content_added(wiki_content) if Setting.notified_events.include?('wiki_content_added')
end
def after_update(wiki_content)
if wiki_content.text_changed?
Mailer.deliver_wiki_content_updated(wiki_content) if Setting.notified_events.include?('wiki_content_updated')
end
end
end

View File

@ -58,7 +58,7 @@ Rails::Initializer.run do |config|
# Activate observers that should always be running
# config.active_record.observers = :cacher, :garbage_collector
config.active_record.observers = :journal_observer, :message_observer, :issue_observer, :news_observer, :document_observer, :wiki_content_observer, :comment_observer
config.active_record.observers = :journal_observer, :message_observer, :issue_observer, :news_observer, :document_observer, :comment_observer
# Make Active Record use UTC-base instead of local time
# config.active_record.default_timezone = :utc