diff --git a/app/controllers/news_controller.rb b/app/controllers/news_controller.rb
index 57e0ff28d..3111f8274 100644
--- a/app/controllers/news_controller.rb
+++ b/app/controllers/news_controller.rb
@@ -31,6 +31,8 @@ class NewsController < ApplicationController
helper :watchers
helper :attachments
+ helper :issues
+ helper :custom_fields
def index
case params[:format]
@@ -68,6 +70,7 @@ class NewsController < ApplicationController
end
def show
+ @journals = @news.journals.visible.preload(:user, :details).reorder(:id).to_a
@comments = @news.comments.preload(:commented).to_a
@comments.reverse! if User.current.wants_comments_in_reverse_order?
@@ -105,6 +108,7 @@ class NewsController < ApplicationController
end
def update
+ @news.init_journal(User.current)
@news.safe_attributes = params[:news]
@news.save_attachments(params[:attachments] || (params[:news] && params[:news][:uploads]))
if @news.save
diff --git a/app/models/news.rb b/app/models/news.rb
index 40130ce4a..aebdded61 100644
--- a/app/models/news.rb
+++ b/app/models/news.rb
@@ -30,7 +30,9 @@ class News < ApplicationRecord
validates_length_of :summary, :maximum => 255
acts_as_attachable :edit_permission => :manage_news,
- :delete_permission => :manage_news
+ :delete_permission => :manage_news,
+ :after_add => :attachment_added,
+ :after_remove => :attachment_removed
acts_as_searchable :columns => ['title', 'summary', "#{table_name}.description"],
:preload => :project
acts_as_event :url => Proc.new {|o| {:controller => 'news', :action => 'show', :id => o.id}}
@@ -38,10 +40,17 @@ class News < ApplicationRecord
:author_key => :author_id
acts_as_watchable
acts_as_webhookable
+ acts_as_journalized :activity_type => 'news',
+ :attributes => %w(title summary description),
+ :permissions => {
+ :edit_notes => :manage_news,
+ :add_watchers => :manage_news
+ }
include News::Webhookable
after_create :add_author_as_watcher
after_create_commit :send_notification
+ after_save :create_journal
scope :visible, (lambda do |*args|
joins(:project).
@@ -54,6 +63,35 @@ class News < ApplicationRecord
!user.nil? && user.allowed_to?(:view_news, project)
end
+ def init_journal(user, notes = '')
+ @current_journal ||= Journal.new(:journalized => self, :user => user, :notes => notes)
+ end
+
+ attr_reader :current_journal
+
+ # Callback on file attachment
+ def attachment_added(attachment)
+ if current_journal && !attachment.new_record?
+ current_journal.journalize_attachment(attachment, :added)
+ end
+ end
+
+ # Callback on attachment deletion
+ def attachment_removed(attachment)
+ if current_journal && !attachment.new_record?
+ current_journal.journalize_attachment(attachment, :removed)
+ current_journal.save
+ end
+ end
+
+ def journal_event_title(journal)
+ "#{l(:label_news)}: #{title}"
+ end
+
+ def journal_event_type(journal)
+ 'news'
+ end
+
# Returns true if the news can be commented by user
def commentable?(user=User.current)
user.allowed_to?(:comment_news, project)
@@ -91,6 +129,11 @@ class News < ApplicationRecord
private
+ def create_journal
+ current_journal&.save
+ @current_journal = nil
+ end
+
def add_author_as_watcher
Watcher.create(:watchable => self, :user => author)
end
diff --git a/app/views/news/show.html.erb b/app/views/news/show.html.erb
index 008460fbd..f0fa7462b 100644
--- a/app/views/news/show.html.erb
+++ b/app/views/news/show.html.erb
@@ -35,6 +35,38 @@
+<% if @journals.any? %>
+
<%= Redmine::Helpers::Diff.new(detail.value, detail.old_value).to_html %>+
<%= l(:label_comment_plural) %>
<% if @news.commentable? && @comments.size >= 3 %> diff --git a/lib/redmine/preparation.rb b/lib/redmine/preparation.rb index 4138128c9..eb7fbd408 100644 --- a/lib/redmine/preparation.rb +++ b/lib/redmine/preparation.rb @@ -27,6 +27,7 @@ module Redmine # Journalized types, registered before their classes are loaded Redmine::Acts::Journalized.register 'Issue' + Redmine::Acts::Journalized.register 'News' Scm::Base.add "Subversion" Scm::Base.add "Mercurial" @@ -409,7 +410,7 @@ module Redmine Activity.map do |activity| activity.register :issues, :class_name => %w(Issue Journal) activity.register :changesets - activity.register :news + activity.register :news, :class_name => %w(News Journal) activity.register :documents, :class_name => %w(Document Attachment) activity.register :files, :class_name => 'Attachment' activity.register :wiki_edits, :class_name => 'WikiContentVersion', :default => false