annotate .svn/pristine/29/298be127abf8c78d6ccda6e13729844112a36c53.svn-base @ 1327:287f201c2802 redmine-2.2-integration

Add italic
author Chris Cannam <chris.cannam@soundsoftware.ac.uk>
date Wed, 19 Jun 2013 20:56:22 +0100
parents 038ba2d95de8
children
rev   line source
Chris@1296 1 # Redmine - project management software
Chris@1296 2 # Copyright (C) 2006-2012 Jean-Philippe Lang
Chris@1296 3 #
Chris@1296 4 # This program is free software; you can redistribute it and/or
Chris@1296 5 # modify it under the terms of the GNU General Public License
Chris@1296 6 # as published by the Free Software Foundation; either version 2
Chris@1296 7 # of the License, or (at your option) any later version.
Chris@1296 8 #
Chris@1296 9 # This program is distributed in the hope that it will be useful,
Chris@1296 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
Chris@1296 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Chris@1296 12 # GNU General Public License for more details.
Chris@1296 13 #
Chris@1296 14 # You should have received a copy of the GNU General Public License
Chris@1296 15 # along with this program; if not, write to the Free Software
Chris@1296 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
Chris@1296 17
Chris@1296 18 class Journal < ActiveRecord::Base
Chris@1296 19 belongs_to :journalized, :polymorphic => true
Chris@1296 20 # added as a quick fix to allow eager loading of the polymorphic association
Chris@1296 21 # since always associated to an issue, for now
Chris@1296 22 belongs_to :issue, :foreign_key => :journalized_id
Chris@1296 23
Chris@1296 24 belongs_to :user
Chris@1296 25 has_many :details, :class_name => "JournalDetail", :dependent => :delete_all
Chris@1296 26 attr_accessor :indice
Chris@1296 27
Chris@1296 28 acts_as_event :title => Proc.new {|o| status = ((s = o.new_status) ? " (#{s})" : nil); "#{o.issue.tracker} ##{o.issue.id}#{status}: #{o.issue.subject}" },
Chris@1296 29 :description => :notes,
Chris@1296 30 :author => :user,
Chris@1296 31 :type => Proc.new {|o| (s = o.new_status) ? (s.is_closed? ? 'issue-closed' : 'issue-edit') : 'issue-note' },
Chris@1296 32 :url => Proc.new {|o| {:controller => 'issues', :action => 'show', :id => o.issue.id, :anchor => "change-#{o.id}"}}
Chris@1296 33
Chris@1296 34 acts_as_activity_provider :type => 'issues',
Chris@1296 35 :author_key => :user_id,
Chris@1296 36 :find_options => {:include => [{:issue => :project}, :details, :user],
Chris@1296 37 :conditions => "#{Journal.table_name}.journalized_type = 'Issue' AND" +
Chris@1296 38 " (#{JournalDetail.table_name}.prop_key = 'status_id' OR #{Journal.table_name}.notes <> '')"}
Chris@1296 39
Chris@1296 40 before_create :split_private_notes
Chris@1296 41
Chris@1296 42 scope :visible, lambda {|*args|
Chris@1296 43 user = args.shift || User.current
Chris@1296 44
Chris@1296 45 includes(:issue => :project).
Chris@1296 46 where(Issue.visible_condition(user, *args)).
Chris@1296 47 where("(#{Journal.table_name}.private_notes = ? OR (#{Project.allowed_to_condition(user, :view_private_notes, *args)}))", false)
Chris@1296 48 }
Chris@1296 49
Chris@1296 50 def save(*args)
Chris@1296 51 # Do not save an empty journal
Chris@1296 52 (details.empty? && notes.blank?) ? false : super
Chris@1296 53 end
Chris@1296 54
Chris@1296 55 # Returns the new status if the journal contains a status change, otherwise nil
Chris@1296 56 def new_status
Chris@1296 57 c = details.detect {|detail| detail.prop_key == 'status_id'}
Chris@1296 58 (c && c.value) ? IssueStatus.find_by_id(c.value.to_i) : nil
Chris@1296 59 end
Chris@1296 60
Chris@1296 61 def new_value_for(prop)
Chris@1296 62 c = details.detect {|detail| detail.prop_key == prop}
Chris@1296 63 c ? c.value : nil
Chris@1296 64 end
Chris@1296 65
Chris@1296 66 def editable_by?(usr)
Chris@1296 67 usr && usr.logged? && (usr.allowed_to?(:edit_issue_notes, project) || (self.user == usr && usr.allowed_to?(:edit_own_issue_notes, project)))
Chris@1296 68 end
Chris@1296 69
Chris@1296 70 def project
Chris@1296 71 journalized.respond_to?(:project) ? journalized.project : nil
Chris@1296 72 end
Chris@1296 73
Chris@1296 74 def attachments
Chris@1296 75 journalized.respond_to?(:attachments) ? journalized.attachments : nil
Chris@1296 76 end
Chris@1296 77
Chris@1296 78 # Returns a string of css classes
Chris@1296 79 def css_classes
Chris@1296 80 s = 'journal'
Chris@1296 81 s << ' has-notes' unless notes.blank?
Chris@1296 82 s << ' has-details' unless details.blank?
Chris@1296 83 s << ' private-notes' if private_notes?
Chris@1296 84 s
Chris@1296 85 end
Chris@1296 86
Chris@1296 87 def notify?
Chris@1296 88 @notify != false
Chris@1296 89 end
Chris@1296 90
Chris@1296 91 def notify=(arg)
Chris@1296 92 @notify = arg
Chris@1296 93 end
Chris@1296 94
Chris@1296 95 def recipients
Chris@1296 96 notified = journalized.notified_users
Chris@1296 97 if private_notes?
Chris@1296 98 notified = notified.select {|user| user.allowed_to?(:view_private_notes, journalized.project)}
Chris@1296 99 end
Chris@1296 100 notified.map(&:mail)
Chris@1296 101 end
Chris@1296 102
Chris@1296 103 def watcher_recipients
Chris@1296 104 notified = journalized.notified_watchers
Chris@1296 105 if private_notes?
Chris@1296 106 notified = notified.select {|user| user.allowed_to?(:view_private_notes, journalized.project)}
Chris@1296 107 end
Chris@1296 108 notified.map(&:mail)
Chris@1296 109 end
Chris@1296 110
Chris@1296 111 private
Chris@1296 112
Chris@1296 113 def split_private_notes
Chris@1296 114 if private_notes?
Chris@1296 115 if notes.present?
Chris@1296 116 if details.any?
Chris@1296 117 # Split the journal (notes/changes) so we don't have half-private journals
Chris@1296 118 journal = Journal.new(:journalized => journalized, :user => user, :notes => nil, :private_notes => false)
Chris@1296 119 journal.details = details
Chris@1296 120 journal.save
Chris@1296 121 self.details = []
Chris@1296 122 self.created_on = journal.created_on
Chris@1296 123 end
Chris@1296 124 else
Chris@1296 125 # Blank notes should not be private
Chris@1296 126 self.private_notes = false
Chris@1296 127 end
Chris@1296 128 end
Chris@1296 129 true
Chris@1296 130 end
Chris@1296 131 end