You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

journal.rb 3.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. # Redmine - project management software
  2. # Copyright (C) 2006-2011 Jean-Philippe Lang
  3. #
  4. # This program is free software; you can redistribute it and/or
  5. # modify it under the terms of the GNU General Public License
  6. # as published by the Free Software Foundation; either version 2
  7. # of the License, or (at your option) any later version.
  8. #
  9. # This program is distributed in the hope that it will be useful,
  10. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. # GNU General Public License for more details.
  13. #
  14. # You should have received a copy of the GNU General Public License
  15. # along with this program; if not, write to the Free Software
  16. # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  17. class Journal < ActiveRecord::Base
  18. belongs_to :journalized, :polymorphic => true
  19. # added as a quick fix to allow eager loading of the polymorphic association
  20. # since always associated to an issue, for now
  21. belongs_to :issue, :foreign_key => :journalized_id
  22. belongs_to :user
  23. has_many :details, :class_name => "JournalDetail", :dependent => :delete_all
  24. attr_accessor :indice
  25. acts_as_event :title => Proc.new {|o| status = ((s = o.new_status) ? " (#{s})" : nil); "#{o.issue.tracker} ##{o.issue.id}#{status}: #{o.issue.subject}" },
  26. :description => :notes,
  27. :author => :user,
  28. :type => Proc.new {|o| (s = o.new_status) ? (s.is_closed? ? 'issue-closed' : 'issue-edit') : 'issue-note' },
  29. :url => Proc.new {|o| {:controller => 'issues', :action => 'show', :id => o.issue.id, :anchor => "change-#{o.id}"}}
  30. acts_as_activity_provider :type => 'issues',
  31. :author_key => :user_id,
  32. :find_options => {:include => [{:issue => :project}, :details, :user],
  33. :conditions => "#{Journal.table_name}.journalized_type = 'Issue' AND" +
  34. " (#{JournalDetail.table_name}.prop_key = 'status_id' OR #{Journal.table_name}.notes <> '')"}
  35. named_scope :visible, lambda {|*args| {
  36. :include => {:issue => :project},
  37. :conditions => Issue.visible_condition(args.shift || User.current, *args)
  38. }}
  39. def save(*args)
  40. # Do not save an empty journal
  41. (details.empty? && notes.blank?) ? false : super
  42. end
  43. # Returns the new status if the journal contains a status change, otherwise nil
  44. def new_status
  45. c = details.detect {|detail| detail.prop_key == 'status_id'}
  46. (c && c.value) ? IssueStatus.find_by_id(c.value.to_i) : nil
  47. end
  48. def new_value_for(prop)
  49. c = details.detect {|detail| detail.prop_key == prop}
  50. c ? c.value : nil
  51. end
  52. def editable_by?(usr)
  53. usr && usr.logged? && (usr.allowed_to?(:edit_issue_notes, project) || (self.user == usr && usr.allowed_to?(:edit_own_issue_notes, project)))
  54. end
  55. def project
  56. journalized.respond_to?(:project) ? journalized.project : nil
  57. end
  58. def attachments
  59. journalized.respond_to?(:attachments) ? journalized.attachments : nil
  60. end
  61. # Returns a string of css classes
  62. def css_classes
  63. s = 'journal'
  64. s << ' has-notes' unless notes.blank?
  65. s << ' has-details' unless details.blank?
  66. s
  67. end
  68. def notify?
  69. @notify != false
  70. end
  71. def notify=(arg)
  72. @notify = arg
  73. end
  74. end