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