Mercurial > hg > soundsoftware-site
comparison .svn/pristine/eb/ebfee87b692025d708fcb9b6e98c73314886e7fc.svn-base @ 1298:4f746d8966dd redmine_2.3_integration
Merge from redmine-2.3 branch to create new branch redmine-2.3-integration
author | Chris Cannam |
---|---|
date | Fri, 14 Jun 2013 09:28:30 +0100 |
parents | 622f24f53b42 |
children |
comparison
equal
deleted
inserted
replaced
1297:0a574315af3e | 1298:4f746d8966dd |
---|---|
1 # Redmine - project management software | |
2 # Copyright (C) 2006-2013 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 | |
18 class Journal < ActiveRecord::Base | |
19 belongs_to :journalized, :polymorphic => true | |
20 # added as a quick fix to allow eager loading of the polymorphic association | |
21 # since always associated to an issue, for now | |
22 belongs_to :issue, :foreign_key => :journalized_id | |
23 | |
24 belongs_to :user | |
25 has_many :details, :class_name => "JournalDetail", :dependent => :delete_all | |
26 attr_accessor :indice | |
27 | |
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 :description => :notes, | |
30 :author => :user, | |
31 :group => :issue, | |
32 :type => Proc.new {|o| (s = o.new_status) ? (s.is_closed? ? 'issue-closed' : 'issue-edit') : 'issue-note' }, | |
33 :url => Proc.new {|o| {:controller => 'issues', :action => 'show', :id => o.issue.id, :anchor => "change-#{o.id}"}} | |
34 | |
35 acts_as_activity_provider :type => 'issues', | |
36 :author_key => :user_id, | |
37 :find_options => {:include => [{:issue => :project}, :details, :user], | |
38 :conditions => "#{Journal.table_name}.journalized_type = 'Issue' AND" + | |
39 " (#{JournalDetail.table_name}.prop_key = 'status_id' OR #{Journal.table_name}.notes <> '')"} | |
40 | |
41 before_create :split_private_notes | |
42 | |
43 scope :visible, lambda {|*args| | |
44 user = args.shift || User.current | |
45 | |
46 includes(:issue => :project). | |
47 where(Issue.visible_condition(user, *args)). | |
48 where("(#{Journal.table_name}.private_notes = ? OR (#{Project.allowed_to_condition(user, :view_private_notes, *args)}))", false) | |
49 } | |
50 | |
51 def save(*args) | |
52 # Do not save an empty journal | |
53 (details.empty? && notes.blank?) ? false : super | |
54 end | |
55 | |
56 # Returns the new status if the journal contains a status change, otherwise nil | |
57 def new_status | |
58 c = details.detect {|detail| detail.prop_key == 'status_id'} | |
59 (c && c.value) ? IssueStatus.find_by_id(c.value.to_i) : nil | |
60 end | |
61 | |
62 def new_value_for(prop) | |
63 c = details.detect {|detail| detail.prop_key == prop} | |
64 c ? c.value : nil | |
65 end | |
66 | |
67 def editable_by?(usr) | |
68 usr && usr.logged? && (usr.allowed_to?(:edit_issue_notes, project) || (self.user == usr && usr.allowed_to?(:edit_own_issue_notes, project))) | |
69 end | |
70 | |
71 def project | |
72 journalized.respond_to?(:project) ? journalized.project : nil | |
73 end | |
74 | |
75 def attachments | |
76 journalized.respond_to?(:attachments) ? journalized.attachments : nil | |
77 end | |
78 | |
79 # Returns a string of css classes | |
80 def css_classes | |
81 s = 'journal' | |
82 s << ' has-notes' unless notes.blank? | |
83 s << ' has-details' unless details.blank? | |
84 s << ' private-notes' if private_notes? | |
85 s | |
86 end | |
87 | |
88 def notify? | |
89 @notify != false | |
90 end | |
91 | |
92 def notify=(arg) | |
93 @notify = arg | |
94 end | |
95 | |
96 def recipients | |
97 notified = journalized.notified_users | |
98 if private_notes? | |
99 notified = notified.select {|user| user.allowed_to?(:view_private_notes, journalized.project)} | |
100 end | |
101 notified.map(&:mail) | |
102 end | |
103 | |
104 def watcher_recipients | |
105 notified = journalized.notified_watchers | |
106 if private_notes? | |
107 notified = notified.select {|user| user.allowed_to?(:view_private_notes, journalized.project)} | |
108 end | |
109 notified.map(&:mail) | |
110 end | |
111 | |
112 private | |
113 | |
114 def split_private_notes | |
115 if private_notes? | |
116 if notes.present? | |
117 if details.any? | |
118 # Split the journal (notes/changes) so we don't have half-private journals | |
119 journal = Journal.new(:journalized => journalized, :user => user, :notes => nil, :private_notes => false) | |
120 journal.details = details | |
121 journal.save | |
122 self.details = [] | |
123 self.created_on = journal.created_on | |
124 end | |
125 else | |
126 # Blank notes should not be private | |
127 self.private_notes = false | |
128 end | |
129 end | |
130 true | |
131 end | |
132 end |