summaryrefslogtreecommitdiffstats
path: root/app/models/journal.rb
diff options
context:
space:
mode:
authorJean-Philippe Lang <jp_lang@yahoo.fr>2012-10-03 21:36:19 +0000
committerJean-Philippe Lang <jp_lang@yahoo.fr>2012-10-03 21:36:19 +0000
commit0178b5a2fe07e1160348b99ac56c19ebf154ca1b (patch)
tree53f762a779c95b598815864bb674463d90ef64d6 /app/models/journal.rb
parentbb1563f23ffabcf948797e0d8806c3d5344d09a7 (diff)
downloadredmine-0178b5a2fe07e1160348b99ac56c19ebf154ca1b.tar.gz
redmine-0178b5a2fe07e1160348b99ac56c19ebf154ca1b.zip
Private issue notes (#1554).
Adds 2 new permissions for viewing/adding private comments to issues. git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@10547 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'app/models/journal.rb')
-rw-r--r--app/models/journal.rb43
1 files changed, 39 insertions, 4 deletions
diff --git a/app/models/journal.rb b/app/models/journal.rb
index a6a800e7a..895b8537d 100644
--- a/app/models/journal.rb
+++ b/app/models/journal.rb
@@ -37,10 +37,15 @@ class Journal < ActiveRecord::Base
:conditions => "#{Journal.table_name}.journalized_type = 'Issue' AND" +
" (#{JournalDetail.table_name}.prop_key = 'status_id' OR #{Journal.table_name}.notes <> '')"}
- scope :visible, lambda {|*args| {
- :include => {:issue => :project},
- :conditions => Issue.visible_condition(args.shift || User.current, *args)
- }}
+ before_create :split_private_notes
+
+ scope :visible, lambda {|*args|
+ user = args.shift || User.current
+
+ includes(:issue => :project).
+ where(Issue.visible_condition(user, *args)).
+ where("(#{Journal.table_name}.private_notes = ? OR (#{Project.allowed_to_condition(user, :view_private_notes, *args)}))", false)
+ }
def save(*args)
# Do not save an empty journal
@@ -75,6 +80,7 @@ class Journal < ActiveRecord::Base
s = 'journal'
s << ' has-notes' unless notes.blank?
s << ' has-details' unless details.blank?
+ s << ' private-notes' if private_notes?
s
end
@@ -85,4 +91,33 @@ class Journal < ActiveRecord::Base
def notify=(arg)
@notify = arg
end
+
+ def recipients
+ notified = journalized.notified_users
+ if private_notes?
+ notified = notified.select {|user| user.allowed_to?(:view_private_notes, journalized.project)}
+ end
+ notified.map(&:mail)
+ end
+
+ private
+
+ def split_private_notes
+ if private_notes?
+ if notes.present?
+ if details.any?
+ # Split the journal (notes/changes) so we don't have half-private journals
+ journal = Journal.new(:journalized => journalized, :user => user, :notes => nil, :private_notes => false)
+ journal.details = details
+ journal.save
+ self.details = []
+ self.created_on = journal.created_on
+ end
+ else
+ # Blank notes should not be private
+ self.private_notes = false
+ end
+ end
+ true
+ end
end