2019-03-16 09:37:35 +00:00
|
|
|
# frozen_string_literal: true
|
2019-03-15 01:32:57 +00:00
|
|
|
|
2011-08-31 06:08:13 +00:00
|
|
|
# Redmine - project management software
|
2024-02-26 22:55:54 +00:00
|
|
|
# Copyright (C) 2006- Jean-Philippe Lang
|
2006-12-26 17:11:44 +00:00
|
|
|
#
|
|
|
|
|
# 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.
|
2011-08-31 06:08:13 +00:00
|
|
|
#
|
2006-12-26 17:11:44 +00:00
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
# GNU General Public License for more details.
|
2011-08-31 06:08:13 +00:00
|
|
|
#
|
2006-12-26 17:11:44 +00:00
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
|
# along with this program; if not, write to the Free Software
|
|
|
|
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
|
|
2024-01-23 11:52:38 +00:00
|
|
|
class Comment < ApplicationRecord
|
2012-03-06 18:48:47 +00:00
|
|
|
include Redmine::SafeAttributes
|
2006-12-10 18:35:48 +00:00
|
|
|
belongs_to :commented, :polymorphic => true, :counter_cache => true
|
2014-10-22 18:41:03 +00:00
|
|
|
belongs_to :author, :class_name => 'User'
|
2006-12-10 18:35:48 +00:00
|
|
|
|
2017-07-23 11:40:14 +00:00
|
|
|
validates_presence_of :commented, :author, :content
|
2012-03-06 18:48:47 +00:00
|
|
|
|
2018-10-10 17:13:09 +00:00
|
|
|
after_create_commit :send_notification
|
2013-07-14 14:26:27 +00:00
|
|
|
|
2012-03-06 18:48:47 +00:00
|
|
|
safe_attributes 'comments'
|
2013-07-14 14:26:27 +00:00
|
|
|
|
2017-07-23 11:40:14 +00:00
|
|
|
def comments=(arg)
|
|
|
|
|
self.content = arg
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def comments
|
|
|
|
|
content
|
|
|
|
|
end
|
|
|
|
|
|
2013-07-14 14:26:27 +00:00
|
|
|
private
|
|
|
|
|
|
|
|
|
|
def send_notification
|
2018-10-10 17:13:09 +00:00
|
|
|
event = "#{commented.class.name.underscore}_comment_added"
|
|
|
|
|
if Setting.notified_events.include?(event)
|
2023-12-20 09:23:05 +00:00
|
|
|
Mailer.public_send(:"deliver_#{event}", self)
|
2013-07-14 14:26:27 +00:00
|
|
|
end
|
|
|
|
|
end
|
2006-12-10 18:35:48 +00:00
|
|
|
end
|