##// END OF EJS Templates
Estimated time recognizes improved time formats (#1092)....
Jean-Philippe Lang -
r1346:a6311a960370
parent child
Show More
@@ -0,0 +1,1
1 Dir[File.dirname(__FILE__) + "/core_ext/*.rb"].each { |file| require(file) }
@@ -0,0 +1,5
1 require File.dirname(__FILE__) + '/string/conversions'
2
3 class String #:nodoc:
4 include Redmine::CoreExtensions::String::Conversions
5 end
@@ -0,0 +1,40
1 # redMine - project management software
2 # Copyright (C) 2008 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 module Redmine #:nodoc:
19 module CoreExtensions #:nodoc:
20 module String #:nodoc:
21 # Custom string conversions
22 module Conversions
23 # Parses hours format and returns a float
24 def to_hours
25 s = self.dup
26 s.strip!
27 unless s =~ %r{^[\d\.,]+$}
28 # 2:30 => 2.5
29 s.gsub!(%r{^(\d+):(\d+)$}) { $1.to_i + $2.to_i / 60.0 }
30 # 2h30, 2h, 30m => 2.5, 2, 0.5
31 s.gsub!(%r{^((\d+)\s*(h|hours?))?\s*((\d+)\s*(m|min)?)?$}) { |m| ($1 || $4) ? ($2.to_i + $5.to_i / 60.0) : m[0] }
32 end
33 # 2,5 => 2.5
34 s.gsub!(',', '.')
35 s.to_f
36 end
37 end
38 end
39 end
40 end
@@ -1,246 +1,250
1 # redMine - project management software
1 # redMine - project management software
2 # Copyright (C) 2006-2007 Jean-Philippe Lang
2 # Copyright (C) 2006-2007 Jean-Philippe Lang
3 #
3 #
4 # This program is free software; you can redistribute it and/or
4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License
5 # modify it under the terms of the GNU General Public License
6 # as published by the Free Software Foundation; either version 2
6 # as published by the Free Software Foundation; either version 2
7 # of the License, or (at your option) any later version.
7 # of the License, or (at your option) any later version.
8 #
8 #
9 # This program is distributed in the hope that it will be useful,
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
12 # GNU General Public License for more details.
13 #
13 #
14 # You should have received a copy of the GNU General Public License
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
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.
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17
17
18 class Issue < ActiveRecord::Base
18 class Issue < ActiveRecord::Base
19 belongs_to :project
19 belongs_to :project
20 belongs_to :tracker
20 belongs_to :tracker
21 belongs_to :status, :class_name => 'IssueStatus', :foreign_key => 'status_id'
21 belongs_to :status, :class_name => 'IssueStatus', :foreign_key => 'status_id'
22 belongs_to :author, :class_name => 'User', :foreign_key => 'author_id'
22 belongs_to :author, :class_name => 'User', :foreign_key => 'author_id'
23 belongs_to :assigned_to, :class_name => 'User', :foreign_key => 'assigned_to_id'
23 belongs_to :assigned_to, :class_name => 'User', :foreign_key => 'assigned_to_id'
24 belongs_to :fixed_version, :class_name => 'Version', :foreign_key => 'fixed_version_id'
24 belongs_to :fixed_version, :class_name => 'Version', :foreign_key => 'fixed_version_id'
25 belongs_to :priority, :class_name => 'Enumeration', :foreign_key => 'priority_id'
25 belongs_to :priority, :class_name => 'Enumeration', :foreign_key => 'priority_id'
26 belongs_to :category, :class_name => 'IssueCategory', :foreign_key => 'category_id'
26 belongs_to :category, :class_name => 'IssueCategory', :foreign_key => 'category_id'
27
27
28 has_many :journals, :as => :journalized, :dependent => :destroy
28 has_many :journals, :as => :journalized, :dependent => :destroy
29 has_many :attachments, :as => :container, :dependent => :destroy
29 has_many :attachments, :as => :container, :dependent => :destroy
30 has_many :time_entries, :dependent => :delete_all
30 has_many :time_entries, :dependent => :delete_all
31 has_many :custom_values, :dependent => :delete_all, :as => :customized
31 has_many :custom_values, :dependent => :delete_all, :as => :customized
32 has_many :custom_fields, :through => :custom_values
32 has_many :custom_fields, :through => :custom_values
33 has_and_belongs_to_many :changesets, :order => "revision ASC"
33 has_and_belongs_to_many :changesets, :order => "revision ASC"
34
34
35 has_many :relations_from, :class_name => 'IssueRelation', :foreign_key => 'issue_from_id', :dependent => :delete_all
35 has_many :relations_from, :class_name => 'IssueRelation', :foreign_key => 'issue_from_id', :dependent => :delete_all
36 has_many :relations_to, :class_name => 'IssueRelation', :foreign_key => 'issue_to_id', :dependent => :delete_all
36 has_many :relations_to, :class_name => 'IssueRelation', :foreign_key => 'issue_to_id', :dependent => :delete_all
37
37
38 acts_as_watchable
38 acts_as_watchable
39 acts_as_searchable :columns => ['subject', 'description'], :with => {:journal => :issue}
39 acts_as_searchable :columns => ['subject', 'description'], :with => {:journal => :issue}
40 acts_as_event :title => Proc.new {|o| "#{o.tracker.name} ##{o.id}: #{o.subject}"},
40 acts_as_event :title => Proc.new {|o| "#{o.tracker.name} ##{o.id}: #{o.subject}"},
41 :url => Proc.new {|o| {:controller => 'issues', :action => 'show', :id => o.id}}
41 :url => Proc.new {|o| {:controller => 'issues', :action => 'show', :id => o.id}}
42
42
43 validates_presence_of :subject, :description, :priority, :project, :tracker, :author, :status
43 validates_presence_of :subject, :description, :priority, :project, :tracker, :author, :status
44 validates_length_of :subject, :maximum => 255
44 validates_length_of :subject, :maximum => 255
45 validates_inclusion_of :done_ratio, :in => 0..100
45 validates_inclusion_of :done_ratio, :in => 0..100
46 validates_numericality_of :estimated_hours, :allow_nil => true
46 validates_numericality_of :estimated_hours, :allow_nil => true
47 validates_associated :custom_values, :on => :update
47 validates_associated :custom_values, :on => :update
48
48
49 def after_initialize
49 def after_initialize
50 if new_record?
50 if new_record?
51 # set default values for new records only
51 # set default values for new records only
52 self.status ||= IssueStatus.default
52 self.status ||= IssueStatus.default
53 self.priority ||= Enumeration.default('IPRI')
53 self.priority ||= Enumeration.default('IPRI')
54 end
54 end
55 end
55 end
56
56
57 def copy_from(arg)
57 def copy_from(arg)
58 issue = arg.is_a?(Issue) ? arg : Issue.find(arg)
58 issue = arg.is_a?(Issue) ? arg : Issue.find(arg)
59 self.attributes = issue.attributes.dup
59 self.attributes = issue.attributes.dup
60 self.custom_values = issue.custom_values.collect {|v| v.clone}
60 self.custom_values = issue.custom_values.collect {|v| v.clone}
61 self
61 self
62 end
62 end
63
63
64 # Move an issue to a new project and tracker
64 # Move an issue to a new project and tracker
65 def move_to(new_project, new_tracker = nil)
65 def move_to(new_project, new_tracker = nil)
66 transaction do
66 transaction do
67 if new_project && project_id != new_project.id
67 if new_project && project_id != new_project.id
68 # delete issue relations
68 # delete issue relations
69 unless Setting.cross_project_issue_relations?
69 unless Setting.cross_project_issue_relations?
70 self.relations_from.clear
70 self.relations_from.clear
71 self.relations_to.clear
71 self.relations_to.clear
72 end
72 end
73 # issue is moved to another project
73 # issue is moved to another project
74 self.category = nil
74 self.category = nil
75 self.fixed_version = nil
75 self.fixed_version = nil
76 self.project = new_project
76 self.project = new_project
77 end
77 end
78 if new_tracker
78 if new_tracker
79 self.tracker = new_tracker
79 self.tracker = new_tracker
80 end
80 end
81 if save
81 if save
82 # Manually update project_id on related time entries
82 # Manually update project_id on related time entries
83 TimeEntry.update_all("project_id = #{new_project.id}", {:issue_id => id})
83 TimeEntry.update_all("project_id = #{new_project.id}", {:issue_id => id})
84 else
84 else
85 rollback_db_transaction
85 rollback_db_transaction
86 return false
86 return false
87 end
87 end
88 end
88 end
89 return true
89 return true
90 end
90 end
91
91
92 def priority_id=(pid)
92 def priority_id=(pid)
93 self.priority = nil
93 self.priority = nil
94 write_attribute(:priority_id, pid)
94 write_attribute(:priority_id, pid)
95 end
95 end
96
96
97 def estimated_hours=(h)
98 write_attribute :estimated_hours, (h.is_a?(String) ? h.to_hours : h)
99 end
100
97 def validate
101 def validate
98 if self.due_date.nil? && @attributes['due_date'] && !@attributes['due_date'].empty?
102 if self.due_date.nil? && @attributes['due_date'] && !@attributes['due_date'].empty?
99 errors.add :due_date, :activerecord_error_not_a_date
103 errors.add :due_date, :activerecord_error_not_a_date
100 end
104 end
101
105
102 if self.due_date and self.start_date and self.due_date < self.start_date
106 if self.due_date and self.start_date and self.due_date < self.start_date
103 errors.add :due_date, :activerecord_error_greater_than_start_date
107 errors.add :due_date, :activerecord_error_greater_than_start_date
104 end
108 end
105
109
106 if start_date && soonest_start && start_date < soonest_start
110 if start_date && soonest_start && start_date < soonest_start
107 errors.add :start_date, :activerecord_error_invalid
111 errors.add :start_date, :activerecord_error_invalid
108 end
112 end
109 end
113 end
110
114
111 def validate_on_create
115 def validate_on_create
112 errors.add :tracker_id, :activerecord_error_invalid unless project.trackers.include?(tracker)
116 errors.add :tracker_id, :activerecord_error_invalid unless project.trackers.include?(tracker)
113 end
117 end
114
118
115 def before_create
119 def before_create
116 # default assignment based on category
120 # default assignment based on category
117 if assigned_to.nil? && category && category.assigned_to
121 if assigned_to.nil? && category && category.assigned_to
118 self.assigned_to = category.assigned_to
122 self.assigned_to = category.assigned_to
119 end
123 end
120 end
124 end
121
125
122 def before_save
126 def before_save
123 if @current_journal
127 if @current_journal
124 # attributes changes
128 # attributes changes
125 (Issue.column_names - %w(id description)).each {|c|
129 (Issue.column_names - %w(id description)).each {|c|
126 @current_journal.details << JournalDetail.new(:property => 'attr',
130 @current_journal.details << JournalDetail.new(:property => 'attr',
127 :prop_key => c,
131 :prop_key => c,
128 :old_value => @issue_before_change.send(c),
132 :old_value => @issue_before_change.send(c),
129 :value => send(c)) unless send(c)==@issue_before_change.send(c)
133 :value => send(c)) unless send(c)==@issue_before_change.send(c)
130 }
134 }
131 # custom fields changes
135 # custom fields changes
132 custom_values.each {|c|
136 custom_values.each {|c|
133 next if (@custom_values_before_change[c.custom_field_id]==c.value ||
137 next if (@custom_values_before_change[c.custom_field_id]==c.value ||
134 (@custom_values_before_change[c.custom_field_id].blank? && c.value.blank?))
138 (@custom_values_before_change[c.custom_field_id].blank? && c.value.blank?))
135 @current_journal.details << JournalDetail.new(:property => 'cf',
139 @current_journal.details << JournalDetail.new(:property => 'cf',
136 :prop_key => c.custom_field_id,
140 :prop_key => c.custom_field_id,
137 :old_value => @custom_values_before_change[c.custom_field_id],
141 :old_value => @custom_values_before_change[c.custom_field_id],
138 :value => c.value)
142 :value => c.value)
139 }
143 }
140 @current_journal.save
144 @current_journal.save
141 end
145 end
142 # Save the issue even if the journal is not saved (because empty)
146 # Save the issue even if the journal is not saved (because empty)
143 true
147 true
144 end
148 end
145
149
146 def after_save
150 def after_save
147 # Reload is needed in order to get the right status
151 # Reload is needed in order to get the right status
148 reload
152 reload
149
153
150 # Update start/due dates of following issues
154 # Update start/due dates of following issues
151 relations_from.each(&:set_issue_to_dates)
155 relations_from.each(&:set_issue_to_dates)
152
156
153 # Close duplicates if the issue was closed
157 # Close duplicates if the issue was closed
154 if @issue_before_change && !@issue_before_change.closed? && self.closed?
158 if @issue_before_change && !@issue_before_change.closed? && self.closed?
155 duplicates.each do |duplicate|
159 duplicates.each do |duplicate|
156 # Reload is need in case the duplicate was updated by a previous duplicate
160 # Reload is need in case the duplicate was updated by a previous duplicate
157 duplicate.reload
161 duplicate.reload
158 # Don't re-close it if it's already closed
162 # Don't re-close it if it's already closed
159 next if duplicate.closed?
163 next if duplicate.closed?
160 # Same user and notes
164 # Same user and notes
161 duplicate.init_journal(@current_journal.user, @current_journal.notes)
165 duplicate.init_journal(@current_journal.user, @current_journal.notes)
162 duplicate.update_attribute :status, self.status
166 duplicate.update_attribute :status, self.status
163 end
167 end
164 end
168 end
165 end
169 end
166
170
167 def custom_value_for(custom_field)
171 def custom_value_for(custom_field)
168 self.custom_values.each {|v| return v if v.custom_field_id == custom_field.id }
172 self.custom_values.each {|v| return v if v.custom_field_id == custom_field.id }
169 return nil
173 return nil
170 end
174 end
171
175
172 def init_journal(user, notes = "")
176 def init_journal(user, notes = "")
173 @current_journal ||= Journal.new(:journalized => self, :user => user, :notes => notes)
177 @current_journal ||= Journal.new(:journalized => self, :user => user, :notes => notes)
174 @issue_before_change = self.clone
178 @issue_before_change = self.clone
175 @issue_before_change.status = self.status
179 @issue_before_change.status = self.status
176 @custom_values_before_change = {}
180 @custom_values_before_change = {}
177 self.custom_values.each {|c| @custom_values_before_change.store c.custom_field_id, c.value }
181 self.custom_values.each {|c| @custom_values_before_change.store c.custom_field_id, c.value }
178 @current_journal
182 @current_journal
179 end
183 end
180
184
181 # Return true if the issue is closed, otherwise false
185 # Return true if the issue is closed, otherwise false
182 def closed?
186 def closed?
183 self.status.is_closed?
187 self.status.is_closed?
184 end
188 end
185
189
186 # Users the issue can be assigned to
190 # Users the issue can be assigned to
187 def assignable_users
191 def assignable_users
188 project.assignable_users
192 project.assignable_users
189 end
193 end
190
194
191 # Returns an array of status that user is able to apply
195 # Returns an array of status that user is able to apply
192 def new_statuses_allowed_to(user)
196 def new_statuses_allowed_to(user)
193 statuses = status.find_new_statuses_allowed_to(user.role_for_project(project), tracker)
197 statuses = status.find_new_statuses_allowed_to(user.role_for_project(project), tracker)
194 statuses << status unless statuses.empty?
198 statuses << status unless statuses.empty?
195 statuses.uniq.sort
199 statuses.uniq.sort
196 end
200 end
197
201
198 # Returns the mail adresses of users that should be notified for the issue
202 # Returns the mail adresses of users that should be notified for the issue
199 def recipients
203 def recipients
200 recipients = project.recipients
204 recipients = project.recipients
201 # Author and assignee are always notified unless they have been locked
205 # Author and assignee are always notified unless they have been locked
202 recipients << author.mail if author && author.active?
206 recipients << author.mail if author && author.active?
203 recipients << assigned_to.mail if assigned_to && assigned_to.active?
207 recipients << assigned_to.mail if assigned_to && assigned_to.active?
204 recipients.compact.uniq
208 recipients.compact.uniq
205 end
209 end
206
210
207 def spent_hours
211 def spent_hours
208 @spent_hours ||= time_entries.sum(:hours) || 0
212 @spent_hours ||= time_entries.sum(:hours) || 0
209 end
213 end
210
214
211 def relations
215 def relations
212 (relations_from + relations_to).sort
216 (relations_from + relations_to).sort
213 end
217 end
214
218
215 def all_dependent_issues
219 def all_dependent_issues
216 dependencies = []
220 dependencies = []
217 relations_from.each do |relation|
221 relations_from.each do |relation|
218 dependencies << relation.issue_to
222 dependencies << relation.issue_to
219 dependencies += relation.issue_to.all_dependent_issues
223 dependencies += relation.issue_to.all_dependent_issues
220 end
224 end
221 dependencies
225 dependencies
222 end
226 end
223
227
224 # Returns an array of the duplicate issues
228 # Returns an array of the duplicate issues
225 def duplicates
229 def duplicates
226 relations.select {|r| r.relation_type == IssueRelation::TYPE_DUPLICATES}.collect {|r| r.other_issue(self)}
230 relations.select {|r| r.relation_type == IssueRelation::TYPE_DUPLICATES}.collect {|r| r.other_issue(self)}
227 end
231 end
228
232
229 def duration
233 def duration
230 (start_date && due_date) ? due_date - start_date : 0
234 (start_date && due_date) ? due_date - start_date : 0
231 end
235 end
232
236
233 def soonest_start
237 def soonest_start
234 @soonest_start ||= relations_to.collect{|relation| relation.successor_soonest_start}.compact.min
238 @soonest_start ||= relations_to.collect{|relation| relation.successor_soonest_start}.compact.min
235 end
239 end
236
240
237 def self.visible_by(usr)
241 def self.visible_by(usr)
238 with_scope(:find => { :conditions => Project.visible_by(usr) }) do
242 with_scope(:find => { :conditions => Project.visible_by(usr) }) do
239 yield
243 yield
240 end
244 end
241 end
245 end
242
246
243 def to_s
247 def to_s
244 "#{tracker} ##{id}: #{subject}"
248 "#{tracker} ##{id}: #{subject}"
245 end
249 end
246 end
250 end
@@ -1,77 +1,65
1 # redMine - project management software
1 # redMine - project management software
2 # Copyright (C) 2006-2008 Jean-Philippe Lang
2 # Copyright (C) 2006-2008 Jean-Philippe Lang
3 #
3 #
4 # This program is free software; you can redistribute it and/or
4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License
5 # modify it under the terms of the GNU General Public License
6 # as published by the Free Software Foundation; either version 2
6 # as published by the Free Software Foundation; either version 2
7 # of the License, or (at your option) any later version.
7 # of the License, or (at your option) any later version.
8 #
8 #
9 # This program is distributed in the hope that it will be useful,
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
12 # GNU General Public License for more details.
13 #
13 #
14 # You should have received a copy of the GNU General Public License
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
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.
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17
17
18 class TimeEntry < ActiveRecord::Base
18 class TimeEntry < ActiveRecord::Base
19 # could have used polymorphic association
19 # could have used polymorphic association
20 # project association here allows easy loading of time entries at project level with one database trip
20 # project association here allows easy loading of time entries at project level with one database trip
21 belongs_to :project
21 belongs_to :project
22 belongs_to :issue
22 belongs_to :issue
23 belongs_to :user
23 belongs_to :user
24 belongs_to :activity, :class_name => 'Enumeration', :foreign_key => :activity_id
24 belongs_to :activity, :class_name => 'Enumeration', :foreign_key => :activity_id
25
25
26 attr_protected :project_id, :user_id, :tyear, :tmonth, :tweek
26 attr_protected :project_id, :user_id, :tyear, :tmonth, :tweek
27
27
28 validates_presence_of :user_id, :activity_id, :project_id, :hours, :spent_on
28 validates_presence_of :user_id, :activity_id, :project_id, :hours, :spent_on
29 validates_numericality_of :hours, :allow_nil => true
29 validates_numericality_of :hours, :allow_nil => true
30 validates_length_of :comments, :maximum => 255
30 validates_length_of :comments, :maximum => 255
31
31
32 def before_validation
32 def before_validation
33 self.project = issue.project if issue && project.nil?
33 self.project = issue.project if issue && project.nil?
34 end
34 end
35
35
36 def validate
36 def validate
37 errors.add :hours, :activerecord_error_invalid if hours && (hours < 0 || hours >= 1000)
37 errors.add :hours, :activerecord_error_invalid if hours && (hours < 0 || hours >= 1000)
38 errors.add :project_id, :activerecord_error_invalid if project.nil?
38 errors.add :project_id, :activerecord_error_invalid if project.nil?
39 errors.add :issue_id, :activerecord_error_invalid if (issue_id && !issue) || (issue && project!=issue.project)
39 errors.add :issue_id, :activerecord_error_invalid if (issue_id && !issue) || (issue && project!=issue.project)
40 end
40 end
41
41
42 def hours=(h)
42 def hours=(h)
43 s = h.dup
43 write_attribute :hours, (h.is_a?(String) ? h.to_hours : h)
44 if s.is_a?(String)
45 s.strip!
46 unless s =~ %r{^[\d\.,]+$}
47 # 2:30 => 2.5
48 s.gsub!(%r{^(\d+):(\d+)$}) { $1.to_i + $2.to_i / 60.0 }
49 # 2h30, 2h, 30m
50 s.gsub!(%r{^((\d+)\s*(h|hours?))?\s*((\d+)\s*(m|min)?)?$}) { |m| ($1 || $4) ? ($2.to_i + $5.to_i / 60.0) : m[0] }
51 end
52 # 2,5 => 2.5
53 s.gsub!(',', '.')
54 end
55 write_attribute :hours, s
56 end
44 end
57
45
58 # tyear, tmonth, tweek assigned where setting spent_on attributes
46 # tyear, tmonth, tweek assigned where setting spent_on attributes
59 # these attributes make time aggregations easier
47 # these attributes make time aggregations easier
60 def spent_on=(date)
48 def spent_on=(date)
61 super
49 super
62 self.tyear = spent_on ? spent_on.year : nil
50 self.tyear = spent_on ? spent_on.year : nil
63 self.tmonth = spent_on ? spent_on.month : nil
51 self.tmonth = spent_on ? spent_on.month : nil
64 self.tweek = spent_on ? Date.civil(spent_on.year, spent_on.month, spent_on.day).cweek : nil
52 self.tweek = spent_on ? Date.civil(spent_on.year, spent_on.month, spent_on.day).cweek : nil
65 end
53 end
66
54
67 # Returns true if the time entry can be edited by usr, otherwise false
55 # Returns true if the time entry can be edited by usr, otherwise false
68 def editable_by?(usr)
56 def editable_by?(usr)
69 (usr == user && usr.allowed_to?(:edit_own_time_entries, project)) || usr.allowed_to?(:edit_time_entries, project)
57 (usr == user && usr.allowed_to?(:edit_own_time_entries, project)) || usr.allowed_to?(:edit_time_entries, project)
70 end
58 end
71
59
72 def self.visible_by(usr)
60 def self.visible_by(usr)
73 with_scope(:find => { :conditions => Project.allowed_to_condition(usr, :view_time_entries) }) do
61 with_scope(:find => { :conditions => Project.allowed_to_condition(usr, :view_time_entries) }) do
74 yield
62 yield
75 end
63 end
76 end
64 end
77 end
65 end
@@ -1,132 +1,133
1 require 'redmine/access_control'
1 require 'redmine/access_control'
2 require 'redmine/menu_manager'
2 require 'redmine/menu_manager'
3 require 'redmine/mime_type'
3 require 'redmine/mime_type'
4 require 'redmine/core_ext'
4 require 'redmine/themes'
5 require 'redmine/themes'
5 require 'redmine/plugin'
6 require 'redmine/plugin'
6
7
7 begin
8 begin
8 require_library_or_gem 'RMagick' unless Object.const_defined?(:Magick)
9 require_library_or_gem 'RMagick' unless Object.const_defined?(:Magick)
9 rescue LoadError
10 rescue LoadError
10 # RMagick is not available
11 # RMagick is not available
11 end
12 end
12
13
13 REDMINE_SUPPORTED_SCM = %w( Subversion Darcs Mercurial Cvs Bazaar Git )
14 REDMINE_SUPPORTED_SCM = %w( Subversion Darcs Mercurial Cvs Bazaar Git )
14
15
15 # Permissions
16 # Permissions
16 Redmine::AccessControl.map do |map|
17 Redmine::AccessControl.map do |map|
17 map.permission :view_project, {:projects => [:show, :activity]}, :public => true
18 map.permission :view_project, {:projects => [:show, :activity]}, :public => true
18 map.permission :search_project, {:search => :index}, :public => true
19 map.permission :search_project, {:search => :index}, :public => true
19 map.permission :edit_project, {:projects => [:settings, :edit]}, :require => :member
20 map.permission :edit_project, {:projects => [:settings, :edit]}, :require => :member
20 map.permission :select_project_modules, {:projects => :modules}, :require => :member
21 map.permission :select_project_modules, {:projects => :modules}, :require => :member
21 map.permission :manage_members, {:projects => :settings, :members => [:new, :edit, :destroy]}, :require => :member
22 map.permission :manage_members, {:projects => :settings, :members => [:new, :edit, :destroy]}, :require => :member
22 map.permission :manage_versions, {:projects => [:settings, :add_version], :versions => [:edit, :destroy]}, :require => :member
23 map.permission :manage_versions, {:projects => [:settings, :add_version], :versions => [:edit, :destroy]}, :require => :member
23
24
24 map.project_module :issue_tracking do |map|
25 map.project_module :issue_tracking do |map|
25 # Issue categories
26 # Issue categories
26 map.permission :manage_categories, {:projects => [:settings, :add_issue_category], :issue_categories => [:edit, :destroy]}, :require => :member
27 map.permission :manage_categories, {:projects => [:settings, :add_issue_category], :issue_categories => [:edit, :destroy]}, :require => :member
27 # Issues
28 # Issues
28 map.permission :view_issues, {:projects => [:changelog, :roadmap],
29 map.permission :view_issues, {:projects => [:changelog, :roadmap],
29 :issues => [:index, :changes, :show, :context_menu],
30 :issues => [:index, :changes, :show, :context_menu],
30 :versions => [:show, :status_by],
31 :versions => [:show, :status_by],
31 :queries => :index,
32 :queries => :index,
32 :reports => :issue_report}, :public => true
33 :reports => :issue_report}, :public => true
33 map.permission :add_issues, {:issues => :new}
34 map.permission :add_issues, {:issues => :new}
34 map.permission :edit_issues, {:issues => [:edit, :bulk_edit, :destroy_attachment]}
35 map.permission :edit_issues, {:issues => [:edit, :bulk_edit, :destroy_attachment]}
35 map.permission :manage_issue_relations, {:issue_relations => [:new, :destroy]}
36 map.permission :manage_issue_relations, {:issue_relations => [:new, :destroy]}
36 map.permission :add_issue_notes, {:issues => :edit}
37 map.permission :add_issue_notes, {:issues => :edit}
37 map.permission :edit_issue_notes, {:journals => :edit}, :require => :loggedin
38 map.permission :edit_issue_notes, {:journals => :edit}, :require => :loggedin
38 map.permission :edit_own_issue_notes, {:journals => :edit}, :require => :loggedin
39 map.permission :edit_own_issue_notes, {:journals => :edit}, :require => :loggedin
39 map.permission :move_issues, {:issues => :move}, :require => :loggedin
40 map.permission :move_issues, {:issues => :move}, :require => :loggedin
40 map.permission :delete_issues, {:issues => :destroy}, :require => :member
41 map.permission :delete_issues, {:issues => :destroy}, :require => :member
41 # Queries
42 # Queries
42 map.permission :manage_public_queries, {:queries => [:new, :edit, :destroy]}, :require => :member
43 map.permission :manage_public_queries, {:queries => [:new, :edit, :destroy]}, :require => :member
43 map.permission :save_queries, {:queries => [:new, :edit, :destroy]}, :require => :loggedin
44 map.permission :save_queries, {:queries => [:new, :edit, :destroy]}, :require => :loggedin
44 # Gantt & calendar
45 # Gantt & calendar
45 map.permission :view_gantt, :projects => :gantt
46 map.permission :view_gantt, :projects => :gantt
46 map.permission :view_calendar, :projects => :calendar
47 map.permission :view_calendar, :projects => :calendar
47 end
48 end
48
49
49 map.project_module :time_tracking do |map|
50 map.project_module :time_tracking do |map|
50 map.permission :log_time, {:timelog => :edit}, :require => :loggedin
51 map.permission :log_time, {:timelog => :edit}, :require => :loggedin
51 map.permission :view_time_entries, :timelog => [:details, :report]
52 map.permission :view_time_entries, :timelog => [:details, :report]
52 map.permission :edit_time_entries, {:timelog => [:edit, :destroy]}, :require => :member
53 map.permission :edit_time_entries, {:timelog => [:edit, :destroy]}, :require => :member
53 map.permission :edit_own_time_entries, {:timelog => [:edit, :destroy]}, :require => :loggedin
54 map.permission :edit_own_time_entries, {:timelog => [:edit, :destroy]}, :require => :loggedin
54 end
55 end
55
56
56 map.project_module :news do |map|
57 map.project_module :news do |map|
57 map.permission :manage_news, {:news => [:new, :edit, :destroy, :destroy_comment]}, :require => :member
58 map.permission :manage_news, {:news => [:new, :edit, :destroy, :destroy_comment]}, :require => :member
58 map.permission :view_news, {:news => [:index, :show]}, :public => true
59 map.permission :view_news, {:news => [:index, :show]}, :public => true
59 map.permission :comment_news, {:news => :add_comment}
60 map.permission :comment_news, {:news => :add_comment}
60 end
61 end
61
62
62 map.project_module :documents do |map|
63 map.project_module :documents do |map|
63 map.permission :manage_documents, {:documents => [:new, :edit, :destroy, :add_attachment, :destroy_attachment]}, :require => :loggedin
64 map.permission :manage_documents, {:documents => [:new, :edit, :destroy, :add_attachment, :destroy_attachment]}, :require => :loggedin
64 map.permission :view_documents, :documents => [:index, :show, :download]
65 map.permission :view_documents, :documents => [:index, :show, :download]
65 end
66 end
66
67
67 map.project_module :files do |map|
68 map.project_module :files do |map|
68 map.permission :manage_files, {:projects => :add_file, :versions => :destroy_file}, :require => :loggedin
69 map.permission :manage_files, {:projects => :add_file, :versions => :destroy_file}, :require => :loggedin
69 map.permission :view_files, :projects => :list_files, :versions => :download
70 map.permission :view_files, :projects => :list_files, :versions => :download
70 end
71 end
71
72
72 map.project_module :wiki do |map|
73 map.project_module :wiki do |map|
73 map.permission :manage_wiki, {:wikis => [:edit, :destroy]}, :require => :member
74 map.permission :manage_wiki, {:wikis => [:edit, :destroy]}, :require => :member
74 map.permission :rename_wiki_pages, {:wiki => :rename}, :require => :member
75 map.permission :rename_wiki_pages, {:wiki => :rename}, :require => :member
75 map.permission :delete_wiki_pages, {:wiki => :destroy}, :require => :member
76 map.permission :delete_wiki_pages, {:wiki => :destroy}, :require => :member
76 map.permission :view_wiki_pages, :wiki => [:index, :history, :diff, :annotate, :special]
77 map.permission :view_wiki_pages, :wiki => [:index, :history, :diff, :annotate, :special]
77 map.permission :edit_wiki_pages, :wiki => [:edit, :preview, :add_attachment, :destroy_attachment]
78 map.permission :edit_wiki_pages, :wiki => [:edit, :preview, :add_attachment, :destroy_attachment]
78 end
79 end
79
80
80 map.project_module :repository do |map|
81 map.project_module :repository do |map|
81 map.permission :manage_repository, {:repositories => [:edit, :destroy]}, :require => :member
82 map.permission :manage_repository, {:repositories => [:edit, :destroy]}, :require => :member
82 map.permission :browse_repository, :repositories => [:show, :browse, :entry, :annotate, :changes, :diff, :stats, :graph]
83 map.permission :browse_repository, :repositories => [:show, :browse, :entry, :annotate, :changes, :diff, :stats, :graph]
83 map.permission :view_changesets, :repositories => [:show, :revisions, :revision]
84 map.permission :view_changesets, :repositories => [:show, :revisions, :revision]
84 end
85 end
85
86
86 map.project_module :boards do |map|
87 map.project_module :boards do |map|
87 map.permission :manage_boards, {:boards => [:new, :edit, :destroy]}, :require => :member
88 map.permission :manage_boards, {:boards => [:new, :edit, :destroy]}, :require => :member
88 map.permission :view_messages, {:boards => [:index, :show], :messages => [:show]}, :public => true
89 map.permission :view_messages, {:boards => [:index, :show], :messages => [:show]}, :public => true
89 map.permission :add_messages, {:messages => [:new, :reply]}
90 map.permission :add_messages, {:messages => [:new, :reply]}
90 map.permission :edit_messages, {:messages => :edit}, :require => :member
91 map.permission :edit_messages, {:messages => :edit}, :require => :member
91 map.permission :delete_messages, {:messages => :destroy}, :require => :member
92 map.permission :delete_messages, {:messages => :destroy}, :require => :member
92 end
93 end
93 end
94 end
94
95
95 Redmine::MenuManager.map :top_menu do |menu|
96 Redmine::MenuManager.map :top_menu do |menu|
96 menu.push :home, :home_url, :html => { :class => 'home' }
97 menu.push :home, :home_url, :html => { :class => 'home' }
97 menu.push :my_page, { :controller => 'my', :action => 'page' }, :html => { :class => 'mypage' }, :if => Proc.new { User.current.logged? }
98 menu.push :my_page, { :controller => 'my', :action => 'page' }, :html => { :class => 'mypage' }, :if => Proc.new { User.current.logged? }
98 menu.push :projects, { :controller => 'projects', :action => 'index' }, :caption => :label_project_plural, :html => { :class => 'projects' }
99 menu.push :projects, { :controller => 'projects', :action => 'index' }, :caption => :label_project_plural, :html => { :class => 'projects' }
99 menu.push :administration, { :controller => 'admin', :action => 'index' }, :html => { :class => 'admin' }, :if => Proc.new { User.current.admin? }
100 menu.push :administration, { :controller => 'admin', :action => 'index' }, :html => { :class => 'admin' }, :if => Proc.new { User.current.admin? }
100 menu.push :help, Redmine::Info.help_url, :html => { :class => 'help' }
101 menu.push :help, Redmine::Info.help_url, :html => { :class => 'help' }
101 end
102 end
102
103
103 Redmine::MenuManager.map :account_menu do |menu|
104 Redmine::MenuManager.map :account_menu do |menu|
104 menu.push :login, :signin_url, :html => { :class => 'login' }, :if => Proc.new { !User.current.logged? }
105 menu.push :login, :signin_url, :html => { :class => 'login' }, :if => Proc.new { !User.current.logged? }
105 menu.push :register, { :controller => 'account', :action => 'register' }, :html => { :class => 'register' }, :if => Proc.new { !User.current.logged? && Setting.self_registration? }
106 menu.push :register, { :controller => 'account', :action => 'register' }, :html => { :class => 'register' }, :if => Proc.new { !User.current.logged? && Setting.self_registration? }
106 menu.push :my_account, { :controller => 'my', :action => 'account' }, :html => { :class => 'myaccount' }, :if => Proc.new { User.current.logged? }
107 menu.push :my_account, { :controller => 'my', :action => 'account' }, :html => { :class => 'myaccount' }, :if => Proc.new { User.current.logged? }
107 menu.push :logout, :signout_url, :html => { :class => 'logout' }, :if => Proc.new { User.current.logged? }
108 menu.push :logout, :signout_url, :html => { :class => 'logout' }, :if => Proc.new { User.current.logged? }
108 end
109 end
109
110
110 Redmine::MenuManager.map :application_menu do |menu|
111 Redmine::MenuManager.map :application_menu do |menu|
111 # Empty
112 # Empty
112 end
113 end
113
114
114 Redmine::MenuManager.map :project_menu do |menu|
115 Redmine::MenuManager.map :project_menu do |menu|
115 menu.push :overview, { :controller => 'projects', :action => 'show' }
116 menu.push :overview, { :controller => 'projects', :action => 'show' }
116 menu.push :activity, { :controller => 'projects', :action => 'activity' }
117 menu.push :activity, { :controller => 'projects', :action => 'activity' }
117 menu.push :roadmap, { :controller => 'projects', :action => 'roadmap' },
118 menu.push :roadmap, { :controller => 'projects', :action => 'roadmap' },
118 :if => Proc.new { |p| p.versions.any? }
119 :if => Proc.new { |p| p.versions.any? }
119 menu.push :issues, { :controller => 'issues', :action => 'index' }, :param => :project_id, :caption => :label_issue_plural
120 menu.push :issues, { :controller => 'issues', :action => 'index' }, :param => :project_id, :caption => :label_issue_plural
120 menu.push :new_issue, { :controller => 'issues', :action => 'new' }, :param => :project_id, :caption => :label_issue_new,
121 menu.push :new_issue, { :controller => 'issues', :action => 'new' }, :param => :project_id, :caption => :label_issue_new,
121 :html => { :accesskey => Redmine::AccessKeys.key_for(:new_issue) }
122 :html => { :accesskey => Redmine::AccessKeys.key_for(:new_issue) }
122 menu.push :news, { :controller => 'news', :action => 'index' }, :param => :project_id, :caption => :label_news_plural
123 menu.push :news, { :controller => 'news', :action => 'index' }, :param => :project_id, :caption => :label_news_plural
123 menu.push :documents, { :controller => 'documents', :action => 'index' }, :param => :project_id, :caption => :label_document_plural
124 menu.push :documents, { :controller => 'documents', :action => 'index' }, :param => :project_id, :caption => :label_document_plural
124 menu.push :wiki, { :controller => 'wiki', :action => 'index', :page => nil },
125 menu.push :wiki, { :controller => 'wiki', :action => 'index', :page => nil },
125 :if => Proc.new { |p| p.wiki && !p.wiki.new_record? }
126 :if => Proc.new { |p| p.wiki && !p.wiki.new_record? }
126 menu.push :boards, { :controller => 'boards', :action => 'index', :id => nil }, :param => :project_id,
127 menu.push :boards, { :controller => 'boards', :action => 'index', :id => nil }, :param => :project_id,
127 :if => Proc.new { |p| p.boards.any? }, :caption => :label_board_plural
128 :if => Proc.new { |p| p.boards.any? }, :caption => :label_board_plural
128 menu.push :files, { :controller => 'projects', :action => 'list_files' }, :caption => :label_attachment_plural
129 menu.push :files, { :controller => 'projects', :action => 'list_files' }, :caption => :label_attachment_plural
129 menu.push :repository, { :controller => 'repositories', :action => 'show' },
130 menu.push :repository, { :controller => 'repositories', :action => 'show' },
130 :if => Proc.new { |p| p.repository && !p.repository.new_record? }
131 :if => Proc.new { |p| p.repository && !p.repository.new_record? }
131 menu.push :settings, { :controller => 'projects', :action => 'settings' }
132 menu.push :settings, { :controller => 'projects', :action => 'settings' }
132 end
133 end
@@ -1,81 +1,88
1 # redMine - project management software
1 # redMine - project management software
2 # Copyright (C) 2006-2007 Jean-Philippe Lang
2 # Copyright (C) 2006-2007 Jean-Philippe Lang
3 #
3 #
4 # This program is free software; you can redistribute it and/or
4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License
5 # modify it under the terms of the GNU General Public License
6 # as published by the Free Software Foundation; either version 2
6 # as published by the Free Software Foundation; either version 2
7 # of the License, or (at your option) any later version.
7 # of the License, or (at your option) any later version.
8 #
8 #
9 # This program is distributed in the hope that it will be useful,
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
12 # GNU General Public License for more details.
13 #
13 #
14 # You should have received a copy of the GNU General Public License
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
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.
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17
17
18 require File.dirname(__FILE__) + '/../test_helper'
18 require File.dirname(__FILE__) + '/../test_helper'
19
19
20 class IssueTest < Test::Unit::TestCase
20 class IssueTest < Test::Unit::TestCase
21 fixtures :projects, :users, :members, :trackers, :projects_trackers, :issue_statuses, :issue_categories, :enumerations, :issues, :custom_fields, :custom_values, :time_entries
21 fixtures :projects, :users, :members, :trackers, :projects_trackers, :issue_statuses, :issue_categories, :enumerations, :issues, :custom_fields, :custom_values, :time_entries
22
22
23 def test_create
24 issue = Issue.new(:project_id => 1, :tracker_id => 1, :author_id => 3, :status_id => 1, :priority => Enumeration.get_values('IPRI').first, :subject => 'test_create', :description => 'IssueTest#test_create', :estimated_hours => '1:30')
25 assert issue.save
26 issue.reload
27 assert_equal 1.5, issue.estimated_hours
28 end
29
23 def test_category_based_assignment
30 def test_category_based_assignment
24 issue = Issue.create(:project_id => 1, :tracker_id => 1, :author_id => 3, :status_id => 1, :priority => Enumeration.get_values('IPRI').first, :subject => 'Assignment test', :description => 'Assignment test', :category_id => 1)
31 issue = Issue.create(:project_id => 1, :tracker_id => 1, :author_id => 3, :status_id => 1, :priority => Enumeration.get_values('IPRI').first, :subject => 'Assignment test', :description => 'Assignment test', :category_id => 1)
25 assert_equal IssueCategory.find(1).assigned_to, issue.assigned_to
32 assert_equal IssueCategory.find(1).assigned_to, issue.assigned_to
26 end
33 end
27
34
28 def test_copy
35 def test_copy
29 issue = Issue.new.copy_from(1)
36 issue = Issue.new.copy_from(1)
30 assert issue.save
37 assert issue.save
31 issue.reload
38 issue.reload
32 orig = Issue.find(1)
39 orig = Issue.find(1)
33 assert_equal orig.subject, issue.subject
40 assert_equal orig.subject, issue.subject
34 assert_equal orig.tracker, issue.tracker
41 assert_equal orig.tracker, issue.tracker
35 assert_equal orig.custom_values.first.value, issue.custom_values.first.value
42 assert_equal orig.custom_values.first.value, issue.custom_values.first.value
36 end
43 end
37
44
38 def test_close_duplicates
45 def test_close_duplicates
39 # Create 3 issues
46 # Create 3 issues
40 issue1 = Issue.new(:project_id => 1, :tracker_id => 1, :author_id => 1, :status_id => 1, :priority => Enumeration.get_values('IPRI').first, :subject => 'Duplicates test', :description => 'Duplicates test')
47 issue1 = Issue.new(:project_id => 1, :tracker_id => 1, :author_id => 1, :status_id => 1, :priority => Enumeration.get_values('IPRI').first, :subject => 'Duplicates test', :description => 'Duplicates test')
41 assert issue1.save
48 assert issue1.save
42 issue2 = issue1.clone
49 issue2 = issue1.clone
43 assert issue2.save
50 assert issue2.save
44 issue3 = issue1.clone
51 issue3 = issue1.clone
45 assert issue3.save
52 assert issue3.save
46
53
47 # 2 is a dupe of 1
54 # 2 is a dupe of 1
48 IssueRelation.create(:issue_from => issue1, :issue_to => issue2, :relation_type => IssueRelation::TYPE_DUPLICATES)
55 IssueRelation.create(:issue_from => issue1, :issue_to => issue2, :relation_type => IssueRelation::TYPE_DUPLICATES)
49 # And 3 is a dupe of 2
56 # And 3 is a dupe of 2
50 IssueRelation.create(:issue_from => issue2, :issue_to => issue3, :relation_type => IssueRelation::TYPE_DUPLICATES)
57 IssueRelation.create(:issue_from => issue2, :issue_to => issue3, :relation_type => IssueRelation::TYPE_DUPLICATES)
51 # And 3 is a dupe of 1 (circular duplicates)
58 # And 3 is a dupe of 1 (circular duplicates)
52 IssueRelation.create(:issue_from => issue1, :issue_to => issue3, :relation_type => IssueRelation::TYPE_DUPLICATES)
59 IssueRelation.create(:issue_from => issue1, :issue_to => issue3, :relation_type => IssueRelation::TYPE_DUPLICATES)
53
60
54 assert issue1.reload.duplicates.include?(issue2)
61 assert issue1.reload.duplicates.include?(issue2)
55
62
56 # Closing issue 1
63 # Closing issue 1
57 issue1.init_journal(User.find(:first), "Closing issue1")
64 issue1.init_journal(User.find(:first), "Closing issue1")
58 issue1.status = IssueStatus.find :first, :conditions => {:is_closed => true}
65 issue1.status = IssueStatus.find :first, :conditions => {:is_closed => true}
59 assert issue1.save
66 assert issue1.save
60 # 2 and 3 should be also closed
67 # 2 and 3 should be also closed
61 assert issue2.reload.closed?
68 assert issue2.reload.closed?
62 assert issue3.reload.closed?
69 assert issue3.reload.closed?
63 end
70 end
64
71
65 def test_move_to_another_project
72 def test_move_to_another_project
66 issue = Issue.find(1)
73 issue = Issue.find(1)
67 assert issue.move_to(Project.find(2))
74 assert issue.move_to(Project.find(2))
68 issue.reload
75 issue.reload
69 assert_equal 2, issue.project_id
76 assert_equal 2, issue.project_id
70 # Category removed
77 # Category removed
71 assert_nil issue.category
78 assert_nil issue.category
72 # Make sure time entries were move to the target project
79 # Make sure time entries were move to the target project
73 assert_equal 2, issue.time_entries.first.project_id
80 assert_equal 2, issue.time_entries.first.project_id
74 end
81 end
75
82
76 def test_issue_destroy
83 def test_issue_destroy
77 Issue.find(1).destroy
84 Issue.find(1).destroy
78 assert_nil Issue.find_by_id(1)
85 assert_nil Issue.find_by_id(1)
79 assert_nil TimeEntry.find_by_issue_id(1)
86 assert_nil TimeEntry.find_by_issue_id(1)
80 end
87 end
81 end
88 end
General Comments 0
You need to be logged in to leave comments. Login now