diff options
author | Go MAEDA <maeda@farend.jp> | 2023-03-26 05:35:50 +0000 |
---|---|---|
committer | Go MAEDA <maeda@farend.jp> | 2023-03-26 05:35:50 +0000 |
commit | 421dc8320fdbcfccbf5d73c377d2ff21b7e28bc7 (patch) | |
tree | 3366ec016d6b98da2b6abf35a7f173abced457d1 /app/models/mail_handler.rb | |
parent | 260ba2e04a02945f24068fe3402cf0b838b74d63 (diff) | |
download | redmine-421dc8320fdbcfccbf5d73c377d2ff21b7e28bc7.tar.gz redmine-421dc8320fdbcfccbf5d73c377d2ff21b7e28bc7.zip |
Receive e-mail replies to news and news comments (#38274).
Patch by Felix Schäfer.
git-svn-id: https://svn.redmine.org/redmine/trunk@22160 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'app/models/mail_handler.rb')
-rw-r--r-- | app/models/mail_handler.rb | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/app/models/mail_handler.rb b/app/models/mail_handler.rb index 8a4084769..67cb016d1 100644 --- a/app/models/mail_handler.rb +++ b/app/models/mail_handler.rb @@ -306,6 +306,41 @@ class MailHandler < ActionMailer::Base end end + # Receives a reply to a news entry + def receive_news_reply(news_id) + news = News.find_by_id(news_id) + if news.nil? + raise MissingContainer, "reply to nonexistant news [#{news_id}]" + end + + # Never receive emails to projects where adding news comments is not possible + project = news.project + raise NotAllowedInProject, "not possible to add news comments to project [#{project.name}]" unless project.allows_to?(:comment_news) + + unless handler_options[:no_permission_check] + unless news.commentable?(user) + raise InsufficientPermissions, "not allowed to comment on news item [#{news.id} #{news.title}]" + end + end + + comment = news.comments.new + comment.author = user + comment.comments = cleaned_up_text_body + comment.save! + comment + end + + # Receives a reply to a comment to a news entry + def receive_comment_reply(comment_id) + comment = Comment.find_by_id(comment_id) + + if comment && comment.commented_type == 'News' + receive_news_reply(comment.commented.id) + else + raise MissingContainer, "reply to nonexistant comment [#{comment_id}]" + end + end + def add_attachments(obj) if email.attachments && email.attachments.any? email.attachments.each do |attachment| |