@@ -1,548 +1,541 | |||||
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 IssuesController < ApplicationController |
|
18 | class IssuesController < ApplicationController | |
19 | menu_item :new_issue, :only => :new |
|
19 | menu_item :new_issue, :only => :new | |
20 | default_search_scope :issues |
|
20 | default_search_scope :issues | |
21 |
|
21 | |||
22 | before_filter :find_issue, :only => [:show, :edit, :reply] |
|
22 | before_filter :find_issue, :only => [:show, :edit, :reply] | |
23 | before_filter :find_issues, :only => [:bulk_edit, :move, :destroy] |
|
23 | before_filter :find_issues, :only => [:bulk_edit, :move, :destroy] | |
24 | before_filter :find_project, :only => [:new, :update_form, :preview] |
|
24 | before_filter :find_project, :only => [:new, :update_form, :preview] | |
25 | before_filter :authorize, :except => [:index, :changes, :gantt, :calendar, :preview, :context_menu] |
|
25 | before_filter :authorize, :except => [:index, :changes, :gantt, :calendar, :preview, :context_menu] | |
26 | before_filter :find_optional_project, :only => [:index, :changes, :gantt, :calendar] |
|
26 | before_filter :find_optional_project, :only => [:index, :changes, :gantt, :calendar] | |
27 | accept_key_auth :index, :show, :changes |
|
27 | accept_key_auth :index, :show, :changes | |
28 |
|
28 | |||
29 | rescue_from Query::StatementInvalid, :with => :query_statement_invalid |
|
29 | rescue_from Query::StatementInvalid, :with => :query_statement_invalid | |
30 |
|
30 | |||
31 | helper :journals |
|
31 | helper :journals | |
32 | helper :projects |
|
32 | helper :projects | |
33 | include ProjectsHelper |
|
33 | include ProjectsHelper | |
34 | helper :custom_fields |
|
34 | helper :custom_fields | |
35 | include CustomFieldsHelper |
|
35 | include CustomFieldsHelper | |
36 | helper :issue_relations |
|
36 | helper :issue_relations | |
37 | include IssueRelationsHelper |
|
37 | include IssueRelationsHelper | |
38 | helper :watchers |
|
38 | helper :watchers | |
39 | include WatchersHelper |
|
39 | include WatchersHelper | |
40 | helper :attachments |
|
40 | helper :attachments | |
41 | include AttachmentsHelper |
|
41 | include AttachmentsHelper | |
42 | helper :queries |
|
42 | helper :queries | |
43 | include QueriesHelper |
|
43 | include QueriesHelper | |
44 | helper :sort |
|
44 | helper :sort | |
45 | include SortHelper |
|
45 | include SortHelper | |
46 | include IssuesHelper |
|
46 | include IssuesHelper | |
47 | helper :timelog |
|
47 | helper :timelog | |
48 | include Redmine::Export::PDF |
|
48 | include Redmine::Export::PDF | |
49 |
|
49 | |||
50 | verify :method => :post, |
|
50 | verify :method => :post, | |
51 | :only => :destroy, |
|
51 | :only => :destroy, | |
52 | :render => { :nothing => true, :status => :method_not_allowed } |
|
52 | :render => { :nothing => true, :status => :method_not_allowed } | |
53 |
|
53 | |||
54 | def index |
|
54 | def index | |
55 | retrieve_query |
|
55 | retrieve_query | |
56 | sort_init(@query.sort_criteria.empty? ? [['id', 'desc']] : @query.sort_criteria) |
|
56 | sort_init(@query.sort_criteria.empty? ? [['id', 'desc']] : @query.sort_criteria) | |
57 | sort_update({'id' => "#{Issue.table_name}.id"}.merge(@query.available_columns.inject({}) {|h, c| h[c.name.to_s] = c.sortable; h})) |
|
57 | sort_update({'id' => "#{Issue.table_name}.id"}.merge(@query.available_columns.inject({}) {|h, c| h[c.name.to_s] = c.sortable; h})) | |
58 |
|
58 | |||
59 | if @query.valid? |
|
59 | if @query.valid? | |
60 | limit = case params[:format] |
|
60 | limit = case params[:format] | |
61 | when 'csv', 'pdf' |
|
61 | when 'csv', 'pdf' | |
62 | Setting.issues_export_limit.to_i |
|
62 | Setting.issues_export_limit.to_i | |
63 | when 'atom' |
|
63 | when 'atom' | |
64 | Setting.feeds_limit.to_i |
|
64 | Setting.feeds_limit.to_i | |
65 | else |
|
65 | else | |
66 | per_page_option |
|
66 | per_page_option | |
67 | end |
|
67 | end | |
68 |
|
68 | |||
69 | @issue_count = @query.issue_count |
|
69 | @issue_count = @query.issue_count | |
70 | @issue_pages = Paginator.new self, @issue_count, limit, params['page'] |
|
70 | @issue_pages = Paginator.new self, @issue_count, limit, params['page'] | |
71 | @issues = @query.issues(:include => [:assigned_to, :tracker, :priority, :category, :fixed_version], |
|
71 | @issues = @query.issues(:include => [:assigned_to, :tracker, :priority, :category, :fixed_version], | |
72 | :order => sort_clause, |
|
72 | :order => sort_clause, | |
73 | :offset => @issue_pages.current.offset, |
|
73 | :offset => @issue_pages.current.offset, | |
74 | :limit => limit) |
|
74 | :limit => limit) | |
75 | @issue_count_by_group = @query.issue_count_by_group |
|
75 | @issue_count_by_group = @query.issue_count_by_group | |
76 |
|
76 | |||
77 | respond_to do |format| |
|
77 | respond_to do |format| | |
78 | format.html { render :template => 'issues/index.rhtml', :layout => !request.xhr? } |
|
78 | format.html { render :template => 'issues/index.rhtml', :layout => !request.xhr? } | |
79 | format.atom { render_feed(@issues, :title => "#{@project || Setting.app_title}: #{l(:label_issue_plural)}") } |
|
79 | format.atom { render_feed(@issues, :title => "#{@project || Setting.app_title}: #{l(:label_issue_plural)}") } | |
80 | format.csv { send_data(issues_to_csv(@issues, @project), :type => 'text/csv; header=present', :filename => 'export.csv') } |
|
80 | format.csv { send_data(issues_to_csv(@issues, @project), :type => 'text/csv; header=present', :filename => 'export.csv') } | |
81 | format.pdf { send_data(issues_to_pdf(@issues, @project, @query), :type => 'application/pdf', :filename => 'export.pdf') } |
|
81 | format.pdf { send_data(issues_to_pdf(@issues, @project, @query), :type => 'application/pdf', :filename => 'export.pdf') } | |
82 | end |
|
82 | end | |
83 | else |
|
83 | else | |
84 | # Send html if the query is not valid |
|
84 | # Send html if the query is not valid | |
85 | render(:template => 'issues/index.rhtml', :layout => !request.xhr?) |
|
85 | render(:template => 'issues/index.rhtml', :layout => !request.xhr?) | |
86 | end |
|
86 | end | |
87 | rescue ActiveRecord::RecordNotFound |
|
87 | rescue ActiveRecord::RecordNotFound | |
88 | render_404 |
|
88 | render_404 | |
89 | end |
|
89 | end | |
90 |
|
90 | |||
91 | def changes |
|
91 | def changes | |
92 | retrieve_query |
|
92 | retrieve_query | |
93 | sort_init 'id', 'desc' |
|
93 | sort_init 'id', 'desc' | |
94 | sort_update({'id' => "#{Issue.table_name}.id"}.merge(@query.available_columns.inject({}) {|h, c| h[c.name.to_s] = c.sortable; h})) |
|
94 | sort_update({'id' => "#{Issue.table_name}.id"}.merge(@query.available_columns.inject({}) {|h, c| h[c.name.to_s] = c.sortable; h})) | |
95 |
|
95 | |||
96 | if @query.valid? |
|
96 | if @query.valid? | |
97 | @journals = @query.journals(:order => "#{Journal.table_name}.created_on DESC", |
|
97 | @journals = @query.journals(:order => "#{Journal.table_name}.created_on DESC", | |
98 | :limit => 25) |
|
98 | :limit => 25) | |
99 | end |
|
99 | end | |
100 | @title = (@project ? @project.name : Setting.app_title) + ": " + (@query.new_record? ? l(:label_changes_details) : @query.name) |
|
100 | @title = (@project ? @project.name : Setting.app_title) + ": " + (@query.new_record? ? l(:label_changes_details) : @query.name) | |
101 | render :layout => false, :content_type => 'application/atom+xml' |
|
101 | render :layout => false, :content_type => 'application/atom+xml' | |
102 | rescue ActiveRecord::RecordNotFound |
|
102 | rescue ActiveRecord::RecordNotFound | |
103 | render_404 |
|
103 | render_404 | |
104 | end |
|
104 | end | |
105 |
|
105 | |||
106 | def show |
|
106 | def show | |
107 | @journals = @issue.journals.find(:all, :include => [:user, :details], :order => "#{Journal.table_name}.created_on ASC") |
|
107 | @journals = @issue.journals.find(:all, :include => [:user, :details], :order => "#{Journal.table_name}.created_on ASC") | |
108 | @journals.each_with_index {|j,i| j.indice = i+1} |
|
108 | @journals.each_with_index {|j,i| j.indice = i+1} | |
109 | @journals.reverse! if User.current.wants_comments_in_reverse_order? |
|
109 | @journals.reverse! if User.current.wants_comments_in_reverse_order? | |
110 | @changesets = @issue.changesets.visible.all |
|
110 | @changesets = @issue.changesets.visible.all | |
111 | @changesets.reverse! if User.current.wants_comments_in_reverse_order? |
|
111 | @changesets.reverse! if User.current.wants_comments_in_reverse_order? | |
112 | @allowed_statuses = @issue.new_statuses_allowed_to(User.current) |
|
112 | @allowed_statuses = @issue.new_statuses_allowed_to(User.current) | |
113 | @edit_allowed = User.current.allowed_to?(:edit_issues, @project) |
|
113 | @edit_allowed = User.current.allowed_to?(:edit_issues, @project) | |
114 | @priorities = IssuePriority.all |
|
114 | @priorities = IssuePriority.all | |
115 | @time_entry = TimeEntry.new |
|
115 | @time_entry = TimeEntry.new | |
116 | respond_to do |format| |
|
116 | respond_to do |format| | |
117 | format.html { render :template => 'issues/show.rhtml' } |
|
117 | format.html { render :template => 'issues/show.rhtml' } | |
118 | format.atom { render :action => 'changes', :layout => false, :content_type => 'application/atom+xml' } |
|
118 | format.atom { render :action => 'changes', :layout => false, :content_type => 'application/atom+xml' } | |
119 | format.pdf { send_data(issue_to_pdf(@issue), :type => 'application/pdf', :filename => "#{@project.identifier}-#{@issue.id}.pdf") } |
|
119 | format.pdf { send_data(issue_to_pdf(@issue), :type => 'application/pdf', :filename => "#{@project.identifier}-#{@issue.id}.pdf") } | |
120 | end |
|
120 | end | |
121 | end |
|
121 | end | |
122 |
|
122 | |||
123 | # Add a new issue |
|
123 | # Add a new issue | |
124 | # The new issue will be created from an existing one if copy_from parameter is given |
|
124 | # The new issue will be created from an existing one if copy_from parameter is given | |
125 | def new |
|
125 | def new | |
126 | @issue = Issue.new |
|
126 | @issue = Issue.new | |
127 | @issue.copy_from(params[:copy_from]) if params[:copy_from] |
|
127 | @issue.copy_from(params[:copy_from]) if params[:copy_from] | |
128 | @issue.project = @project |
|
128 | @issue.project = @project | |
129 | # Tracker must be set before custom field values |
|
129 | # Tracker must be set before custom field values | |
130 | @issue.tracker ||= @project.trackers.find((params[:issue] && params[:issue][:tracker_id]) || params[:tracker_id] || :first) |
|
130 | @issue.tracker ||= @project.trackers.find((params[:issue] && params[:issue][:tracker_id]) || params[:tracker_id] || :first) | |
131 | if @issue.tracker.nil? |
|
131 | if @issue.tracker.nil? | |
132 | render_error l(:error_no_tracker_in_project) |
|
132 | render_error l(:error_no_tracker_in_project) | |
133 | return |
|
133 | return | |
134 | end |
|
134 | end | |
135 | if params[:issue].is_a?(Hash) |
|
135 | if params[:issue].is_a?(Hash) | |
136 | @issue.attributes = params[:issue] |
|
136 | @issue.attributes = params[:issue] | |
137 | @issue.watcher_user_ids = params[:issue]['watcher_user_ids'] if User.current.allowed_to?(:add_issue_watchers, @project) |
|
137 | @issue.watcher_user_ids = params[:issue]['watcher_user_ids'] if User.current.allowed_to?(:add_issue_watchers, @project) | |
138 | end |
|
138 | end | |
139 | @issue.author = User.current |
|
139 | @issue.author = User.current | |
140 |
|
140 | |||
141 | default_status = IssueStatus.default |
|
141 | default_status = IssueStatus.default | |
142 | unless default_status |
|
142 | unless default_status | |
143 | render_error l(:error_no_default_issue_status) |
|
143 | render_error l(:error_no_default_issue_status) | |
144 | return |
|
144 | return | |
145 | end |
|
145 | end | |
146 | @issue.status = default_status |
|
146 | @issue.status = default_status | |
147 | @allowed_statuses = ([default_status] + default_status.find_new_statuses_allowed_to(User.current.roles_for_project(@project), @issue.tracker)).uniq |
|
147 | @allowed_statuses = ([default_status] + default_status.find_new_statuses_allowed_to(User.current.roles_for_project(@project), @issue.tracker)).uniq | |
148 |
|
148 | |||
149 | if request.get? || request.xhr? |
|
149 | if request.get? || request.xhr? | |
150 | @issue.start_date ||= Date.today |
|
150 | @issue.start_date ||= Date.today | |
151 | else |
|
151 | else | |
152 | requested_status = IssueStatus.find_by_id(params[:issue][:status_id]) |
|
152 | requested_status = IssueStatus.find_by_id(params[:issue][:status_id]) | |
153 | # Check that the user is allowed to apply the requested status |
|
153 | # Check that the user is allowed to apply the requested status | |
154 | @issue.status = (@allowed_statuses.include? requested_status) ? requested_status : default_status |
|
154 | @issue.status = (@allowed_statuses.include? requested_status) ? requested_status : default_status | |
155 | call_hook(:controller_issues_new_before_save, { :params => params, :issue => @issue }) |
|
155 | call_hook(:controller_issues_new_before_save, { :params => params, :issue => @issue }) | |
156 | if @issue.save |
|
156 | if @issue.save | |
157 | attach_files(@issue, params[:attachments]) |
|
157 | attach_files(@issue, params[:attachments]) | |
158 | flash[:notice] = l(:notice_successful_create) |
|
158 | flash[:notice] = l(:notice_successful_create) | |
159 | call_hook(:controller_issues_new_after_save, { :params => params, :issue => @issue}) |
|
159 | call_hook(:controller_issues_new_after_save, { :params => params, :issue => @issue}) | |
160 | redirect_to(params[:continue] ? { :action => 'new', :tracker_id => @issue.tracker } : |
|
160 | redirect_to(params[:continue] ? { :action => 'new', :tracker_id => @issue.tracker } : | |
161 | { :action => 'show', :id => @issue }) |
|
161 | { :action => 'show', :id => @issue }) | |
162 | return |
|
162 | return | |
163 | end |
|
163 | end | |
164 | end |
|
164 | end | |
165 | @priorities = IssuePriority.all |
|
165 | @priorities = IssuePriority.all | |
166 | render :layout => !request.xhr? |
|
166 | render :layout => !request.xhr? | |
167 | end |
|
167 | end | |
168 |
|
168 | |||
169 | # Attributes that can be updated on workflow transition (without :edit permission) |
|
169 | # Attributes that can be updated on workflow transition (without :edit permission) | |
170 | # TODO: make it configurable (at least per role) |
|
170 | # TODO: make it configurable (at least per role) | |
171 | UPDATABLE_ATTRS_ON_TRANSITION = %w(status_id assigned_to_id fixed_version_id done_ratio) unless const_defined?(:UPDATABLE_ATTRS_ON_TRANSITION) |
|
171 | UPDATABLE_ATTRS_ON_TRANSITION = %w(status_id assigned_to_id fixed_version_id done_ratio) unless const_defined?(:UPDATABLE_ATTRS_ON_TRANSITION) | |
172 |
|
172 | |||
173 | def edit |
|
173 | def edit | |
174 | @allowed_statuses = @issue.new_statuses_allowed_to(User.current) |
|
174 | @allowed_statuses = @issue.new_statuses_allowed_to(User.current) | |
175 | @priorities = IssuePriority.all |
|
175 | @priorities = IssuePriority.all | |
176 | @edit_allowed = User.current.allowed_to?(:edit_issues, @project) |
|
176 | @edit_allowed = User.current.allowed_to?(:edit_issues, @project) | |
177 | @time_entry = TimeEntry.new |
|
177 | @time_entry = TimeEntry.new | |
178 |
|
178 | |||
179 | @notes = params[:notes] |
|
179 | @notes = params[:notes] | |
180 | journal = @issue.init_journal(User.current, @notes) |
|
180 | journal = @issue.init_journal(User.current, @notes) | |
181 | # User can change issue attributes only if he has :edit permission or if a workflow transition is allowed |
|
181 | # User can change issue attributes only if he has :edit permission or if a workflow transition is allowed | |
182 | if (@edit_allowed || !@allowed_statuses.empty?) && params[:issue] |
|
182 | if (@edit_allowed || !@allowed_statuses.empty?) && params[:issue] | |
183 | attrs = params[:issue].dup |
|
183 | attrs = params[:issue].dup | |
184 | attrs.delete_if {|k,v| !UPDATABLE_ATTRS_ON_TRANSITION.include?(k) } unless @edit_allowed |
|
184 | attrs.delete_if {|k,v| !UPDATABLE_ATTRS_ON_TRANSITION.include?(k) } unless @edit_allowed | |
185 | attrs.delete(:status_id) unless @allowed_statuses.detect {|s| s.id.to_s == attrs[:status_id].to_s} |
|
185 | attrs.delete(:status_id) unless @allowed_statuses.detect {|s| s.id.to_s == attrs[:status_id].to_s} | |
186 | @issue.attributes = attrs |
|
186 | @issue.attributes = attrs | |
187 | end |
|
187 | end | |
188 |
|
188 | |||
189 | if request.post? |
|
189 | if request.post? | |
190 | @time_entry = TimeEntry.new(:project => @project, :issue => @issue, :user => User.current, :spent_on => Date.today) |
|
190 | @time_entry = TimeEntry.new(:project => @project, :issue => @issue, :user => User.current, :spent_on => Date.today) | |
191 | @time_entry.attributes = params[:time_entry] |
|
191 | @time_entry.attributes = params[:time_entry] | |
192 | if (@time_entry.hours.nil? || @time_entry.valid?) && @issue.valid? |
|
192 | if (@time_entry.hours.nil? || @time_entry.valid?) && @issue.valid? | |
193 | attachments = attach_files(@issue, params[:attachments]) |
|
193 | attachments = attach_files(@issue, params[:attachments]) | |
194 | attachments.each {|a| journal.details << JournalDetail.new(:property => 'attachment', :prop_key => a.id, :value => a.filename)} |
|
194 | attachments.each {|a| journal.details << JournalDetail.new(:property => 'attachment', :prop_key => a.id, :value => a.filename)} | |
195 | call_hook(:controller_issues_edit_before_save, { :params => params, :issue => @issue, :time_entry => @time_entry, :journal => journal}) |
|
195 | call_hook(:controller_issues_edit_before_save, { :params => params, :issue => @issue, :time_entry => @time_entry, :journal => journal}) | |
196 | if @issue.save |
|
196 | if @issue.save | |
197 | # Log spend time |
|
197 | # Log spend time | |
198 | if User.current.allowed_to?(:log_time, @project) |
|
198 | if User.current.allowed_to?(:log_time, @project) | |
199 | @time_entry.save |
|
199 | @time_entry.save | |
200 | end |
|
200 | end | |
201 | if !journal.new_record? |
|
201 | if !journal.new_record? | |
202 | # Only send notification if something was actually changed |
|
202 | # Only send notification if something was actually changed | |
203 | flash[:notice] = l(:notice_successful_update) |
|
203 | flash[:notice] = l(:notice_successful_update) | |
204 | end |
|
204 | end | |
205 | call_hook(:controller_issues_edit_after_save, { :params => params, :issue => @issue, :time_entry => @time_entry, :journal => journal}) |
|
205 | call_hook(:controller_issues_edit_after_save, { :params => params, :issue => @issue, :time_entry => @time_entry, :journal => journal}) | |
206 | redirect_back_or_default({:action => 'show', :id => @issue}) |
|
206 | redirect_back_or_default({:action => 'show', :id => @issue}) | |
207 | end |
|
207 | end | |
208 | end |
|
208 | end | |
209 | end |
|
209 | end | |
210 | rescue ActiveRecord::StaleObjectError |
|
210 | rescue ActiveRecord::StaleObjectError | |
211 | # Optimistic locking exception |
|
211 | # Optimistic locking exception | |
212 | flash.now[:error] = l(:notice_locking_conflict) |
|
212 | flash.now[:error] = l(:notice_locking_conflict) | |
213 | # Remove the previously added attachments if issue was not updated |
|
213 | # Remove the previously added attachments if issue was not updated | |
214 | attachments.each(&:destroy) |
|
214 | attachments.each(&:destroy) | |
215 | end |
|
215 | end | |
216 |
|
216 | |||
217 | def reply |
|
217 | def reply | |
218 | journal = Journal.find(params[:journal_id]) if params[:journal_id] |
|
218 | journal = Journal.find(params[:journal_id]) if params[:journal_id] | |
219 | if journal |
|
219 | if journal | |
220 | user = journal.user |
|
220 | user = journal.user | |
221 | text = journal.notes |
|
221 | text = journal.notes | |
222 | else |
|
222 | else | |
223 | user = @issue.author |
|
223 | user = @issue.author | |
224 | text = @issue.description |
|
224 | text = @issue.description | |
225 | end |
|
225 | end | |
226 | # Replaces pre blocks with [...] |
|
226 | # Replaces pre blocks with [...] | |
227 | text = text.to_s.strip.gsub(%r{<pre>((.|\s)*?)</pre>}m, '[...]') |
|
227 | text = text.to_s.strip.gsub(%r{<pre>((.|\s)*?)</pre>}m, '[...]') | |
228 | content = "#{ll(Setting.default_language, :text_user_wrote, user)}\n> " |
|
228 | content = "#{ll(Setting.default_language, :text_user_wrote, user)}\n> " | |
229 | content << text.gsub(/(\r?\n|\r\n?)/, "\n> ") + "\n\n" |
|
229 | content << text.gsub(/(\r?\n|\r\n?)/, "\n> ") + "\n\n" | |
230 |
|
230 | |||
231 | render(:update) { |page| |
|
231 | render(:update) { |page| | |
232 | page.<< "$('notes').value = \"#{escape_javascript content}\";" |
|
232 | page.<< "$('notes').value = \"#{escape_javascript content}\";" | |
233 | page.show 'update' |
|
233 | page.show 'update' | |
234 | page << "Form.Element.focus('notes');" |
|
234 | page << "Form.Element.focus('notes');" | |
235 | page << "Element.scrollTo('update');" |
|
235 | page << "Element.scrollTo('update');" | |
236 | page << "$('notes').scrollTop = $('notes').scrollHeight - $('notes').clientHeight;" |
|
236 | page << "$('notes').scrollTop = $('notes').scrollHeight - $('notes').clientHeight;" | |
237 | } |
|
237 | } | |
238 | end |
|
238 | end | |
239 |
|
239 | |||
240 | # Bulk edit a set of issues |
|
240 | # Bulk edit a set of issues | |
241 | def bulk_edit |
|
241 | def bulk_edit | |
242 | if request.post? |
|
242 | if request.post? | |
243 | tracker = params[:tracker_id].blank? ? nil : @project.trackers.find_by_id(params[:tracker_id]) |
|
243 | tracker = params[:tracker_id].blank? ? nil : @project.trackers.find_by_id(params[:tracker_id]) | |
244 | status = params[:status_id].blank? ? nil : IssueStatus.find_by_id(params[:status_id]) |
|
244 | status = params[:status_id].blank? ? nil : IssueStatus.find_by_id(params[:status_id]) | |
245 | priority = params[:priority_id].blank? ? nil : IssuePriority.find_by_id(params[:priority_id]) |
|
245 | priority = params[:priority_id].blank? ? nil : IssuePriority.find_by_id(params[:priority_id]) | |
246 | assigned_to = (params[:assigned_to_id].blank? || params[:assigned_to_id] == 'none') ? nil : User.find_by_id(params[:assigned_to_id]) |
|
246 | assigned_to = (params[:assigned_to_id].blank? || params[:assigned_to_id] == 'none') ? nil : User.find_by_id(params[:assigned_to_id]) | |
247 | category = (params[:category_id].blank? || params[:category_id] == 'none') ? nil : @project.issue_categories.find_by_id(params[:category_id]) |
|
247 | category = (params[:category_id].blank? || params[:category_id] == 'none') ? nil : @project.issue_categories.find_by_id(params[:category_id]) | |
248 | fixed_version = (params[:fixed_version_id].blank? || params[:fixed_version_id] == 'none') ? nil : @project.shared_versions.find_by_id(params[:fixed_version_id]) |
|
248 | fixed_version = (params[:fixed_version_id].blank? || params[:fixed_version_id] == 'none') ? nil : @project.shared_versions.find_by_id(params[:fixed_version_id]) | |
249 | custom_field_values = params[:custom_field_values] ? params[:custom_field_values].reject {|k,v| v.blank?} : nil |
|
249 | custom_field_values = params[:custom_field_values] ? params[:custom_field_values].reject {|k,v| v.blank?} : nil | |
250 |
|
250 | |||
251 | unsaved_issue_ids = [] |
|
251 | unsaved_issue_ids = [] | |
252 | @issues.each do |issue| |
|
252 | @issues.each do |issue| | |
253 | journal = issue.init_journal(User.current, params[:notes]) |
|
253 | journal = issue.init_journal(User.current, params[:notes]) | |
254 | issue.tracker = tracker if tracker |
|
254 | issue.tracker = tracker if tracker | |
255 | issue.priority = priority if priority |
|
255 | issue.priority = priority if priority | |
256 | issue.assigned_to = assigned_to if assigned_to || params[:assigned_to_id] == 'none' |
|
256 | issue.assigned_to = assigned_to if assigned_to || params[:assigned_to_id] == 'none' | |
257 | issue.category = category if category || params[:category_id] == 'none' |
|
257 | issue.category = category if category || params[:category_id] == 'none' | |
258 | issue.fixed_version = fixed_version if fixed_version || params[:fixed_version_id] == 'none' |
|
258 | issue.fixed_version = fixed_version if fixed_version || params[:fixed_version_id] == 'none' | |
259 | issue.start_date = params[:start_date] unless params[:start_date].blank? |
|
259 | issue.start_date = params[:start_date] unless params[:start_date].blank? | |
260 | issue.due_date = params[:due_date] unless params[:due_date].blank? |
|
260 | issue.due_date = params[:due_date] unless params[:due_date].blank? | |
261 | issue.done_ratio = params[:done_ratio] unless params[:done_ratio].blank? |
|
261 | issue.done_ratio = params[:done_ratio] unless params[:done_ratio].blank? | |
262 | issue.custom_field_values = custom_field_values if custom_field_values && !custom_field_values.empty? |
|
262 | issue.custom_field_values = custom_field_values if custom_field_values && !custom_field_values.empty? | |
263 | call_hook(:controller_issues_bulk_edit_before_save, { :params => params, :issue => issue }) |
|
263 | call_hook(:controller_issues_bulk_edit_before_save, { :params => params, :issue => issue }) | |
264 | # Don't save any change to the issue if the user is not authorized to apply the requested status |
|
264 | # Don't save any change to the issue if the user is not authorized to apply the requested status | |
265 | unless (status.nil? || (issue.new_statuses_allowed_to(User.current).include?(status) && issue.status = status)) && issue.save |
|
265 | unless (status.nil? || (issue.new_statuses_allowed_to(User.current).include?(status) && issue.status = status)) && issue.save | |
266 | # Keep unsaved issue ids to display them in flash error |
|
266 | # Keep unsaved issue ids to display them in flash error | |
267 | unsaved_issue_ids << issue.id |
|
267 | unsaved_issue_ids << issue.id | |
268 | end |
|
268 | end | |
269 | end |
|
269 | end | |
270 | if unsaved_issue_ids.empty? |
|
270 | if unsaved_issue_ids.empty? | |
271 | flash[:notice] = l(:notice_successful_update) unless @issues.empty? |
|
271 | flash[:notice] = l(:notice_successful_update) unless @issues.empty? | |
272 | else |
|
272 | else | |
273 | flash[:error] = l(:notice_failed_to_save_issues, :count => unsaved_issue_ids.size, |
|
273 | flash[:error] = l(:notice_failed_to_save_issues, :count => unsaved_issue_ids.size, | |
274 | :total => @issues.size, |
|
274 | :total => @issues.size, | |
275 | :ids => '#' + unsaved_issue_ids.join(', #')) |
|
275 | :ids => '#' + unsaved_issue_ids.join(', #')) | |
276 | end |
|
276 | end | |
277 | redirect_back_or_default({:controller => 'issues', :action => 'index', :project_id => @project}) |
|
277 | redirect_back_or_default({:controller => 'issues', :action => 'index', :project_id => @project}) | |
278 | return |
|
278 | return | |
279 | end |
|
279 | end | |
280 | @available_statuses = Workflow.available_statuses(@project) |
|
280 | @available_statuses = Workflow.available_statuses(@project) | |
281 | @custom_fields = @project.all_issue_custom_fields |
|
281 | @custom_fields = @project.all_issue_custom_fields | |
282 | end |
|
282 | end | |
283 |
|
283 | |||
284 | def move |
|
284 | def move | |
285 | @copy = params[:copy_options] && params[:copy_options][:copy] |
|
285 | @copy = params[:copy_options] && params[:copy_options][:copy] | |
286 | @allowed_projects = [] |
|
286 | @allowed_projects = Issue.allowed_target_projects_on_move | |
287 | # find projects to which the user is allowed to move the issue |
|
|||
288 | if User.current.admin? |
|
|||
289 | # admin is allowed to move issues to any active (visible) project |
|
|||
290 | @allowed_projects = Project.find(:all, :conditions => Project.visible_by(User.current)) |
|
|||
291 | else |
|
|||
292 | User.current.memberships.each {|m| @allowed_projects << m.project if m.roles.detect {|r| r.allowed_to?(:move_issues)}} |
|
|||
293 | end |
|
|||
294 | @target_project = @allowed_projects.detect {|p| p.id.to_s == params[:new_project_id]} if params[:new_project_id] |
|
287 | @target_project = @allowed_projects.detect {|p| p.id.to_s == params[:new_project_id]} if params[:new_project_id] | |
295 | @target_project ||= @project |
|
288 | @target_project ||= @project | |
296 | @trackers = @target_project.trackers |
|
289 | @trackers = @target_project.trackers | |
297 | @available_statuses = Workflow.available_statuses(@project) |
|
290 | @available_statuses = Workflow.available_statuses(@project) | |
298 | if request.post? |
|
291 | if request.post? | |
299 | new_tracker = params[:new_tracker_id].blank? ? nil : @target_project.trackers.find_by_id(params[:new_tracker_id]) |
|
292 | new_tracker = params[:new_tracker_id].blank? ? nil : @target_project.trackers.find_by_id(params[:new_tracker_id]) | |
300 | unsaved_issue_ids = [] |
|
293 | unsaved_issue_ids = [] | |
301 | moved_issues = [] |
|
294 | moved_issues = [] | |
302 | @issues.each do |issue| |
|
295 | @issues.each do |issue| | |
303 | changed_attributes = {} |
|
296 | changed_attributes = {} | |
304 | [:assigned_to_id, :status_id, :start_date, :due_date].each do |valid_attribute| |
|
297 | [:assigned_to_id, :status_id, :start_date, :due_date].each do |valid_attribute| | |
305 | unless params[valid_attribute].blank? |
|
298 | unless params[valid_attribute].blank? | |
306 | changed_attributes[valid_attribute] = (params[valid_attribute] == 'none' ? nil : params[valid_attribute]) |
|
299 | changed_attributes[valid_attribute] = (params[valid_attribute] == 'none' ? nil : params[valid_attribute]) | |
307 | end |
|
300 | end | |
308 | end |
|
301 | end | |
309 | issue.init_journal(User.current) |
|
302 | issue.init_journal(User.current) | |
310 | if r = issue.move_to(@target_project, new_tracker, {:copy => @copy, :attributes => changed_attributes}) |
|
303 | if r = issue.move_to(@target_project, new_tracker, {:copy => @copy, :attributes => changed_attributes}) | |
311 | moved_issues << r |
|
304 | moved_issues << r | |
312 | else |
|
305 | else | |
313 | unsaved_issue_ids << issue.id |
|
306 | unsaved_issue_ids << issue.id | |
314 | end |
|
307 | end | |
315 | end |
|
308 | end | |
316 | if unsaved_issue_ids.empty? |
|
309 | if unsaved_issue_ids.empty? | |
317 | flash[:notice] = l(:notice_successful_update) unless @issues.empty? |
|
310 | flash[:notice] = l(:notice_successful_update) unless @issues.empty? | |
318 | else |
|
311 | else | |
319 | flash[:error] = l(:notice_failed_to_save_issues, :count => unsaved_issue_ids.size, |
|
312 | flash[:error] = l(:notice_failed_to_save_issues, :count => unsaved_issue_ids.size, | |
320 | :total => @issues.size, |
|
313 | :total => @issues.size, | |
321 | :ids => '#' + unsaved_issue_ids.join(', #')) |
|
314 | :ids => '#' + unsaved_issue_ids.join(', #')) | |
322 | end |
|
315 | end | |
323 | if params[:follow] |
|
316 | if params[:follow] | |
324 | if @issues.size == 1 && moved_issues.size == 1 |
|
317 | if @issues.size == 1 && moved_issues.size == 1 | |
325 | redirect_to :controller => 'issues', :action => 'show', :id => moved_issues.first |
|
318 | redirect_to :controller => 'issues', :action => 'show', :id => moved_issues.first | |
326 | else |
|
319 | else | |
327 | redirect_to :controller => 'issues', :action => 'index', :project_id => (@target_project || @project) |
|
320 | redirect_to :controller => 'issues', :action => 'index', :project_id => (@target_project || @project) | |
328 | end |
|
321 | end | |
329 | else |
|
322 | else | |
330 | redirect_to :controller => 'issues', :action => 'index', :project_id => @project |
|
323 | redirect_to :controller => 'issues', :action => 'index', :project_id => @project | |
331 | end |
|
324 | end | |
332 | return |
|
325 | return | |
333 | end |
|
326 | end | |
334 | render :layout => false if request.xhr? |
|
327 | render :layout => false if request.xhr? | |
335 | end |
|
328 | end | |
336 |
|
329 | |||
337 | def destroy |
|
330 | def destroy | |
338 | @hours = TimeEntry.sum(:hours, :conditions => ['issue_id IN (?)', @issues]).to_f |
|
331 | @hours = TimeEntry.sum(:hours, :conditions => ['issue_id IN (?)', @issues]).to_f | |
339 | if @hours > 0 |
|
332 | if @hours > 0 | |
340 | case params[:todo] |
|
333 | case params[:todo] | |
341 | when 'destroy' |
|
334 | when 'destroy' | |
342 | # nothing to do |
|
335 | # nothing to do | |
343 | when 'nullify' |
|
336 | when 'nullify' | |
344 | TimeEntry.update_all('issue_id = NULL', ['issue_id IN (?)', @issues]) |
|
337 | TimeEntry.update_all('issue_id = NULL', ['issue_id IN (?)', @issues]) | |
345 | when 'reassign' |
|
338 | when 'reassign' | |
346 | reassign_to = @project.issues.find_by_id(params[:reassign_to_id]) |
|
339 | reassign_to = @project.issues.find_by_id(params[:reassign_to_id]) | |
347 | if reassign_to.nil? |
|
340 | if reassign_to.nil? | |
348 | flash.now[:error] = l(:error_issue_not_found_in_project) |
|
341 | flash.now[:error] = l(:error_issue_not_found_in_project) | |
349 | return |
|
342 | return | |
350 | else |
|
343 | else | |
351 | TimeEntry.update_all("issue_id = #{reassign_to.id}", ['issue_id IN (?)', @issues]) |
|
344 | TimeEntry.update_all("issue_id = #{reassign_to.id}", ['issue_id IN (?)', @issues]) | |
352 | end |
|
345 | end | |
353 | else |
|
346 | else | |
354 | # display the destroy form |
|
347 | # display the destroy form | |
355 | return |
|
348 | return | |
356 | end |
|
349 | end | |
357 | end |
|
350 | end | |
358 | @issues.each(&:destroy) |
|
351 | @issues.each(&:destroy) | |
359 | redirect_to :action => 'index', :project_id => @project |
|
352 | redirect_to :action => 'index', :project_id => @project | |
360 | end |
|
353 | end | |
361 |
|
354 | |||
362 | def gantt |
|
355 | def gantt | |
363 | @gantt = Redmine::Helpers::Gantt.new(params) |
|
356 | @gantt = Redmine::Helpers::Gantt.new(params) | |
364 | retrieve_query |
|
357 | retrieve_query | |
365 | @query.group_by = nil |
|
358 | @query.group_by = nil | |
366 | if @query.valid? |
|
359 | if @query.valid? | |
367 | events = [] |
|
360 | events = [] | |
368 | # Issues that have start and due dates |
|
361 | # Issues that have start and due dates | |
369 | events += @query.issues(:include => [:tracker, :assigned_to, :priority], |
|
362 | events += @query.issues(:include => [:tracker, :assigned_to, :priority], | |
370 | :order => "start_date, due_date", |
|
363 | :order => "start_date, due_date", | |
371 | :conditions => ["(((start_date>=? and start_date<=?) or (due_date>=? and due_date<=?) or (start_date<? and due_date>?)) and start_date is not null and due_date is not null)", @gantt.date_from, @gantt.date_to, @gantt.date_from, @gantt.date_to, @gantt.date_from, @gantt.date_to] |
|
364 | :conditions => ["(((start_date>=? and start_date<=?) or (due_date>=? and due_date<=?) or (start_date<? and due_date>?)) and start_date is not null and due_date is not null)", @gantt.date_from, @gantt.date_to, @gantt.date_from, @gantt.date_to, @gantt.date_from, @gantt.date_to] | |
372 | ) |
|
365 | ) | |
373 | # Issues that don't have a due date but that are assigned to a version with a date |
|
366 | # Issues that don't have a due date but that are assigned to a version with a date | |
374 | events += @query.issues(:include => [:tracker, :assigned_to, :priority, :fixed_version], |
|
367 | events += @query.issues(:include => [:tracker, :assigned_to, :priority, :fixed_version], | |
375 | :order => "start_date, effective_date", |
|
368 | :order => "start_date, effective_date", | |
376 | :conditions => ["(((start_date>=? and start_date<=?) or (effective_date>=? and effective_date<=?) or (start_date<? and effective_date>?)) and start_date is not null and due_date is null and effective_date is not null)", @gantt.date_from, @gantt.date_to, @gantt.date_from, @gantt.date_to, @gantt.date_from, @gantt.date_to] |
|
369 | :conditions => ["(((start_date>=? and start_date<=?) or (effective_date>=? and effective_date<=?) or (start_date<? and effective_date>?)) and start_date is not null and due_date is null and effective_date is not null)", @gantt.date_from, @gantt.date_to, @gantt.date_from, @gantt.date_to, @gantt.date_from, @gantt.date_to] | |
377 | ) |
|
370 | ) | |
378 | # Versions |
|
371 | # Versions | |
379 | events += @query.versions(:conditions => ["effective_date BETWEEN ? AND ?", @gantt.date_from, @gantt.date_to]) |
|
372 | events += @query.versions(:conditions => ["effective_date BETWEEN ? AND ?", @gantt.date_from, @gantt.date_to]) | |
380 |
|
373 | |||
381 | @gantt.events = events |
|
374 | @gantt.events = events | |
382 | end |
|
375 | end | |
383 |
|
376 | |||
384 | basename = (@project ? "#{@project.identifier}-" : '') + 'gantt' |
|
377 | basename = (@project ? "#{@project.identifier}-" : '') + 'gantt' | |
385 |
|
378 | |||
386 | respond_to do |format| |
|
379 | respond_to do |format| | |
387 | format.html { render :template => "issues/gantt.rhtml", :layout => !request.xhr? } |
|
380 | format.html { render :template => "issues/gantt.rhtml", :layout => !request.xhr? } | |
388 | format.png { send_data(@gantt.to_image, :disposition => 'inline', :type => 'image/png', :filename => "#{basename}.png") } if @gantt.respond_to?('to_image') |
|
381 | format.png { send_data(@gantt.to_image, :disposition => 'inline', :type => 'image/png', :filename => "#{basename}.png") } if @gantt.respond_to?('to_image') | |
389 | format.pdf { send_data(gantt_to_pdf(@gantt, @project), :type => 'application/pdf', :filename => "#{basename}.pdf") } |
|
382 | format.pdf { send_data(gantt_to_pdf(@gantt, @project), :type => 'application/pdf', :filename => "#{basename}.pdf") } | |
390 | end |
|
383 | end | |
391 | end |
|
384 | end | |
392 |
|
385 | |||
393 | def calendar |
|
386 | def calendar | |
394 | if params[:year] and params[:year].to_i > 1900 |
|
387 | if params[:year] and params[:year].to_i > 1900 | |
395 | @year = params[:year].to_i |
|
388 | @year = params[:year].to_i | |
396 | if params[:month] and params[:month].to_i > 0 and params[:month].to_i < 13 |
|
389 | if params[:month] and params[:month].to_i > 0 and params[:month].to_i < 13 | |
397 | @month = params[:month].to_i |
|
390 | @month = params[:month].to_i | |
398 | end |
|
391 | end | |
399 | end |
|
392 | end | |
400 | @year ||= Date.today.year |
|
393 | @year ||= Date.today.year | |
401 | @month ||= Date.today.month |
|
394 | @month ||= Date.today.month | |
402 |
|
395 | |||
403 | @calendar = Redmine::Helpers::Calendar.new(Date.civil(@year, @month, 1), current_language, :month) |
|
396 | @calendar = Redmine::Helpers::Calendar.new(Date.civil(@year, @month, 1), current_language, :month) | |
404 | retrieve_query |
|
397 | retrieve_query | |
405 | @query.group_by = nil |
|
398 | @query.group_by = nil | |
406 | if @query.valid? |
|
399 | if @query.valid? | |
407 | events = [] |
|
400 | events = [] | |
408 | events += @query.issues(:include => [:tracker, :assigned_to, :priority], |
|
401 | events += @query.issues(:include => [:tracker, :assigned_to, :priority], | |
409 | :conditions => ["((start_date BETWEEN ? AND ?) OR (due_date BETWEEN ? AND ?))", @calendar.startdt, @calendar.enddt, @calendar.startdt, @calendar.enddt] |
|
402 | :conditions => ["((start_date BETWEEN ? AND ?) OR (due_date BETWEEN ? AND ?))", @calendar.startdt, @calendar.enddt, @calendar.startdt, @calendar.enddt] | |
410 | ) |
|
403 | ) | |
411 | events += @query.versions(:conditions => ["effective_date BETWEEN ? AND ?", @calendar.startdt, @calendar.enddt]) |
|
404 | events += @query.versions(:conditions => ["effective_date BETWEEN ? AND ?", @calendar.startdt, @calendar.enddt]) | |
412 |
|
405 | |||
413 | @calendar.events = events |
|
406 | @calendar.events = events | |
414 | end |
|
407 | end | |
415 |
|
408 | |||
416 | render :layout => false if request.xhr? |
|
409 | render :layout => false if request.xhr? | |
417 | end |
|
410 | end | |
418 |
|
411 | |||
419 | def context_menu |
|
412 | def context_menu | |
420 | @issues = Issue.find_all_by_id(params[:ids], :include => :project) |
|
413 | @issues = Issue.find_all_by_id(params[:ids], :include => :project) | |
421 | if (@issues.size == 1) |
|
414 | if (@issues.size == 1) | |
422 | @issue = @issues.first |
|
415 | @issue = @issues.first | |
423 | @allowed_statuses = @issue.new_statuses_allowed_to(User.current) |
|
416 | @allowed_statuses = @issue.new_statuses_allowed_to(User.current) | |
424 | end |
|
417 | end | |
425 | projects = @issues.collect(&:project).compact.uniq |
|
418 | projects = @issues.collect(&:project).compact.uniq | |
426 | @project = projects.first if projects.size == 1 |
|
419 | @project = projects.first if projects.size == 1 | |
427 |
|
420 | |||
428 | @can = {:edit => (@project && User.current.allowed_to?(:edit_issues, @project)), |
|
421 | @can = {:edit => (@project && User.current.allowed_to?(:edit_issues, @project)), | |
429 | :log_time => (@project && User.current.allowed_to?(:log_time, @project)), |
|
422 | :log_time => (@project && User.current.allowed_to?(:log_time, @project)), | |
430 | :update => (@project && (User.current.allowed_to?(:edit_issues, @project) || (User.current.allowed_to?(:change_status, @project) && @allowed_statuses && !@allowed_statuses.empty?))), |
|
423 | :update => (@project && (User.current.allowed_to?(:edit_issues, @project) || (User.current.allowed_to?(:change_status, @project) && @allowed_statuses && !@allowed_statuses.empty?))), | |
431 | :move => (@project && User.current.allowed_to?(:move_issues, @project)), |
|
424 | :move => (@project && User.current.allowed_to?(:move_issues, @project)), | |
432 | :copy => (@issue && @project.trackers.include?(@issue.tracker) && User.current.allowed_to?(:add_issues, @project)), |
|
425 | :copy => (@issue && @project.trackers.include?(@issue.tracker) && User.current.allowed_to?(:add_issues, @project)), | |
433 | :delete => (@project && User.current.allowed_to?(:delete_issues, @project)) |
|
426 | :delete => (@project && User.current.allowed_to?(:delete_issues, @project)) | |
434 | } |
|
427 | } | |
435 | if @project |
|
428 | if @project | |
436 | @assignables = @project.assignable_users |
|
429 | @assignables = @project.assignable_users | |
437 | @assignables << @issue.assigned_to if @issue && @issue.assigned_to && !@assignables.include?(@issue.assigned_to) |
|
430 | @assignables << @issue.assigned_to if @issue && @issue.assigned_to && !@assignables.include?(@issue.assigned_to) | |
438 | @trackers = @project.trackers |
|
431 | @trackers = @project.trackers | |
439 | end |
|
432 | end | |
440 |
|
433 | |||
441 | @priorities = IssuePriority.all.reverse |
|
434 | @priorities = IssuePriority.all.reverse | |
442 | @statuses = IssueStatus.find(:all, :order => 'position') |
|
435 | @statuses = IssueStatus.find(:all, :order => 'position') | |
443 | @back = params[:back_url] || request.env['HTTP_REFERER'] |
|
436 | @back = params[:back_url] || request.env['HTTP_REFERER'] | |
444 |
|
437 | |||
445 | render :layout => false |
|
438 | render :layout => false | |
446 | end |
|
439 | end | |
447 |
|
440 | |||
448 | def update_form |
|
441 | def update_form | |
449 | if params[:id].blank? |
|
442 | if params[:id].blank? | |
450 | @issue = Issue.new |
|
443 | @issue = Issue.new | |
451 | @issue.project = @project |
|
444 | @issue.project = @project | |
452 | else |
|
445 | else | |
453 | @issue = @project.issues.visible.find(params[:id]) |
|
446 | @issue = @project.issues.visible.find(params[:id]) | |
454 | end |
|
447 | end | |
455 | @issue.attributes = params[:issue] |
|
448 | @issue.attributes = params[:issue] | |
456 | @allowed_statuses = ([@issue.status] + @issue.status.find_new_statuses_allowed_to(User.current.roles_for_project(@project), @issue.tracker)).uniq |
|
449 | @allowed_statuses = ([@issue.status] + @issue.status.find_new_statuses_allowed_to(User.current.roles_for_project(@project), @issue.tracker)).uniq | |
457 | @priorities = IssuePriority.all |
|
450 | @priorities = IssuePriority.all | |
458 |
|
451 | |||
459 | render :partial => 'attributes' |
|
452 | render :partial => 'attributes' | |
460 | end |
|
453 | end | |
461 |
|
454 | |||
462 | def preview |
|
455 | def preview | |
463 | @issue = @project.issues.find_by_id(params[:id]) unless params[:id].blank? |
|
456 | @issue = @project.issues.find_by_id(params[:id]) unless params[:id].blank? | |
464 | @attachements = @issue.attachments if @issue |
|
457 | @attachements = @issue.attachments if @issue | |
465 | @text = params[:notes] || (params[:issue] ? params[:issue][:description] : nil) |
|
458 | @text = params[:notes] || (params[:issue] ? params[:issue][:description] : nil) | |
466 | render :partial => 'common/preview' |
|
459 | render :partial => 'common/preview' | |
467 | end |
|
460 | end | |
468 |
|
461 | |||
469 | private |
|
462 | private | |
470 | def find_issue |
|
463 | def find_issue | |
471 | @issue = Issue.find(params[:id], :include => [:project, :tracker, :status, :author, :priority, :category]) |
|
464 | @issue = Issue.find(params[:id], :include => [:project, :tracker, :status, :author, :priority, :category]) | |
472 | @project = @issue.project |
|
465 | @project = @issue.project | |
473 | rescue ActiveRecord::RecordNotFound |
|
466 | rescue ActiveRecord::RecordNotFound | |
474 | render_404 |
|
467 | render_404 | |
475 | end |
|
468 | end | |
476 |
|
469 | |||
477 | # Filter for bulk operations |
|
470 | # Filter for bulk operations | |
478 | def find_issues |
|
471 | def find_issues | |
479 | @issues = Issue.find_all_by_id(params[:id] || params[:ids]) |
|
472 | @issues = Issue.find_all_by_id(params[:id] || params[:ids]) | |
480 | raise ActiveRecord::RecordNotFound if @issues.empty? |
|
473 | raise ActiveRecord::RecordNotFound if @issues.empty? | |
481 | projects = @issues.collect(&:project).compact.uniq |
|
474 | projects = @issues.collect(&:project).compact.uniq | |
482 | if projects.size == 1 |
|
475 | if projects.size == 1 | |
483 | @project = projects.first |
|
476 | @project = projects.first | |
484 | else |
|
477 | else | |
485 | # TODO: let users bulk edit/move/destroy issues from different projects |
|
478 | # TODO: let users bulk edit/move/destroy issues from different projects | |
486 | render_error 'Can not bulk edit/move/destroy issues from different projects' |
|
479 | render_error 'Can not bulk edit/move/destroy issues from different projects' | |
487 | return false |
|
480 | return false | |
488 | end |
|
481 | end | |
489 | rescue ActiveRecord::RecordNotFound |
|
482 | rescue ActiveRecord::RecordNotFound | |
490 | render_404 |
|
483 | render_404 | |
491 | end |
|
484 | end | |
492 |
|
485 | |||
493 | def find_project |
|
486 | def find_project | |
494 | @project = Project.find(params[:project_id]) |
|
487 | @project = Project.find(params[:project_id]) | |
495 | rescue ActiveRecord::RecordNotFound |
|
488 | rescue ActiveRecord::RecordNotFound | |
496 | render_404 |
|
489 | render_404 | |
497 | end |
|
490 | end | |
498 |
|
491 | |||
499 | def find_optional_project |
|
492 | def find_optional_project | |
500 | @project = Project.find(params[:project_id]) unless params[:project_id].blank? |
|
493 | @project = Project.find(params[:project_id]) unless params[:project_id].blank? | |
501 | allowed = User.current.allowed_to?({:controller => params[:controller], :action => params[:action]}, @project, :global => true) |
|
494 | allowed = User.current.allowed_to?({:controller => params[:controller], :action => params[:action]}, @project, :global => true) | |
502 | allowed ? true : deny_access |
|
495 | allowed ? true : deny_access | |
503 | rescue ActiveRecord::RecordNotFound |
|
496 | rescue ActiveRecord::RecordNotFound | |
504 | render_404 |
|
497 | render_404 | |
505 | end |
|
498 | end | |
506 |
|
499 | |||
507 | # Retrieve query from session or build a new query |
|
500 | # Retrieve query from session or build a new query | |
508 | def retrieve_query |
|
501 | def retrieve_query | |
509 | if !params[:query_id].blank? |
|
502 | if !params[:query_id].blank? | |
510 | cond = "project_id IS NULL" |
|
503 | cond = "project_id IS NULL" | |
511 | cond << " OR project_id = #{@project.id}" if @project |
|
504 | cond << " OR project_id = #{@project.id}" if @project | |
512 | @query = Query.find(params[:query_id], :conditions => cond) |
|
505 | @query = Query.find(params[:query_id], :conditions => cond) | |
513 | @query.project = @project |
|
506 | @query.project = @project | |
514 | session[:query] = {:id => @query.id, :project_id => @query.project_id} |
|
507 | session[:query] = {:id => @query.id, :project_id => @query.project_id} | |
515 | sort_clear |
|
508 | sort_clear | |
516 | else |
|
509 | else | |
517 | if params[:set_filter] || session[:query].nil? || session[:query][:project_id] != (@project ? @project.id : nil) |
|
510 | if params[:set_filter] || session[:query].nil? || session[:query][:project_id] != (@project ? @project.id : nil) | |
518 | # Give it a name, required to be valid |
|
511 | # Give it a name, required to be valid | |
519 | @query = Query.new(:name => "_") |
|
512 | @query = Query.new(:name => "_") | |
520 | @query.project = @project |
|
513 | @query.project = @project | |
521 | if params[:fields] and params[:fields].is_a? Array |
|
514 | if params[:fields] and params[:fields].is_a? Array | |
522 | params[:fields].each do |field| |
|
515 | params[:fields].each do |field| | |
523 | @query.add_filter(field, params[:operators][field], params[:values][field]) |
|
516 | @query.add_filter(field, params[:operators][field], params[:values][field]) | |
524 | end |
|
517 | end | |
525 | else |
|
518 | else | |
526 | @query.available_filters.keys.each do |field| |
|
519 | @query.available_filters.keys.each do |field| | |
527 | @query.add_short_filter(field, params[field]) if params[field] |
|
520 | @query.add_short_filter(field, params[field]) if params[field] | |
528 | end |
|
521 | end | |
529 | end |
|
522 | end | |
530 | @query.group_by = params[:group_by] |
|
523 | @query.group_by = params[:group_by] | |
531 | @query.column_names = params[:query] && params[:query][:column_names] |
|
524 | @query.column_names = params[:query] && params[:query][:column_names] | |
532 | session[:query] = {:project_id => @query.project_id, :filters => @query.filters, :group_by => @query.group_by, :column_names => @query.column_names} |
|
525 | session[:query] = {:project_id => @query.project_id, :filters => @query.filters, :group_by => @query.group_by, :column_names => @query.column_names} | |
533 | else |
|
526 | else | |
534 | @query = Query.find_by_id(session[:query][:id]) if session[:query][:id] |
|
527 | @query = Query.find_by_id(session[:query][:id]) if session[:query][:id] | |
535 | @query ||= Query.new(:name => "_", :project => @project, :filters => session[:query][:filters], :group_by => session[:query][:group_by], :column_names => session[:query][:column_names]) |
|
528 | @query ||= Query.new(:name => "_", :project => @project, :filters => session[:query][:filters], :group_by => session[:query][:group_by], :column_names => session[:query][:column_names]) | |
536 | @query.project = @project |
|
529 | @query.project = @project | |
537 | end |
|
530 | end | |
538 | end |
|
531 | end | |
539 | end |
|
532 | end | |
540 |
|
533 | |||
541 | # Rescues an invalid query statement. Just in case... |
|
534 | # Rescues an invalid query statement. Just in case... | |
542 | def query_statement_invalid(exception) |
|
535 | def query_statement_invalid(exception) | |
543 | logger.error "Query::StatementInvalid: #{exception.message}" if logger |
|
536 | logger.error "Query::StatementInvalid: #{exception.message}" if logger | |
544 | session.delete(:query) |
|
537 | session.delete(:query) | |
545 | sort_clear |
|
538 | sort_clear | |
546 | render_error "An error occurred while executing the query and has been logged. Please report this error to your Redmine administrator." |
|
539 | render_error "An error occurred while executing the query and has been logged. Please report this error to your Redmine administrator." | |
547 | end |
|
540 | end | |
548 | end |
|
541 | end |
@@ -1,446 +1,462 | |||||
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 => 'IssuePriority', :foreign_key => 'priority_id' |
|
25 | belongs_to :priority, :class_name => 'IssuePriority', :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 :time_entries, :dependent => :delete_all |
|
29 | has_many :time_entries, :dependent => :delete_all | |
30 | has_and_belongs_to_many :changesets, :order => "#{Changeset.table_name}.committed_on ASC, #{Changeset.table_name}.id ASC" |
|
30 | has_and_belongs_to_many :changesets, :order => "#{Changeset.table_name}.committed_on ASC, #{Changeset.table_name}.id ASC" | |
31 |
|
31 | |||
32 | has_many :relations_from, :class_name => 'IssueRelation', :foreign_key => 'issue_from_id', :dependent => :delete_all |
|
32 | has_many :relations_from, :class_name => 'IssueRelation', :foreign_key => 'issue_from_id', :dependent => :delete_all | |
33 | has_many :relations_to, :class_name => 'IssueRelation', :foreign_key => 'issue_to_id', :dependent => :delete_all |
|
33 | has_many :relations_to, :class_name => 'IssueRelation', :foreign_key => 'issue_to_id', :dependent => :delete_all | |
34 |
|
34 | |||
35 | acts_as_attachable :after_remove => :attachment_removed |
|
35 | acts_as_attachable :after_remove => :attachment_removed | |
36 | acts_as_customizable |
|
36 | acts_as_customizable | |
37 | acts_as_watchable |
|
37 | acts_as_watchable | |
38 | acts_as_searchable :columns => ['subject', "#{table_name}.description", "#{Journal.table_name}.notes"], |
|
38 | acts_as_searchable :columns => ['subject', "#{table_name}.description", "#{Journal.table_name}.notes"], | |
39 | :include => [:project, :journals], |
|
39 | :include => [:project, :journals], | |
40 | # sort by id so that limited eager loading doesn't break with postgresql |
|
40 | # sort by id so that limited eager loading doesn't break with postgresql | |
41 | :order_column => "#{table_name}.id" |
|
41 | :order_column => "#{table_name}.id" | |
42 | acts_as_event :title => Proc.new {|o| "#{o.tracker.name} ##{o.id} (#{o.status}): #{o.subject}"}, |
|
42 | acts_as_event :title => Proc.new {|o| "#{o.tracker.name} ##{o.id} (#{o.status}): #{o.subject}"}, | |
43 | :url => Proc.new {|o| {:controller => 'issues', :action => 'show', :id => o.id}}, |
|
43 | :url => Proc.new {|o| {:controller => 'issues', :action => 'show', :id => o.id}}, | |
44 | :type => Proc.new {|o| 'issue' + (o.closed? ? ' closed' : '') } |
|
44 | :type => Proc.new {|o| 'issue' + (o.closed? ? ' closed' : '') } | |
45 |
|
45 | |||
46 | acts_as_activity_provider :find_options => {:include => [:project, :author, :tracker]}, |
|
46 | acts_as_activity_provider :find_options => {:include => [:project, :author, :tracker]}, | |
47 | :author_key => :author_id |
|
47 | :author_key => :author_id | |
48 |
|
48 | |||
49 | DONE_RATIO_OPTIONS = %w(issue_field issue_status) |
|
49 | DONE_RATIO_OPTIONS = %w(issue_field issue_status) | |
50 |
|
50 | |||
51 | validates_presence_of :subject, :priority, :project, :tracker, :author, :status |
|
51 | validates_presence_of :subject, :priority, :project, :tracker, :author, :status | |
52 | validates_length_of :subject, :maximum => 255 |
|
52 | validates_length_of :subject, :maximum => 255 | |
53 | validates_inclusion_of :done_ratio, :in => 0..100 |
|
53 | validates_inclusion_of :done_ratio, :in => 0..100 | |
54 | validates_numericality_of :estimated_hours, :allow_nil => true |
|
54 | validates_numericality_of :estimated_hours, :allow_nil => true | |
55 |
|
55 | |||
56 | named_scope :visible, lambda {|*args| { :include => :project, |
|
56 | named_scope :visible, lambda {|*args| { :include => :project, | |
57 | :conditions => Project.allowed_to_condition(args.first || User.current, :view_issues) } } |
|
57 | :conditions => Project.allowed_to_condition(args.first || User.current, :view_issues) } } | |
58 |
|
58 | |||
59 | named_scope :open, :conditions => ["#{IssueStatus.table_name}.is_closed = ?", false], :include => :status |
|
59 | named_scope :open, :conditions => ["#{IssueStatus.table_name}.is_closed = ?", false], :include => :status | |
60 |
|
60 | |||
61 | before_save :update_done_ratio_from_issue_status |
|
61 | before_save :update_done_ratio_from_issue_status | |
62 | after_save :create_journal |
|
62 | after_save :create_journal | |
63 |
|
63 | |||
64 | # Returns true if usr or current user is allowed to view the issue |
|
64 | # Returns true if usr or current user is allowed to view the issue | |
65 | def visible?(usr=nil) |
|
65 | def visible?(usr=nil) | |
66 | (usr || User.current).allowed_to?(:view_issues, self.project) |
|
66 | (usr || User.current).allowed_to?(:view_issues, self.project) | |
67 | end |
|
67 | end | |
68 |
|
68 | |||
69 | def after_initialize |
|
69 | def after_initialize | |
70 | if new_record? |
|
70 | if new_record? | |
71 | # set default values for new records only |
|
71 | # set default values for new records only | |
72 | self.status ||= IssueStatus.default |
|
72 | self.status ||= IssueStatus.default | |
73 | self.priority ||= IssuePriority.default |
|
73 | self.priority ||= IssuePriority.default | |
74 | end |
|
74 | end | |
75 | end |
|
75 | end | |
76 |
|
76 | |||
77 | # Overrides Redmine::Acts::Customizable::InstanceMethods#available_custom_fields |
|
77 | # Overrides Redmine::Acts::Customizable::InstanceMethods#available_custom_fields | |
78 | def available_custom_fields |
|
78 | def available_custom_fields | |
79 | (project && tracker) ? project.all_issue_custom_fields.select {|c| tracker.custom_fields.include? c } : [] |
|
79 | (project && tracker) ? project.all_issue_custom_fields.select {|c| tracker.custom_fields.include? c } : [] | |
80 | end |
|
80 | end | |
81 |
|
81 | |||
82 | def copy_from(arg) |
|
82 | def copy_from(arg) | |
83 | issue = arg.is_a?(Issue) ? arg : Issue.visible.find(arg) |
|
83 | issue = arg.is_a?(Issue) ? arg : Issue.visible.find(arg) | |
84 | self.attributes = issue.attributes.dup.except("id", "created_on", "updated_on") |
|
84 | self.attributes = issue.attributes.dup.except("id", "created_on", "updated_on") | |
85 | self.custom_values = issue.custom_values.collect {|v| v.clone} |
|
85 | self.custom_values = issue.custom_values.collect {|v| v.clone} | |
86 | self.status = issue.status |
|
86 | self.status = issue.status | |
87 | self |
|
87 | self | |
88 | end |
|
88 | end | |
89 |
|
89 | |||
90 | # Moves/copies an issue to a new project and tracker |
|
90 | # Moves/copies an issue to a new project and tracker | |
91 | # Returns the moved/copied issue on success, false on failure |
|
91 | # Returns the moved/copied issue on success, false on failure | |
92 | def move_to(new_project, new_tracker = nil, options = {}) |
|
92 | def move_to(new_project, new_tracker = nil, options = {}) | |
93 | options ||= {} |
|
93 | options ||= {} | |
94 | issue = options[:copy] ? self.clone : self |
|
94 | issue = options[:copy] ? self.clone : self | |
95 | ret = Issue.transaction do |
|
95 | ret = Issue.transaction do | |
96 | if new_project && issue.project_id != new_project.id |
|
96 | if new_project && issue.project_id != new_project.id | |
97 | # delete issue relations |
|
97 | # delete issue relations | |
98 | unless Setting.cross_project_issue_relations? |
|
98 | unless Setting.cross_project_issue_relations? | |
99 | issue.relations_from.clear |
|
99 | issue.relations_from.clear | |
100 | issue.relations_to.clear |
|
100 | issue.relations_to.clear | |
101 | end |
|
101 | end | |
102 | # issue is moved to another project |
|
102 | # issue is moved to another project | |
103 | # reassign to the category with same name if any |
|
103 | # reassign to the category with same name if any | |
104 | new_category = issue.category.nil? ? nil : new_project.issue_categories.find_by_name(issue.category.name) |
|
104 | new_category = issue.category.nil? ? nil : new_project.issue_categories.find_by_name(issue.category.name) | |
105 | issue.category = new_category |
|
105 | issue.category = new_category | |
106 | # Keep the fixed_version if it's still valid in the new_project |
|
106 | # Keep the fixed_version if it's still valid in the new_project | |
107 | unless new_project.shared_versions.include?(issue.fixed_version) |
|
107 | unless new_project.shared_versions.include?(issue.fixed_version) | |
108 | issue.fixed_version = nil |
|
108 | issue.fixed_version = nil | |
109 | end |
|
109 | end | |
110 | issue.project = new_project |
|
110 | issue.project = new_project | |
111 | end |
|
111 | end | |
112 | if new_tracker |
|
112 | if new_tracker | |
113 | issue.tracker = new_tracker |
|
113 | issue.tracker = new_tracker | |
114 | end |
|
114 | end | |
115 | if options[:copy] |
|
115 | if options[:copy] | |
116 | issue.custom_field_values = self.custom_field_values.inject({}) {|h,v| h[v.custom_field_id] = v.value; h} |
|
116 | issue.custom_field_values = self.custom_field_values.inject({}) {|h,v| h[v.custom_field_id] = v.value; h} | |
117 | issue.status = if options[:attributes] && options[:attributes][:status_id] |
|
117 | issue.status = if options[:attributes] && options[:attributes][:status_id] | |
118 | IssueStatus.find_by_id(options[:attributes][:status_id]) |
|
118 | IssueStatus.find_by_id(options[:attributes][:status_id]) | |
119 | else |
|
119 | else | |
120 | self.status |
|
120 | self.status | |
121 | end |
|
121 | end | |
122 | end |
|
122 | end | |
123 | # Allow bulk setting of attributes on the issue |
|
123 | # Allow bulk setting of attributes on the issue | |
124 | if options[:attributes] |
|
124 | if options[:attributes] | |
125 | issue.attributes = options[:attributes] |
|
125 | issue.attributes = options[:attributes] | |
126 | end |
|
126 | end | |
127 | if issue.save |
|
127 | if issue.save | |
128 | unless options[:copy] |
|
128 | unless options[:copy] | |
129 | # Manually update project_id on related time entries |
|
129 | # Manually update project_id on related time entries | |
130 | TimeEntry.update_all("project_id = #{new_project.id}", {:issue_id => id}) |
|
130 | TimeEntry.update_all("project_id = #{new_project.id}", {:issue_id => id}) | |
131 | end |
|
131 | end | |
132 | true |
|
132 | true | |
133 | else |
|
133 | else | |
134 | raise ActiveRecord::Rollback |
|
134 | raise ActiveRecord::Rollback | |
135 | end |
|
135 | end | |
136 | end |
|
136 | end | |
137 | ret ? issue : false |
|
137 | ret ? issue : false | |
138 | end |
|
138 | end | |
139 |
|
139 | |||
140 | def priority_id=(pid) |
|
140 | def priority_id=(pid) | |
141 | self.priority = nil |
|
141 | self.priority = nil | |
142 | write_attribute(:priority_id, pid) |
|
142 | write_attribute(:priority_id, pid) | |
143 | end |
|
143 | end | |
144 |
|
144 | |||
145 | def tracker_id=(tid) |
|
145 | def tracker_id=(tid) | |
146 | self.tracker = nil |
|
146 | self.tracker = nil | |
147 | write_attribute(:tracker_id, tid) |
|
147 | write_attribute(:tracker_id, tid) | |
148 | result = write_attribute(:tracker_id, tid) |
|
148 | result = write_attribute(:tracker_id, tid) | |
149 | @custom_field_values = nil |
|
149 | @custom_field_values = nil | |
150 | result |
|
150 | result | |
151 | end |
|
151 | end | |
152 |
|
152 | |||
153 | # Overrides attributes= so that tracker_id gets assigned first |
|
153 | # Overrides attributes= so that tracker_id gets assigned first | |
154 | def attributes_with_tracker_first=(new_attributes, *args) |
|
154 | def attributes_with_tracker_first=(new_attributes, *args) | |
155 | return if new_attributes.nil? |
|
155 | return if new_attributes.nil? | |
156 | new_tracker_id = new_attributes['tracker_id'] || new_attributes[:tracker_id] |
|
156 | new_tracker_id = new_attributes['tracker_id'] || new_attributes[:tracker_id] | |
157 | if new_tracker_id |
|
157 | if new_tracker_id | |
158 | self.tracker_id = new_tracker_id |
|
158 | self.tracker_id = new_tracker_id | |
159 | end |
|
159 | end | |
160 | send :attributes_without_tracker_first=, new_attributes, *args |
|
160 | send :attributes_without_tracker_first=, new_attributes, *args | |
161 | end |
|
161 | end | |
162 | # Do not redefine alias chain on reload (see #4838) |
|
162 | # Do not redefine alias chain on reload (see #4838) | |
163 | alias_method_chain(:attributes=, :tracker_first) unless method_defined?(:attributes_without_tracker_first=) |
|
163 | alias_method_chain(:attributes=, :tracker_first) unless method_defined?(:attributes_without_tracker_first=) | |
164 |
|
164 | |||
165 | def estimated_hours=(h) |
|
165 | def estimated_hours=(h) | |
166 | write_attribute :estimated_hours, (h.is_a?(String) ? h.to_hours : h) |
|
166 | write_attribute :estimated_hours, (h.is_a?(String) ? h.to_hours : h) | |
167 | end |
|
167 | end | |
168 |
|
168 | |||
169 | def done_ratio |
|
169 | def done_ratio | |
170 | if Issue.use_status_for_done_ratio? && status && status.default_done_ratio? |
|
170 | if Issue.use_status_for_done_ratio? && status && status.default_done_ratio? | |
171 | status.default_done_ratio |
|
171 | status.default_done_ratio | |
172 | else |
|
172 | else | |
173 | read_attribute(:done_ratio) |
|
173 | read_attribute(:done_ratio) | |
174 | end |
|
174 | end | |
175 | end |
|
175 | end | |
176 |
|
176 | |||
177 | def self.use_status_for_done_ratio? |
|
177 | def self.use_status_for_done_ratio? | |
178 | Setting.issue_done_ratio == 'issue_status' |
|
178 | Setting.issue_done_ratio == 'issue_status' | |
179 | end |
|
179 | end | |
180 |
|
180 | |||
181 | def self.use_field_for_done_ratio? |
|
181 | def self.use_field_for_done_ratio? | |
182 | Setting.issue_done_ratio == 'issue_field' |
|
182 | Setting.issue_done_ratio == 'issue_field' | |
183 | end |
|
183 | end | |
184 |
|
184 | |||
185 | def validate |
|
185 | def validate | |
186 | if self.due_date.nil? && @attributes['due_date'] && !@attributes['due_date'].empty? |
|
186 | if self.due_date.nil? && @attributes['due_date'] && !@attributes['due_date'].empty? | |
187 | errors.add :due_date, :not_a_date |
|
187 | errors.add :due_date, :not_a_date | |
188 | end |
|
188 | end | |
189 |
|
189 | |||
190 | if self.due_date and self.start_date and self.due_date < self.start_date |
|
190 | if self.due_date and self.start_date and self.due_date < self.start_date | |
191 | errors.add :due_date, :greater_than_start_date |
|
191 | errors.add :due_date, :greater_than_start_date | |
192 | end |
|
192 | end | |
193 |
|
193 | |||
194 | if start_date && soonest_start && start_date < soonest_start |
|
194 | if start_date && soonest_start && start_date < soonest_start | |
195 | errors.add :start_date, :invalid |
|
195 | errors.add :start_date, :invalid | |
196 | end |
|
196 | end | |
197 |
|
197 | |||
198 | if fixed_version |
|
198 | if fixed_version | |
199 | if !assignable_versions.include?(fixed_version) |
|
199 | if !assignable_versions.include?(fixed_version) | |
200 | errors.add :fixed_version_id, :inclusion |
|
200 | errors.add :fixed_version_id, :inclusion | |
201 | elsif reopened? && fixed_version.closed? |
|
201 | elsif reopened? && fixed_version.closed? | |
202 | errors.add_to_base I18n.t(:error_can_not_reopen_issue_on_closed_version) |
|
202 | errors.add_to_base I18n.t(:error_can_not_reopen_issue_on_closed_version) | |
203 | end |
|
203 | end | |
204 | end |
|
204 | end | |
205 |
|
205 | |||
206 | # Checks that the issue can not be added/moved to a disabled tracker |
|
206 | # Checks that the issue can not be added/moved to a disabled tracker | |
207 | if project && (tracker_id_changed? || project_id_changed?) |
|
207 | if project && (tracker_id_changed? || project_id_changed?) | |
208 | unless project.trackers.include?(tracker) |
|
208 | unless project.trackers.include?(tracker) | |
209 | errors.add :tracker_id, :inclusion |
|
209 | errors.add :tracker_id, :inclusion | |
210 | end |
|
210 | end | |
211 | end |
|
211 | end | |
212 | end |
|
212 | end | |
213 |
|
213 | |||
214 | def before_create |
|
214 | def before_create | |
215 | # default assignment based on category |
|
215 | # default assignment based on category | |
216 | if assigned_to.nil? && category && category.assigned_to |
|
216 | if assigned_to.nil? && category && category.assigned_to | |
217 | self.assigned_to = category.assigned_to |
|
217 | self.assigned_to = category.assigned_to | |
218 | end |
|
218 | end | |
219 | end |
|
219 | end | |
220 |
|
220 | |||
221 | # Set the done_ratio using the status if that setting is set. This will keep the done_ratios |
|
221 | # Set the done_ratio using the status if that setting is set. This will keep the done_ratios | |
222 | # even if the user turns off the setting later |
|
222 | # even if the user turns off the setting later | |
223 | def update_done_ratio_from_issue_status |
|
223 | def update_done_ratio_from_issue_status | |
224 | if Issue.use_status_for_done_ratio? && status && status.default_done_ratio? |
|
224 | if Issue.use_status_for_done_ratio? && status && status.default_done_ratio? | |
225 | self.done_ratio = status.default_done_ratio |
|
225 | self.done_ratio = status.default_done_ratio | |
226 | end |
|
226 | end | |
227 | end |
|
227 | end | |
228 |
|
228 | |||
229 | def after_save |
|
229 | def after_save | |
230 | # Reload is needed in order to get the right status |
|
230 | # Reload is needed in order to get the right status | |
231 | reload |
|
231 | reload | |
232 |
|
232 | |||
233 | # Update start/due dates of following issues |
|
233 | # Update start/due dates of following issues | |
234 | relations_from.each(&:set_issue_to_dates) |
|
234 | relations_from.each(&:set_issue_to_dates) | |
235 |
|
235 | |||
236 | # Close duplicates if the issue was closed |
|
236 | # Close duplicates if the issue was closed | |
237 | if @issue_before_change && !@issue_before_change.closed? && self.closed? |
|
237 | if @issue_before_change && !@issue_before_change.closed? && self.closed? | |
238 | duplicates.each do |duplicate| |
|
238 | duplicates.each do |duplicate| | |
239 | # Reload is need in case the duplicate was updated by a previous duplicate |
|
239 | # Reload is need in case the duplicate was updated by a previous duplicate | |
240 | duplicate.reload |
|
240 | duplicate.reload | |
241 | # Don't re-close it if it's already closed |
|
241 | # Don't re-close it if it's already closed | |
242 | next if duplicate.closed? |
|
242 | next if duplicate.closed? | |
243 | # Same user and notes |
|
243 | # Same user and notes | |
244 | duplicate.init_journal(@current_journal.user, @current_journal.notes) |
|
244 | duplicate.init_journal(@current_journal.user, @current_journal.notes) | |
245 | duplicate.update_attribute :status, self.status |
|
245 | duplicate.update_attribute :status, self.status | |
246 | end |
|
246 | end | |
247 | end |
|
247 | end | |
248 | end |
|
248 | end | |
249 |
|
249 | |||
250 | def init_journal(user, notes = "") |
|
250 | def init_journal(user, notes = "") | |
251 | @current_journal ||= Journal.new(:journalized => self, :user => user, :notes => notes) |
|
251 | @current_journal ||= Journal.new(:journalized => self, :user => user, :notes => notes) | |
252 | @issue_before_change = self.clone |
|
252 | @issue_before_change = self.clone | |
253 | @issue_before_change.status = self.status |
|
253 | @issue_before_change.status = self.status | |
254 | @custom_values_before_change = {} |
|
254 | @custom_values_before_change = {} | |
255 | self.custom_values.each {|c| @custom_values_before_change.store c.custom_field_id, c.value } |
|
255 | self.custom_values.each {|c| @custom_values_before_change.store c.custom_field_id, c.value } | |
256 | # Make sure updated_on is updated when adding a note. |
|
256 | # Make sure updated_on is updated when adding a note. | |
257 | updated_on_will_change! |
|
257 | updated_on_will_change! | |
258 | @current_journal |
|
258 | @current_journal | |
259 | end |
|
259 | end | |
260 |
|
260 | |||
261 | # Return true if the issue is closed, otherwise false |
|
261 | # Return true if the issue is closed, otherwise false | |
262 | def closed? |
|
262 | def closed? | |
263 | self.status.is_closed? |
|
263 | self.status.is_closed? | |
264 | end |
|
264 | end | |
265 |
|
265 | |||
266 | # Return true if the issue is being reopened |
|
266 | # Return true if the issue is being reopened | |
267 | def reopened? |
|
267 | def reopened? | |
268 | if !new_record? && status_id_changed? |
|
268 | if !new_record? && status_id_changed? | |
269 | status_was = IssueStatus.find_by_id(status_id_was) |
|
269 | status_was = IssueStatus.find_by_id(status_id_was) | |
270 | status_new = IssueStatus.find_by_id(status_id) |
|
270 | status_new = IssueStatus.find_by_id(status_id) | |
271 | if status_was && status_new && status_was.is_closed? && !status_new.is_closed? |
|
271 | if status_was && status_new && status_was.is_closed? && !status_new.is_closed? | |
272 | return true |
|
272 | return true | |
273 | end |
|
273 | end | |
274 | end |
|
274 | end | |
275 | false |
|
275 | false | |
276 | end |
|
276 | end | |
277 |
|
277 | |||
278 | # Returns true if the issue is overdue |
|
278 | # Returns true if the issue is overdue | |
279 | def overdue? |
|
279 | def overdue? | |
280 | !due_date.nil? && (due_date < Date.today) && !status.is_closed? |
|
280 | !due_date.nil? && (due_date < Date.today) && !status.is_closed? | |
281 | end |
|
281 | end | |
282 |
|
282 | |||
283 | # Users the issue can be assigned to |
|
283 | # Users the issue can be assigned to | |
284 | def assignable_users |
|
284 | def assignable_users | |
285 | project.assignable_users |
|
285 | project.assignable_users | |
286 | end |
|
286 | end | |
287 |
|
287 | |||
288 | # Versions that the issue can be assigned to |
|
288 | # Versions that the issue can be assigned to | |
289 | def assignable_versions |
|
289 | def assignable_versions | |
290 | @assignable_versions ||= (project.shared_versions.open + [Version.find_by_id(fixed_version_id_was)]).compact.uniq.sort |
|
290 | @assignable_versions ||= (project.shared_versions.open + [Version.find_by_id(fixed_version_id_was)]).compact.uniq.sort | |
291 | end |
|
291 | end | |
292 |
|
292 | |||
293 | # Returns true if this issue is blocked by another issue that is still open |
|
293 | # Returns true if this issue is blocked by another issue that is still open | |
294 | def blocked? |
|
294 | def blocked? | |
295 | !relations_to.detect {|ir| ir.relation_type == 'blocks' && !ir.issue_from.closed?}.nil? |
|
295 | !relations_to.detect {|ir| ir.relation_type == 'blocks' && !ir.issue_from.closed?}.nil? | |
296 | end |
|
296 | end | |
297 |
|
297 | |||
298 | # Returns an array of status that user is able to apply |
|
298 | # Returns an array of status that user is able to apply | |
299 | def new_statuses_allowed_to(user) |
|
299 | def new_statuses_allowed_to(user) | |
300 | statuses = status.find_new_statuses_allowed_to(user.roles_for_project(project), tracker) |
|
300 | statuses = status.find_new_statuses_allowed_to(user.roles_for_project(project), tracker) | |
301 | statuses << status unless statuses.empty? |
|
301 | statuses << status unless statuses.empty? | |
302 | statuses = statuses.uniq.sort |
|
302 | statuses = statuses.uniq.sort | |
303 | blocked? ? statuses.reject {|s| s.is_closed?} : statuses |
|
303 | blocked? ? statuses.reject {|s| s.is_closed?} : statuses | |
304 | end |
|
304 | end | |
305 |
|
305 | |||
306 | # Returns the mail adresses of users that should be notified |
|
306 | # Returns the mail adresses of users that should be notified | |
307 | def recipients |
|
307 | def recipients | |
308 | notified = project.notified_users |
|
308 | notified = project.notified_users | |
309 | # Author and assignee are always notified unless they have been locked |
|
309 | # Author and assignee are always notified unless they have been locked | |
310 | notified << author if author && author.active? |
|
310 | notified << author if author && author.active? | |
311 | notified << assigned_to if assigned_to && assigned_to.active? |
|
311 | notified << assigned_to if assigned_to && assigned_to.active? | |
312 | notified.uniq! |
|
312 | notified.uniq! | |
313 | # Remove users that can not view the issue |
|
313 | # Remove users that can not view the issue | |
314 | notified.reject! {|user| !visible?(user)} |
|
314 | notified.reject! {|user| !visible?(user)} | |
315 | notified.collect(&:mail) |
|
315 | notified.collect(&:mail) | |
316 | end |
|
316 | end | |
317 |
|
317 | |||
318 | # Returns the total number of hours spent on this issue. |
|
318 | # Returns the total number of hours spent on this issue. | |
319 | # |
|
319 | # | |
320 | # Example: |
|
320 | # Example: | |
321 | # spent_hours => 0 |
|
321 | # spent_hours => 0 | |
322 | # spent_hours => 50 |
|
322 | # spent_hours => 50 | |
323 | def spent_hours |
|
323 | def spent_hours | |
324 | @spent_hours ||= time_entries.sum(:hours) || 0 |
|
324 | @spent_hours ||= time_entries.sum(:hours) || 0 | |
325 | end |
|
325 | end | |
326 |
|
326 | |||
327 | def relations |
|
327 | def relations | |
328 | (relations_from + relations_to).sort |
|
328 | (relations_from + relations_to).sort | |
329 | end |
|
329 | end | |
330 |
|
330 | |||
331 | def all_dependent_issues |
|
331 | def all_dependent_issues | |
332 | dependencies = [] |
|
332 | dependencies = [] | |
333 | relations_from.each do |relation| |
|
333 | relations_from.each do |relation| | |
334 | dependencies << relation.issue_to |
|
334 | dependencies << relation.issue_to | |
335 | dependencies += relation.issue_to.all_dependent_issues |
|
335 | dependencies += relation.issue_to.all_dependent_issues | |
336 | end |
|
336 | end | |
337 | dependencies |
|
337 | dependencies | |
338 | end |
|
338 | end | |
339 |
|
339 | |||
340 | # Returns an array of issues that duplicate this one |
|
340 | # Returns an array of issues that duplicate this one | |
341 | def duplicates |
|
341 | def duplicates | |
342 | relations_to.select {|r| r.relation_type == IssueRelation::TYPE_DUPLICATES}.collect {|r| r.issue_from} |
|
342 | relations_to.select {|r| r.relation_type == IssueRelation::TYPE_DUPLICATES}.collect {|r| r.issue_from} | |
343 | end |
|
343 | end | |
344 |
|
344 | |||
345 | # Returns the due date or the target due date if any |
|
345 | # Returns the due date or the target due date if any | |
346 | # Used on gantt chart |
|
346 | # Used on gantt chart | |
347 | def due_before |
|
347 | def due_before | |
348 | due_date || (fixed_version ? fixed_version.effective_date : nil) |
|
348 | due_date || (fixed_version ? fixed_version.effective_date : nil) | |
349 | end |
|
349 | end | |
350 |
|
350 | |||
351 | # Returns the time scheduled for this issue. |
|
351 | # Returns the time scheduled for this issue. | |
352 | # |
|
352 | # | |
353 | # Example: |
|
353 | # Example: | |
354 | # Start Date: 2/26/09, End Date: 3/04/09 |
|
354 | # Start Date: 2/26/09, End Date: 3/04/09 | |
355 | # duration => 6 |
|
355 | # duration => 6 | |
356 | def duration |
|
356 | def duration | |
357 | (start_date && due_date) ? due_date - start_date : 0 |
|
357 | (start_date && due_date) ? due_date - start_date : 0 | |
358 | end |
|
358 | end | |
359 |
|
359 | |||
360 | def soonest_start |
|
360 | def soonest_start | |
361 | @soonest_start ||= relations_to.collect{|relation| relation.successor_soonest_start}.compact.min |
|
361 | @soonest_start ||= relations_to.collect{|relation| relation.successor_soonest_start}.compact.min | |
362 | end |
|
362 | end | |
363 |
|
363 | |||
364 | def to_s |
|
364 | def to_s | |
365 | "#{tracker} ##{id}: #{subject}" |
|
365 | "#{tracker} ##{id}: #{subject}" | |
366 | end |
|
366 | end | |
367 |
|
367 | |||
368 | # Returns a string of css classes that apply to the issue |
|
368 | # Returns a string of css classes that apply to the issue | |
369 | def css_classes |
|
369 | def css_classes | |
370 | s = "issue status-#{status.position} priority-#{priority.position}" |
|
370 | s = "issue status-#{status.position} priority-#{priority.position}" | |
371 | s << ' closed' if closed? |
|
371 | s << ' closed' if closed? | |
372 | s << ' overdue' if overdue? |
|
372 | s << ' overdue' if overdue? | |
373 | s << ' created-by-me' if User.current.logged? && author_id == User.current.id |
|
373 | s << ' created-by-me' if User.current.logged? && author_id == User.current.id | |
374 | s << ' assigned-to-me' if User.current.logged? && assigned_to_id == User.current.id |
|
374 | s << ' assigned-to-me' if User.current.logged? && assigned_to_id == User.current.id | |
375 | s |
|
375 | s | |
376 | end |
|
376 | end | |
377 |
|
377 | |||
378 | # Unassigns issues from +version+ if it's no longer shared with issue's project |
|
378 | # Unassigns issues from +version+ if it's no longer shared with issue's project | |
379 | def self.update_versions_from_sharing_change(version) |
|
379 | def self.update_versions_from_sharing_change(version) | |
380 | # Update issues assigned to the version |
|
380 | # Update issues assigned to the version | |
381 | update_versions(["#{Issue.table_name}.fixed_version_id = ?", version.id]) |
|
381 | update_versions(["#{Issue.table_name}.fixed_version_id = ?", version.id]) | |
382 | end |
|
382 | end | |
383 |
|
383 | |||
384 | # Unassigns issues from versions that are no longer shared |
|
384 | # Unassigns issues from versions that are no longer shared | |
385 | # after +project+ was moved |
|
385 | # after +project+ was moved | |
386 | def self.update_versions_from_hierarchy_change(project) |
|
386 | def self.update_versions_from_hierarchy_change(project) | |
387 | moved_project_ids = project.self_and_descendants.reload.collect(&:id) |
|
387 | moved_project_ids = project.self_and_descendants.reload.collect(&:id) | |
388 | # Update issues of the moved projects and issues assigned to a version of a moved project |
|
388 | # Update issues of the moved projects and issues assigned to a version of a moved project | |
389 | Issue.update_versions(["#{Version.table_name}.project_id IN (?) OR #{Issue.table_name}.project_id IN (?)", moved_project_ids, moved_project_ids]) |
|
389 | Issue.update_versions(["#{Version.table_name}.project_id IN (?) OR #{Issue.table_name}.project_id IN (?)", moved_project_ids, moved_project_ids]) | |
390 | end |
|
390 | end | |
391 |
|
391 | |||
|
392 | # Returns an array of projects that current user can move issues to | |||
|
393 | def self.allowed_target_projects_on_move | |||
|
394 | projects = [] | |||
|
395 | if User.current.admin? | |||
|
396 | # admin is allowed to move issues to any active (visible) project | |||
|
397 | projects = Project.visible.all | |||
|
398 | elsif User.current.logged? | |||
|
399 | if Role.non_member.allowed_to?(:move_issues) | |||
|
400 | projects = Project.visible.all | |||
|
401 | else | |||
|
402 | User.current.memberships.each {|m| projects << m.project if m.roles.detect {|r| r.allowed_to?(:move_issues)}} | |||
|
403 | end | |||
|
404 | end | |||
|
405 | projects | |||
|
406 | end | |||
|
407 | ||||
392 | private |
|
408 | private | |
393 |
|
409 | |||
394 | # Update issues so their versions are not pointing to a |
|
410 | # Update issues so their versions are not pointing to a | |
395 | # fixed_version that is not shared with the issue's project |
|
411 | # fixed_version that is not shared with the issue's project | |
396 | def self.update_versions(conditions=nil) |
|
412 | def self.update_versions(conditions=nil) | |
397 | # Only need to update issues with a fixed_version from |
|
413 | # Only need to update issues with a fixed_version from | |
398 | # a different project and that is not systemwide shared |
|
414 | # a different project and that is not systemwide shared | |
399 | Issue.all(:conditions => merge_conditions("#{Issue.table_name}.fixed_version_id IS NOT NULL" + |
|
415 | Issue.all(:conditions => merge_conditions("#{Issue.table_name}.fixed_version_id IS NOT NULL" + | |
400 | " AND #{Issue.table_name}.project_id <> #{Version.table_name}.project_id" + |
|
416 | " AND #{Issue.table_name}.project_id <> #{Version.table_name}.project_id" + | |
401 | " AND #{Version.table_name}.sharing <> 'system'", |
|
417 | " AND #{Version.table_name}.sharing <> 'system'", | |
402 | conditions), |
|
418 | conditions), | |
403 | :include => [:project, :fixed_version] |
|
419 | :include => [:project, :fixed_version] | |
404 | ).each do |issue| |
|
420 | ).each do |issue| | |
405 | next if issue.project.nil? || issue.fixed_version.nil? |
|
421 | next if issue.project.nil? || issue.fixed_version.nil? | |
406 | unless issue.project.shared_versions.include?(issue.fixed_version) |
|
422 | unless issue.project.shared_versions.include?(issue.fixed_version) | |
407 | issue.init_journal(User.current) |
|
423 | issue.init_journal(User.current) | |
408 | issue.fixed_version = nil |
|
424 | issue.fixed_version = nil | |
409 | issue.save |
|
425 | issue.save | |
410 | end |
|
426 | end | |
411 | end |
|
427 | end | |
412 | end |
|
428 | end | |
413 |
|
429 | |||
414 | # Callback on attachment deletion |
|
430 | # Callback on attachment deletion | |
415 | def attachment_removed(obj) |
|
431 | def attachment_removed(obj) | |
416 | journal = init_journal(User.current) |
|
432 | journal = init_journal(User.current) | |
417 | journal.details << JournalDetail.new(:property => 'attachment', |
|
433 | journal.details << JournalDetail.new(:property => 'attachment', | |
418 | :prop_key => obj.id, |
|
434 | :prop_key => obj.id, | |
419 | :old_value => obj.filename) |
|
435 | :old_value => obj.filename) | |
420 | journal.save |
|
436 | journal.save | |
421 | end |
|
437 | end | |
422 |
|
438 | |||
423 | # Saves the changes in a Journal |
|
439 | # Saves the changes in a Journal | |
424 | # Called after_save |
|
440 | # Called after_save | |
425 | def create_journal |
|
441 | def create_journal | |
426 | if @current_journal |
|
442 | if @current_journal | |
427 | # attributes changes |
|
443 | # attributes changes | |
428 | (Issue.column_names - %w(id description lock_version created_on updated_on)).each {|c| |
|
444 | (Issue.column_names - %w(id description lock_version created_on updated_on)).each {|c| | |
429 | @current_journal.details << JournalDetail.new(:property => 'attr', |
|
445 | @current_journal.details << JournalDetail.new(:property => 'attr', | |
430 | :prop_key => c, |
|
446 | :prop_key => c, | |
431 | :old_value => @issue_before_change.send(c), |
|
447 | :old_value => @issue_before_change.send(c), | |
432 | :value => send(c)) unless send(c)==@issue_before_change.send(c) |
|
448 | :value => send(c)) unless send(c)==@issue_before_change.send(c) | |
433 | } |
|
449 | } | |
434 | # custom fields changes |
|
450 | # custom fields changes | |
435 | custom_values.each {|c| |
|
451 | custom_values.each {|c| | |
436 | next if (@custom_values_before_change[c.custom_field_id]==c.value || |
|
452 | next if (@custom_values_before_change[c.custom_field_id]==c.value || | |
437 | (@custom_values_before_change[c.custom_field_id].blank? && c.value.blank?)) |
|
453 | (@custom_values_before_change[c.custom_field_id].blank? && c.value.blank?)) | |
438 | @current_journal.details << JournalDetail.new(:property => 'cf', |
|
454 | @current_journal.details << JournalDetail.new(:property => 'cf', | |
439 | :prop_key => c.custom_field_id, |
|
455 | :prop_key => c.custom_field_id, | |
440 | :old_value => @custom_values_before_change[c.custom_field_id], |
|
456 | :old_value => @custom_values_before_change[c.custom_field_id], | |
441 | :value => c.value) |
|
457 | :value => c.value) | |
442 | } |
|
458 | } | |
443 | @current_journal.save |
|
459 | @current_journal.save | |
444 | end |
|
460 | end | |
445 | end |
|
461 | end | |
446 | end |
|
462 | end |
@@ -1,602 +1,618 | |||||
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 < ActiveSupport::TestCase |
|
20 | class IssueTest < ActiveSupport::TestCase | |
21 | fixtures :projects, :users, :members, :member_roles, :roles, |
|
21 | fixtures :projects, :users, :members, :member_roles, :roles, | |
22 | :trackers, :projects_trackers, |
|
22 | :trackers, :projects_trackers, | |
23 | :versions, |
|
23 | :versions, | |
24 | :issue_statuses, :issue_categories, :issue_relations, :workflows, |
|
24 | :issue_statuses, :issue_categories, :issue_relations, :workflows, | |
25 | :enumerations, |
|
25 | :enumerations, | |
26 | :issues, |
|
26 | :issues, | |
27 | :custom_fields, :custom_fields_projects, :custom_fields_trackers, :custom_values, |
|
27 | :custom_fields, :custom_fields_projects, :custom_fields_trackers, :custom_values, | |
28 | :time_entries |
|
28 | :time_entries | |
29 |
|
29 | |||
30 | def test_create |
|
30 | def test_create | |
31 | issue = Issue.new(:project_id => 1, :tracker_id => 1, :author_id => 3, :status_id => 1, :priority => IssuePriority.all.first, :subject => 'test_create', :description => 'IssueTest#test_create', :estimated_hours => '1:30') |
|
31 | issue = Issue.new(:project_id => 1, :tracker_id => 1, :author_id => 3, :status_id => 1, :priority => IssuePriority.all.first, :subject => 'test_create', :description => 'IssueTest#test_create', :estimated_hours => '1:30') | |
32 | assert issue.save |
|
32 | assert issue.save | |
33 | issue.reload |
|
33 | issue.reload | |
34 | assert_equal 1.5, issue.estimated_hours |
|
34 | assert_equal 1.5, issue.estimated_hours | |
35 | end |
|
35 | end | |
36 |
|
36 | |||
37 | def test_create_minimal |
|
37 | def test_create_minimal | |
38 | issue = Issue.new(:project_id => 1, :tracker_id => 1, :author_id => 3, :status_id => 1, :priority => IssuePriority.all.first, :subject => 'test_create') |
|
38 | issue = Issue.new(:project_id => 1, :tracker_id => 1, :author_id => 3, :status_id => 1, :priority => IssuePriority.all.first, :subject => 'test_create') | |
39 | assert issue.save |
|
39 | assert issue.save | |
40 | assert issue.description.nil? |
|
40 | assert issue.description.nil? | |
41 | end |
|
41 | end | |
42 |
|
42 | |||
43 | def test_create_with_required_custom_field |
|
43 | def test_create_with_required_custom_field | |
44 | field = IssueCustomField.find_by_name('Database') |
|
44 | field = IssueCustomField.find_by_name('Database') | |
45 | field.update_attribute(:is_required, true) |
|
45 | field.update_attribute(:is_required, true) | |
46 |
|
46 | |||
47 | issue = Issue.new(:project_id => 1, :tracker_id => 1, :author_id => 1, :status_id => 1, :subject => 'test_create', :description => 'IssueTest#test_create_with_required_custom_field') |
|
47 | issue = Issue.new(:project_id => 1, :tracker_id => 1, :author_id => 1, :status_id => 1, :subject => 'test_create', :description => 'IssueTest#test_create_with_required_custom_field') | |
48 | assert issue.available_custom_fields.include?(field) |
|
48 | assert issue.available_custom_fields.include?(field) | |
49 | # No value for the custom field |
|
49 | # No value for the custom field | |
50 | assert !issue.save |
|
50 | assert !issue.save | |
51 | assert_equal I18n.translate('activerecord.errors.messages.invalid'), issue.errors.on(:custom_values) |
|
51 | assert_equal I18n.translate('activerecord.errors.messages.invalid'), issue.errors.on(:custom_values) | |
52 | # Blank value |
|
52 | # Blank value | |
53 | issue.custom_field_values = { field.id => '' } |
|
53 | issue.custom_field_values = { field.id => '' } | |
54 | assert !issue.save |
|
54 | assert !issue.save | |
55 | assert_equal I18n.translate('activerecord.errors.messages.invalid'), issue.errors.on(:custom_values) |
|
55 | assert_equal I18n.translate('activerecord.errors.messages.invalid'), issue.errors.on(:custom_values) | |
56 | # Invalid value |
|
56 | # Invalid value | |
57 | issue.custom_field_values = { field.id => 'SQLServer' } |
|
57 | issue.custom_field_values = { field.id => 'SQLServer' } | |
58 | assert !issue.save |
|
58 | assert !issue.save | |
59 | assert_equal I18n.translate('activerecord.errors.messages.invalid'), issue.errors.on(:custom_values) |
|
59 | assert_equal I18n.translate('activerecord.errors.messages.invalid'), issue.errors.on(:custom_values) | |
60 | # Valid value |
|
60 | # Valid value | |
61 | issue.custom_field_values = { field.id => 'PostgreSQL' } |
|
61 | issue.custom_field_values = { field.id => 'PostgreSQL' } | |
62 | assert issue.save |
|
62 | assert issue.save | |
63 | issue.reload |
|
63 | issue.reload | |
64 | assert_equal 'PostgreSQL', issue.custom_value_for(field).value |
|
64 | assert_equal 'PostgreSQL', issue.custom_value_for(field).value | |
65 | end |
|
65 | end | |
66 |
|
66 | |||
67 | def test_visible_scope_for_anonymous |
|
67 | def test_visible_scope_for_anonymous | |
68 | # Anonymous user should see issues of public projects only |
|
68 | # Anonymous user should see issues of public projects only | |
69 | issues = Issue.visible(User.anonymous).all |
|
69 | issues = Issue.visible(User.anonymous).all | |
70 | assert issues.any? |
|
70 | assert issues.any? | |
71 | assert_nil issues.detect {|issue| !issue.project.is_public?} |
|
71 | assert_nil issues.detect {|issue| !issue.project.is_public?} | |
72 | # Anonymous user should not see issues without permission |
|
72 | # Anonymous user should not see issues without permission | |
73 | Role.anonymous.remove_permission!(:view_issues) |
|
73 | Role.anonymous.remove_permission!(:view_issues) | |
74 | issues = Issue.visible(User.anonymous).all |
|
74 | issues = Issue.visible(User.anonymous).all | |
75 | assert issues.empty? |
|
75 | assert issues.empty? | |
76 | end |
|
76 | end | |
77 |
|
77 | |||
78 | def test_visible_scope_for_user |
|
78 | def test_visible_scope_for_user | |
79 | user = User.find(9) |
|
79 | user = User.find(9) | |
80 | assert user.projects.empty? |
|
80 | assert user.projects.empty? | |
81 | # Non member user should see issues of public projects only |
|
81 | # Non member user should see issues of public projects only | |
82 | issues = Issue.visible(user).all |
|
82 | issues = Issue.visible(user).all | |
83 | assert issues.any? |
|
83 | assert issues.any? | |
84 | assert_nil issues.detect {|issue| !issue.project.is_public?} |
|
84 | assert_nil issues.detect {|issue| !issue.project.is_public?} | |
85 | # Non member user should not see issues without permission |
|
85 | # Non member user should not see issues without permission | |
86 | Role.non_member.remove_permission!(:view_issues) |
|
86 | Role.non_member.remove_permission!(:view_issues) | |
87 | user.reload |
|
87 | user.reload | |
88 | issues = Issue.visible(user).all |
|
88 | issues = Issue.visible(user).all | |
89 | assert issues.empty? |
|
89 | assert issues.empty? | |
90 | # User should see issues of projects for which he has view_issues permissions only |
|
90 | # User should see issues of projects for which he has view_issues permissions only | |
91 | Member.create!(:principal => user, :project_id => 2, :role_ids => [1]) |
|
91 | Member.create!(:principal => user, :project_id => 2, :role_ids => [1]) | |
92 | user.reload |
|
92 | user.reload | |
93 | issues = Issue.visible(user).all |
|
93 | issues = Issue.visible(user).all | |
94 | assert issues.any? |
|
94 | assert issues.any? | |
95 | assert_nil issues.detect {|issue| issue.project_id != 2} |
|
95 | assert_nil issues.detect {|issue| issue.project_id != 2} | |
96 | end |
|
96 | end | |
97 |
|
97 | |||
98 | def test_visible_scope_for_admin |
|
98 | def test_visible_scope_for_admin | |
99 | user = User.find(1) |
|
99 | user = User.find(1) | |
100 | user.members.each(&:destroy) |
|
100 | user.members.each(&:destroy) | |
101 | assert user.projects.empty? |
|
101 | assert user.projects.empty? | |
102 | issues = Issue.visible(user).all |
|
102 | issues = Issue.visible(user).all | |
103 | assert issues.any? |
|
103 | assert issues.any? | |
104 | # Admin should see issues on private projects that he does not belong to |
|
104 | # Admin should see issues on private projects that he does not belong to | |
105 | assert issues.detect {|issue| !issue.project.is_public?} |
|
105 | assert issues.detect {|issue| !issue.project.is_public?} | |
106 | end |
|
106 | end | |
107 |
|
107 | |||
108 | def test_errors_full_messages_should_include_custom_fields_errors |
|
108 | def test_errors_full_messages_should_include_custom_fields_errors | |
109 | field = IssueCustomField.find_by_name('Database') |
|
109 | field = IssueCustomField.find_by_name('Database') | |
110 |
|
110 | |||
111 | issue = Issue.new(:project_id => 1, :tracker_id => 1, :author_id => 1, :status_id => 1, :subject => 'test_create', :description => 'IssueTest#test_create_with_required_custom_field') |
|
111 | issue = Issue.new(:project_id => 1, :tracker_id => 1, :author_id => 1, :status_id => 1, :subject => 'test_create', :description => 'IssueTest#test_create_with_required_custom_field') | |
112 | assert issue.available_custom_fields.include?(field) |
|
112 | assert issue.available_custom_fields.include?(field) | |
113 | # Invalid value |
|
113 | # Invalid value | |
114 | issue.custom_field_values = { field.id => 'SQLServer' } |
|
114 | issue.custom_field_values = { field.id => 'SQLServer' } | |
115 |
|
115 | |||
116 | assert !issue.valid? |
|
116 | assert !issue.valid? | |
117 | assert_equal 1, issue.errors.full_messages.size |
|
117 | assert_equal 1, issue.errors.full_messages.size | |
118 | assert_equal "Database #{I18n.translate('activerecord.errors.messages.inclusion')}", issue.errors.full_messages.first |
|
118 | assert_equal "Database #{I18n.translate('activerecord.errors.messages.inclusion')}", issue.errors.full_messages.first | |
119 | end |
|
119 | end | |
120 |
|
120 | |||
121 | def test_update_issue_with_required_custom_field |
|
121 | def test_update_issue_with_required_custom_field | |
122 | field = IssueCustomField.find_by_name('Database') |
|
122 | field = IssueCustomField.find_by_name('Database') | |
123 | field.update_attribute(:is_required, true) |
|
123 | field.update_attribute(:is_required, true) | |
124 |
|
124 | |||
125 | issue = Issue.find(1) |
|
125 | issue = Issue.find(1) | |
126 | assert_nil issue.custom_value_for(field) |
|
126 | assert_nil issue.custom_value_for(field) | |
127 | assert issue.available_custom_fields.include?(field) |
|
127 | assert issue.available_custom_fields.include?(field) | |
128 | # No change to custom values, issue can be saved |
|
128 | # No change to custom values, issue can be saved | |
129 | assert issue.save |
|
129 | assert issue.save | |
130 | # Blank value |
|
130 | # Blank value | |
131 | issue.custom_field_values = { field.id => '' } |
|
131 | issue.custom_field_values = { field.id => '' } | |
132 | assert !issue.save |
|
132 | assert !issue.save | |
133 | # Valid value |
|
133 | # Valid value | |
134 | issue.custom_field_values = { field.id => 'PostgreSQL' } |
|
134 | issue.custom_field_values = { field.id => 'PostgreSQL' } | |
135 | assert issue.save |
|
135 | assert issue.save | |
136 | issue.reload |
|
136 | issue.reload | |
137 | assert_equal 'PostgreSQL', issue.custom_value_for(field).value |
|
137 | assert_equal 'PostgreSQL', issue.custom_value_for(field).value | |
138 | end |
|
138 | end | |
139 |
|
139 | |||
140 | def test_should_not_update_attributes_if_custom_fields_validation_fails |
|
140 | def test_should_not_update_attributes_if_custom_fields_validation_fails | |
141 | issue = Issue.find(1) |
|
141 | issue = Issue.find(1) | |
142 | field = IssueCustomField.find_by_name('Database') |
|
142 | field = IssueCustomField.find_by_name('Database') | |
143 | assert issue.available_custom_fields.include?(field) |
|
143 | assert issue.available_custom_fields.include?(field) | |
144 |
|
144 | |||
145 | issue.custom_field_values = { field.id => 'Invalid' } |
|
145 | issue.custom_field_values = { field.id => 'Invalid' } | |
146 | issue.subject = 'Should be not be saved' |
|
146 | issue.subject = 'Should be not be saved' | |
147 | assert !issue.save |
|
147 | assert !issue.save | |
148 |
|
148 | |||
149 | issue.reload |
|
149 | issue.reload | |
150 | assert_equal "Can't print recipes", issue.subject |
|
150 | assert_equal "Can't print recipes", issue.subject | |
151 | end |
|
151 | end | |
152 |
|
152 | |||
153 | def test_should_not_recreate_custom_values_objects_on_update |
|
153 | def test_should_not_recreate_custom_values_objects_on_update | |
154 | field = IssueCustomField.find_by_name('Database') |
|
154 | field = IssueCustomField.find_by_name('Database') | |
155 |
|
155 | |||
156 | issue = Issue.find(1) |
|
156 | issue = Issue.find(1) | |
157 | issue.custom_field_values = { field.id => 'PostgreSQL' } |
|
157 | issue.custom_field_values = { field.id => 'PostgreSQL' } | |
158 | assert issue.save |
|
158 | assert issue.save | |
159 | custom_value = issue.custom_value_for(field) |
|
159 | custom_value = issue.custom_value_for(field) | |
160 | issue.reload |
|
160 | issue.reload | |
161 | issue.custom_field_values = { field.id => 'MySQL' } |
|
161 | issue.custom_field_values = { field.id => 'MySQL' } | |
162 | assert issue.save |
|
162 | assert issue.save | |
163 | issue.reload |
|
163 | issue.reload | |
164 | assert_equal custom_value.id, issue.custom_value_for(field).id |
|
164 | assert_equal custom_value.id, issue.custom_value_for(field).id | |
165 | end |
|
165 | end | |
166 |
|
166 | |||
167 | def test_assigning_tracker_id_should_reload_custom_fields_values |
|
167 | def test_assigning_tracker_id_should_reload_custom_fields_values | |
168 | issue = Issue.new(:project => Project.find(1)) |
|
168 | issue = Issue.new(:project => Project.find(1)) | |
169 | assert issue.custom_field_values.empty? |
|
169 | assert issue.custom_field_values.empty? | |
170 | issue.tracker_id = 1 |
|
170 | issue.tracker_id = 1 | |
171 | assert issue.custom_field_values.any? |
|
171 | assert issue.custom_field_values.any? | |
172 | end |
|
172 | end | |
173 |
|
173 | |||
174 | def test_assigning_attributes_should_assign_tracker_id_first |
|
174 | def test_assigning_attributes_should_assign_tracker_id_first | |
175 | attributes = ActiveSupport::OrderedHash.new |
|
175 | attributes = ActiveSupport::OrderedHash.new | |
176 | attributes['custom_field_values'] = { '1' => 'MySQL' } |
|
176 | attributes['custom_field_values'] = { '1' => 'MySQL' } | |
177 | attributes['tracker_id'] = '1' |
|
177 | attributes['tracker_id'] = '1' | |
178 | issue = Issue.new(:project => Project.find(1)) |
|
178 | issue = Issue.new(:project => Project.find(1)) | |
179 | issue.attributes = attributes |
|
179 | issue.attributes = attributes | |
180 | assert_not_nil issue.custom_value_for(1) |
|
180 | assert_not_nil issue.custom_value_for(1) | |
181 | assert_equal 'MySQL', issue.custom_value_for(1).value |
|
181 | assert_equal 'MySQL', issue.custom_value_for(1).value | |
182 | end |
|
182 | end | |
183 |
|
183 | |||
184 | def test_should_update_issue_with_disabled_tracker |
|
184 | def test_should_update_issue_with_disabled_tracker | |
185 | p = Project.find(1) |
|
185 | p = Project.find(1) | |
186 | issue = Issue.find(1) |
|
186 | issue = Issue.find(1) | |
187 |
|
187 | |||
188 | p.trackers.delete(issue.tracker) |
|
188 | p.trackers.delete(issue.tracker) | |
189 | assert !p.trackers.include?(issue.tracker) |
|
189 | assert !p.trackers.include?(issue.tracker) | |
190 |
|
190 | |||
191 | issue.reload |
|
191 | issue.reload | |
192 | issue.subject = 'New subject' |
|
192 | issue.subject = 'New subject' | |
193 | assert issue.save |
|
193 | assert issue.save | |
194 | end |
|
194 | end | |
195 |
|
195 | |||
196 | def test_should_not_set_a_disabled_tracker |
|
196 | def test_should_not_set_a_disabled_tracker | |
197 | p = Project.find(1) |
|
197 | p = Project.find(1) | |
198 | p.trackers.delete(Tracker.find(2)) |
|
198 | p.trackers.delete(Tracker.find(2)) | |
199 |
|
199 | |||
200 | issue = Issue.find(1) |
|
200 | issue = Issue.find(1) | |
201 | issue.tracker_id = 2 |
|
201 | issue.tracker_id = 2 | |
202 | issue.subject = 'New subject' |
|
202 | issue.subject = 'New subject' | |
203 | assert !issue.save |
|
203 | assert !issue.save | |
204 | assert_not_nil issue.errors.on(:tracker_id) |
|
204 | assert_not_nil issue.errors.on(:tracker_id) | |
205 | end |
|
205 | end | |
206 |
|
206 | |||
207 | def test_category_based_assignment |
|
207 | def test_category_based_assignment | |
208 | issue = Issue.create(:project_id => 1, :tracker_id => 1, :author_id => 3, :status_id => 1, :priority => IssuePriority.all.first, :subject => 'Assignment test', :description => 'Assignment test', :category_id => 1) |
|
208 | issue = Issue.create(:project_id => 1, :tracker_id => 1, :author_id => 3, :status_id => 1, :priority => IssuePriority.all.first, :subject => 'Assignment test', :description => 'Assignment test', :category_id => 1) | |
209 | assert_equal IssueCategory.find(1).assigned_to, issue.assigned_to |
|
209 | assert_equal IssueCategory.find(1).assigned_to, issue.assigned_to | |
210 | end |
|
210 | end | |
211 |
|
211 | |||
212 | def test_copy |
|
212 | def test_copy | |
213 | issue = Issue.new.copy_from(1) |
|
213 | issue = Issue.new.copy_from(1) | |
214 | assert issue.save |
|
214 | assert issue.save | |
215 | issue.reload |
|
215 | issue.reload | |
216 | orig = Issue.find(1) |
|
216 | orig = Issue.find(1) | |
217 | assert_equal orig.subject, issue.subject |
|
217 | assert_equal orig.subject, issue.subject | |
218 | assert_equal orig.tracker, issue.tracker |
|
218 | assert_equal orig.tracker, issue.tracker | |
219 | assert_equal "125", issue.custom_value_for(2).value |
|
219 | assert_equal "125", issue.custom_value_for(2).value | |
220 | end |
|
220 | end | |
221 |
|
221 | |||
222 | def test_copy_should_copy_status |
|
222 | def test_copy_should_copy_status | |
223 | orig = Issue.find(8) |
|
223 | orig = Issue.find(8) | |
224 | assert orig.status != IssueStatus.default |
|
224 | assert orig.status != IssueStatus.default | |
225 |
|
225 | |||
226 | issue = Issue.new.copy_from(orig) |
|
226 | issue = Issue.new.copy_from(orig) | |
227 | assert issue.save |
|
227 | assert issue.save | |
228 | issue.reload |
|
228 | issue.reload | |
229 | assert_equal orig.status, issue.status |
|
229 | assert_equal orig.status, issue.status | |
230 | end |
|
230 | end | |
231 |
|
231 | |||
232 | def test_should_close_duplicates |
|
232 | def test_should_close_duplicates | |
233 | # Create 3 issues |
|
233 | # Create 3 issues | |
234 | issue1 = Issue.new(:project_id => 1, :tracker_id => 1, :author_id => 1, :status_id => 1, :priority => IssuePriority.all.first, :subject => 'Duplicates test', :description => 'Duplicates test') |
|
234 | issue1 = Issue.new(:project_id => 1, :tracker_id => 1, :author_id => 1, :status_id => 1, :priority => IssuePriority.all.first, :subject => 'Duplicates test', :description => 'Duplicates test') | |
235 | assert issue1.save |
|
235 | assert issue1.save | |
236 | issue2 = issue1.clone |
|
236 | issue2 = issue1.clone | |
237 | assert issue2.save |
|
237 | assert issue2.save | |
238 | issue3 = issue1.clone |
|
238 | issue3 = issue1.clone | |
239 | assert issue3.save |
|
239 | assert issue3.save | |
240 |
|
240 | |||
241 | # 2 is a dupe of 1 |
|
241 | # 2 is a dupe of 1 | |
242 | IssueRelation.create(:issue_from => issue2, :issue_to => issue1, :relation_type => IssueRelation::TYPE_DUPLICATES) |
|
242 | IssueRelation.create(:issue_from => issue2, :issue_to => issue1, :relation_type => IssueRelation::TYPE_DUPLICATES) | |
243 | # And 3 is a dupe of 2 |
|
243 | # And 3 is a dupe of 2 | |
244 | IssueRelation.create(:issue_from => issue3, :issue_to => issue2, :relation_type => IssueRelation::TYPE_DUPLICATES) |
|
244 | IssueRelation.create(:issue_from => issue3, :issue_to => issue2, :relation_type => IssueRelation::TYPE_DUPLICATES) | |
245 | # And 3 is a dupe of 1 (circular duplicates) |
|
245 | # And 3 is a dupe of 1 (circular duplicates) | |
246 | IssueRelation.create(:issue_from => issue3, :issue_to => issue1, :relation_type => IssueRelation::TYPE_DUPLICATES) |
|
246 | IssueRelation.create(:issue_from => issue3, :issue_to => issue1, :relation_type => IssueRelation::TYPE_DUPLICATES) | |
247 |
|
247 | |||
248 | assert issue1.reload.duplicates.include?(issue2) |
|
248 | assert issue1.reload.duplicates.include?(issue2) | |
249 |
|
249 | |||
250 | # Closing issue 1 |
|
250 | # Closing issue 1 | |
251 | issue1.init_journal(User.find(:first), "Closing issue1") |
|
251 | issue1.init_journal(User.find(:first), "Closing issue1") | |
252 | issue1.status = IssueStatus.find :first, :conditions => {:is_closed => true} |
|
252 | issue1.status = IssueStatus.find :first, :conditions => {:is_closed => true} | |
253 | assert issue1.save |
|
253 | assert issue1.save | |
254 | # 2 and 3 should be also closed |
|
254 | # 2 and 3 should be also closed | |
255 | assert issue2.reload.closed? |
|
255 | assert issue2.reload.closed? | |
256 | assert issue3.reload.closed? |
|
256 | assert issue3.reload.closed? | |
257 | end |
|
257 | end | |
258 |
|
258 | |||
259 | def test_should_not_close_duplicated_issue |
|
259 | def test_should_not_close_duplicated_issue | |
260 | # Create 3 issues |
|
260 | # Create 3 issues | |
261 | issue1 = Issue.new(:project_id => 1, :tracker_id => 1, :author_id => 1, :status_id => 1, :priority => IssuePriority.all.first, :subject => 'Duplicates test', :description => 'Duplicates test') |
|
261 | issue1 = Issue.new(:project_id => 1, :tracker_id => 1, :author_id => 1, :status_id => 1, :priority => IssuePriority.all.first, :subject => 'Duplicates test', :description => 'Duplicates test') | |
262 | assert issue1.save |
|
262 | assert issue1.save | |
263 | issue2 = issue1.clone |
|
263 | issue2 = issue1.clone | |
264 | assert issue2.save |
|
264 | assert issue2.save | |
265 |
|
265 | |||
266 | # 2 is a dupe of 1 |
|
266 | # 2 is a dupe of 1 | |
267 | IssueRelation.create(:issue_from => issue2, :issue_to => issue1, :relation_type => IssueRelation::TYPE_DUPLICATES) |
|
267 | IssueRelation.create(:issue_from => issue2, :issue_to => issue1, :relation_type => IssueRelation::TYPE_DUPLICATES) | |
268 | # 2 is a dup of 1 but 1 is not a duplicate of 2 |
|
268 | # 2 is a dup of 1 but 1 is not a duplicate of 2 | |
269 | assert !issue2.reload.duplicates.include?(issue1) |
|
269 | assert !issue2.reload.duplicates.include?(issue1) | |
270 |
|
270 | |||
271 | # Closing issue 2 |
|
271 | # Closing issue 2 | |
272 | issue2.init_journal(User.find(:first), "Closing issue2") |
|
272 | issue2.init_journal(User.find(:first), "Closing issue2") | |
273 | issue2.status = IssueStatus.find :first, :conditions => {:is_closed => true} |
|
273 | issue2.status = IssueStatus.find :first, :conditions => {:is_closed => true} | |
274 | assert issue2.save |
|
274 | assert issue2.save | |
275 | # 1 should not be also closed |
|
275 | # 1 should not be also closed | |
276 | assert !issue1.reload.closed? |
|
276 | assert !issue1.reload.closed? | |
277 | end |
|
277 | end | |
278 |
|
278 | |||
279 | def test_assignable_versions |
|
279 | def test_assignable_versions | |
280 | issue = Issue.new(:project_id => 1, :tracker_id => 1, :author_id => 1, :status_id => 1, :fixed_version_id => 1, :subject => 'New issue') |
|
280 | issue = Issue.new(:project_id => 1, :tracker_id => 1, :author_id => 1, :status_id => 1, :fixed_version_id => 1, :subject => 'New issue') | |
281 | assert_equal ['open'], issue.assignable_versions.collect(&:status).uniq |
|
281 | assert_equal ['open'], issue.assignable_versions.collect(&:status).uniq | |
282 | end |
|
282 | end | |
283 |
|
283 | |||
284 | def test_should_not_be_able_to_assign_a_new_issue_to_a_closed_version |
|
284 | def test_should_not_be_able_to_assign_a_new_issue_to_a_closed_version | |
285 | issue = Issue.new(:project_id => 1, :tracker_id => 1, :author_id => 1, :status_id => 1, :fixed_version_id => 1, :subject => 'New issue') |
|
285 | issue = Issue.new(:project_id => 1, :tracker_id => 1, :author_id => 1, :status_id => 1, :fixed_version_id => 1, :subject => 'New issue') | |
286 | assert !issue.save |
|
286 | assert !issue.save | |
287 | assert_not_nil issue.errors.on(:fixed_version_id) |
|
287 | assert_not_nil issue.errors.on(:fixed_version_id) | |
288 | end |
|
288 | end | |
289 |
|
289 | |||
290 | def test_should_not_be_able_to_assign_a_new_issue_to_a_locked_version |
|
290 | def test_should_not_be_able_to_assign_a_new_issue_to_a_locked_version | |
291 | issue = Issue.new(:project_id => 1, :tracker_id => 1, :author_id => 1, :status_id => 1, :fixed_version_id => 2, :subject => 'New issue') |
|
291 | issue = Issue.new(:project_id => 1, :tracker_id => 1, :author_id => 1, :status_id => 1, :fixed_version_id => 2, :subject => 'New issue') | |
292 | assert !issue.save |
|
292 | assert !issue.save | |
293 | assert_not_nil issue.errors.on(:fixed_version_id) |
|
293 | assert_not_nil issue.errors.on(:fixed_version_id) | |
294 | end |
|
294 | end | |
295 |
|
295 | |||
296 | def test_should_be_able_to_assign_a_new_issue_to_an_open_version |
|
296 | def test_should_be_able_to_assign_a_new_issue_to_an_open_version | |
297 | issue = Issue.new(:project_id => 1, :tracker_id => 1, :author_id => 1, :status_id => 1, :fixed_version_id => 3, :subject => 'New issue') |
|
297 | issue = Issue.new(:project_id => 1, :tracker_id => 1, :author_id => 1, :status_id => 1, :fixed_version_id => 3, :subject => 'New issue') | |
298 | assert issue.save |
|
298 | assert issue.save | |
299 | end |
|
299 | end | |
300 |
|
300 | |||
301 | def test_should_be_able_to_update_an_issue_assigned_to_a_closed_version |
|
301 | def test_should_be_able_to_update_an_issue_assigned_to_a_closed_version | |
302 | issue = Issue.find(11) |
|
302 | issue = Issue.find(11) | |
303 | assert_equal 'closed', issue.fixed_version.status |
|
303 | assert_equal 'closed', issue.fixed_version.status | |
304 | issue.subject = 'Subject changed' |
|
304 | issue.subject = 'Subject changed' | |
305 | assert issue.save |
|
305 | assert issue.save | |
306 | end |
|
306 | end | |
307 |
|
307 | |||
308 | def test_should_not_be_able_to_reopen_an_issue_assigned_to_a_closed_version |
|
308 | def test_should_not_be_able_to_reopen_an_issue_assigned_to_a_closed_version | |
309 | issue = Issue.find(11) |
|
309 | issue = Issue.find(11) | |
310 | issue.status_id = 1 |
|
310 | issue.status_id = 1 | |
311 | assert !issue.save |
|
311 | assert !issue.save | |
312 | assert_not_nil issue.errors.on_base |
|
312 | assert_not_nil issue.errors.on_base | |
313 | end |
|
313 | end | |
314 |
|
314 | |||
315 | def test_should_be_able_to_reopen_and_reassign_an_issue_assigned_to_a_closed_version |
|
315 | def test_should_be_able_to_reopen_and_reassign_an_issue_assigned_to_a_closed_version | |
316 | issue = Issue.find(11) |
|
316 | issue = Issue.find(11) | |
317 | issue.status_id = 1 |
|
317 | issue.status_id = 1 | |
318 | issue.fixed_version_id = 3 |
|
318 | issue.fixed_version_id = 3 | |
319 | assert issue.save |
|
319 | assert issue.save | |
320 | end |
|
320 | end | |
321 |
|
321 | |||
322 | def test_should_be_able_to_reopen_an_issue_assigned_to_a_locked_version |
|
322 | def test_should_be_able_to_reopen_an_issue_assigned_to_a_locked_version | |
323 | issue = Issue.find(12) |
|
323 | issue = Issue.find(12) | |
324 | assert_equal 'locked', issue.fixed_version.status |
|
324 | assert_equal 'locked', issue.fixed_version.status | |
325 | issue.status_id = 1 |
|
325 | issue.status_id = 1 | |
326 | assert issue.save |
|
326 | assert issue.save | |
327 | end |
|
327 | end | |
328 |
|
328 | |||
329 | def test_move_to_another_project_with_same_category |
|
329 | def test_move_to_another_project_with_same_category | |
330 | issue = Issue.find(1) |
|
330 | issue = Issue.find(1) | |
331 | assert issue.move_to(Project.find(2)) |
|
331 | assert issue.move_to(Project.find(2)) | |
332 | issue.reload |
|
332 | issue.reload | |
333 | assert_equal 2, issue.project_id |
|
333 | assert_equal 2, issue.project_id | |
334 | # Category changes |
|
334 | # Category changes | |
335 | assert_equal 4, issue.category_id |
|
335 | assert_equal 4, issue.category_id | |
336 | # Make sure time entries were move to the target project |
|
336 | # Make sure time entries were move to the target project | |
337 | assert_equal 2, issue.time_entries.first.project_id |
|
337 | assert_equal 2, issue.time_entries.first.project_id | |
338 | end |
|
338 | end | |
339 |
|
339 | |||
340 | def test_move_to_another_project_without_same_category |
|
340 | def test_move_to_another_project_without_same_category | |
341 | issue = Issue.find(2) |
|
341 | issue = Issue.find(2) | |
342 | assert issue.move_to(Project.find(2)) |
|
342 | assert issue.move_to(Project.find(2)) | |
343 | issue.reload |
|
343 | issue.reload | |
344 | assert_equal 2, issue.project_id |
|
344 | assert_equal 2, issue.project_id | |
345 | # Category cleared |
|
345 | # Category cleared | |
346 | assert_nil issue.category_id |
|
346 | assert_nil issue.category_id | |
347 | end |
|
347 | end | |
348 |
|
348 | |||
349 | def test_move_to_another_project_should_clear_fixed_version_when_not_shared |
|
349 | def test_move_to_another_project_should_clear_fixed_version_when_not_shared | |
350 | issue = Issue.find(1) |
|
350 | issue = Issue.find(1) | |
351 | issue.update_attribute(:fixed_version_id, 1) |
|
351 | issue.update_attribute(:fixed_version_id, 1) | |
352 | assert issue.move_to(Project.find(2)) |
|
352 | assert issue.move_to(Project.find(2)) | |
353 | issue.reload |
|
353 | issue.reload | |
354 | assert_equal 2, issue.project_id |
|
354 | assert_equal 2, issue.project_id | |
355 | # Cleared fixed_version |
|
355 | # Cleared fixed_version | |
356 | assert_equal nil, issue.fixed_version |
|
356 | assert_equal nil, issue.fixed_version | |
357 | end |
|
357 | end | |
358 |
|
358 | |||
359 | def test_move_to_another_project_should_keep_fixed_version_when_shared_with_the_target_project |
|
359 | def test_move_to_another_project_should_keep_fixed_version_when_shared_with_the_target_project | |
360 | issue = Issue.find(1) |
|
360 | issue = Issue.find(1) | |
361 | issue.update_attribute(:fixed_version_id, 4) |
|
361 | issue.update_attribute(:fixed_version_id, 4) | |
362 | assert issue.move_to(Project.find(5)) |
|
362 | assert issue.move_to(Project.find(5)) | |
363 | issue.reload |
|
363 | issue.reload | |
364 | assert_equal 5, issue.project_id |
|
364 | assert_equal 5, issue.project_id | |
365 | # Keep fixed_version |
|
365 | # Keep fixed_version | |
366 | assert_equal 4, issue.fixed_version_id |
|
366 | assert_equal 4, issue.fixed_version_id | |
367 | end |
|
367 | end | |
368 |
|
368 | |||
369 | def test_move_to_another_project_should_clear_fixed_version_when_not_shared_with_the_target_project |
|
369 | def test_move_to_another_project_should_clear_fixed_version_when_not_shared_with_the_target_project | |
370 | issue = Issue.find(1) |
|
370 | issue = Issue.find(1) | |
371 | issue.update_attribute(:fixed_version_id, 1) |
|
371 | issue.update_attribute(:fixed_version_id, 1) | |
372 | assert issue.move_to(Project.find(5)) |
|
372 | assert issue.move_to(Project.find(5)) | |
373 | issue.reload |
|
373 | issue.reload | |
374 | assert_equal 5, issue.project_id |
|
374 | assert_equal 5, issue.project_id | |
375 | # Cleared fixed_version |
|
375 | # Cleared fixed_version | |
376 | assert_equal nil, issue.fixed_version |
|
376 | assert_equal nil, issue.fixed_version | |
377 | end |
|
377 | end | |
378 |
|
378 | |||
379 | def test_move_to_another_project_should_keep_fixed_version_when_shared_systemwide |
|
379 | def test_move_to_another_project_should_keep_fixed_version_when_shared_systemwide | |
380 | issue = Issue.find(1) |
|
380 | issue = Issue.find(1) | |
381 | issue.update_attribute(:fixed_version_id, 7) |
|
381 | issue.update_attribute(:fixed_version_id, 7) | |
382 | assert issue.move_to(Project.find(2)) |
|
382 | assert issue.move_to(Project.find(2)) | |
383 | issue.reload |
|
383 | issue.reload | |
384 | assert_equal 2, issue.project_id |
|
384 | assert_equal 2, issue.project_id | |
385 | # Keep fixed_version |
|
385 | # Keep fixed_version | |
386 | assert_equal 7, issue.fixed_version_id |
|
386 | assert_equal 7, issue.fixed_version_id | |
387 | end |
|
387 | end | |
388 |
|
388 | |||
389 | def test_move_to_another_project_with_disabled_tracker |
|
389 | def test_move_to_another_project_with_disabled_tracker | |
390 | issue = Issue.find(1) |
|
390 | issue = Issue.find(1) | |
391 | target = Project.find(2) |
|
391 | target = Project.find(2) | |
392 | target.tracker_ids = [3] |
|
392 | target.tracker_ids = [3] | |
393 | target.save |
|
393 | target.save | |
394 | assert_equal false, issue.move_to(target) |
|
394 | assert_equal false, issue.move_to(target) | |
395 | issue.reload |
|
395 | issue.reload | |
396 | assert_equal 1, issue.project_id |
|
396 | assert_equal 1, issue.project_id | |
397 | end |
|
397 | end | |
398 |
|
398 | |||
399 | def test_copy_to_the_same_project |
|
399 | def test_copy_to_the_same_project | |
400 | issue = Issue.find(1) |
|
400 | issue = Issue.find(1) | |
401 | copy = nil |
|
401 | copy = nil | |
402 | assert_difference 'Issue.count' do |
|
402 | assert_difference 'Issue.count' do | |
403 | copy = issue.move_to(issue.project, nil, :copy => true) |
|
403 | copy = issue.move_to(issue.project, nil, :copy => true) | |
404 | end |
|
404 | end | |
405 | assert_kind_of Issue, copy |
|
405 | assert_kind_of Issue, copy | |
406 | assert_equal issue.project, copy.project |
|
406 | assert_equal issue.project, copy.project | |
407 | assert_equal "125", copy.custom_value_for(2).value |
|
407 | assert_equal "125", copy.custom_value_for(2).value | |
408 | end |
|
408 | end | |
409 |
|
409 | |||
410 | def test_copy_to_another_project_and_tracker |
|
410 | def test_copy_to_another_project_and_tracker | |
411 | issue = Issue.find(1) |
|
411 | issue = Issue.find(1) | |
412 | copy = nil |
|
412 | copy = nil | |
413 | assert_difference 'Issue.count' do |
|
413 | assert_difference 'Issue.count' do | |
414 | copy = issue.move_to(Project.find(3), Tracker.find(2), :copy => true) |
|
414 | copy = issue.move_to(Project.find(3), Tracker.find(2), :copy => true) | |
415 | end |
|
415 | end | |
416 | assert_kind_of Issue, copy |
|
416 | assert_kind_of Issue, copy | |
417 | assert_equal Project.find(3), copy.project |
|
417 | assert_equal Project.find(3), copy.project | |
418 | assert_equal Tracker.find(2), copy.tracker |
|
418 | assert_equal Tracker.find(2), copy.tracker | |
419 | # Custom field #2 is not associated with target tracker |
|
419 | # Custom field #2 is not associated with target tracker | |
420 | assert_nil copy.custom_value_for(2) |
|
420 | assert_nil copy.custom_value_for(2) | |
421 | end |
|
421 | end | |
422 |
|
422 | |||
423 | context "#move_to" do |
|
423 | context "#move_to" do | |
424 | context "as a copy" do |
|
424 | context "as a copy" do | |
425 | setup do |
|
425 | setup do | |
426 | @issue = Issue.find(1) |
|
426 | @issue = Issue.find(1) | |
427 | @copy = nil |
|
427 | @copy = nil | |
428 | end |
|
428 | end | |
429 |
|
429 | |||
430 | should "allow assigned_to changes" do |
|
430 | should "allow assigned_to changes" do | |
431 | @copy = @issue.move_to(Project.find(3), Tracker.find(2), {:copy => true, :attributes => {:assigned_to_id => 3}}) |
|
431 | @copy = @issue.move_to(Project.find(3), Tracker.find(2), {:copy => true, :attributes => {:assigned_to_id => 3}}) | |
432 | assert_equal 3, @copy.assigned_to_id |
|
432 | assert_equal 3, @copy.assigned_to_id | |
433 | end |
|
433 | end | |
434 |
|
434 | |||
435 | should "allow status changes" do |
|
435 | should "allow status changes" do | |
436 | @copy = @issue.move_to(Project.find(3), Tracker.find(2), {:copy => true, :attributes => {:status_id => 2}}) |
|
436 | @copy = @issue.move_to(Project.find(3), Tracker.find(2), {:copy => true, :attributes => {:status_id => 2}}) | |
437 | assert_equal 2, @copy.status_id |
|
437 | assert_equal 2, @copy.status_id | |
438 | end |
|
438 | end | |
439 |
|
439 | |||
440 | should "allow start date changes" do |
|
440 | should "allow start date changes" do | |
441 | date = Date.today |
|
441 | date = Date.today | |
442 | @copy = @issue.move_to(Project.find(3), Tracker.find(2), {:copy => true, :attributes => {:start_date => date}}) |
|
442 | @copy = @issue.move_to(Project.find(3), Tracker.find(2), {:copy => true, :attributes => {:start_date => date}}) | |
443 | assert_equal date, @copy.start_date |
|
443 | assert_equal date, @copy.start_date | |
444 | end |
|
444 | end | |
445 |
|
445 | |||
446 | should "allow due date changes" do |
|
446 | should "allow due date changes" do | |
447 | date = Date.today |
|
447 | date = Date.today | |
448 | @copy = @issue.move_to(Project.find(3), Tracker.find(2), {:copy => true, :attributes => {:due_date => date}}) |
|
448 | @copy = @issue.move_to(Project.find(3), Tracker.find(2), {:copy => true, :attributes => {:due_date => date}}) | |
449 |
|
449 | |||
450 | assert_equal date, @copy.due_date |
|
450 | assert_equal date, @copy.due_date | |
451 | end |
|
451 | end | |
452 | end |
|
452 | end | |
453 | end |
|
453 | end | |
454 |
|
454 | |||
455 | def test_recipients_should_not_include_users_that_cannot_view_the_issue |
|
455 | def test_recipients_should_not_include_users_that_cannot_view_the_issue | |
456 | issue = Issue.find(12) |
|
456 | issue = Issue.find(12) | |
457 | assert issue.recipients.include?(issue.author.mail) |
|
457 | assert issue.recipients.include?(issue.author.mail) | |
458 | # move the issue to a private project |
|
458 | # move the issue to a private project | |
459 | copy = issue.move_to(Project.find(5), Tracker.find(2), :copy => true) |
|
459 | copy = issue.move_to(Project.find(5), Tracker.find(2), :copy => true) | |
460 | # author is not a member of project anymore |
|
460 | # author is not a member of project anymore | |
461 | assert !copy.recipients.include?(copy.author.mail) |
|
461 | assert !copy.recipients.include?(copy.author.mail) | |
462 | end |
|
462 | end | |
463 |
|
463 | |||
464 | def test_watcher_recipients_should_not_include_users_that_cannot_view_the_issue |
|
464 | def test_watcher_recipients_should_not_include_users_that_cannot_view_the_issue | |
465 | user = User.find(3) |
|
465 | user = User.find(3) | |
466 | issue = Issue.find(9) |
|
466 | issue = Issue.find(9) | |
467 | Watcher.create!(:user => user, :watchable => issue) |
|
467 | Watcher.create!(:user => user, :watchable => issue) | |
468 | assert issue.watched_by?(user) |
|
468 | assert issue.watched_by?(user) | |
469 | assert !issue.watcher_recipients.include?(user.mail) |
|
469 | assert !issue.watcher_recipients.include?(user.mail) | |
470 | end |
|
470 | end | |
471 |
|
471 | |||
472 | def test_issue_destroy |
|
472 | def test_issue_destroy | |
473 | Issue.find(1).destroy |
|
473 | Issue.find(1).destroy | |
474 | assert_nil Issue.find_by_id(1) |
|
474 | assert_nil Issue.find_by_id(1) | |
475 | assert_nil TimeEntry.find_by_issue_id(1) |
|
475 | assert_nil TimeEntry.find_by_issue_id(1) | |
476 | end |
|
476 | end | |
477 |
|
477 | |||
478 | def test_blocked |
|
478 | def test_blocked | |
479 | blocked_issue = Issue.find(9) |
|
479 | blocked_issue = Issue.find(9) | |
480 | blocking_issue = Issue.find(10) |
|
480 | blocking_issue = Issue.find(10) | |
481 |
|
481 | |||
482 | assert blocked_issue.blocked? |
|
482 | assert blocked_issue.blocked? | |
483 | assert !blocking_issue.blocked? |
|
483 | assert !blocking_issue.blocked? | |
484 | end |
|
484 | end | |
485 |
|
485 | |||
486 | def test_blocked_issues_dont_allow_closed_statuses |
|
486 | def test_blocked_issues_dont_allow_closed_statuses | |
487 | blocked_issue = Issue.find(9) |
|
487 | blocked_issue = Issue.find(9) | |
488 |
|
488 | |||
489 | allowed_statuses = blocked_issue.new_statuses_allowed_to(users(:users_002)) |
|
489 | allowed_statuses = blocked_issue.new_statuses_allowed_to(users(:users_002)) | |
490 | assert !allowed_statuses.empty? |
|
490 | assert !allowed_statuses.empty? | |
491 | closed_statuses = allowed_statuses.select {|st| st.is_closed?} |
|
491 | closed_statuses = allowed_statuses.select {|st| st.is_closed?} | |
492 | assert closed_statuses.empty? |
|
492 | assert closed_statuses.empty? | |
493 | end |
|
493 | end | |
494 |
|
494 | |||
495 | def test_unblocked_issues_allow_closed_statuses |
|
495 | def test_unblocked_issues_allow_closed_statuses | |
496 | blocking_issue = Issue.find(10) |
|
496 | blocking_issue = Issue.find(10) | |
497 |
|
497 | |||
498 | allowed_statuses = blocking_issue.new_statuses_allowed_to(users(:users_002)) |
|
498 | allowed_statuses = blocking_issue.new_statuses_allowed_to(users(:users_002)) | |
499 | assert !allowed_statuses.empty? |
|
499 | assert !allowed_statuses.empty? | |
500 | closed_statuses = allowed_statuses.select {|st| st.is_closed?} |
|
500 | closed_statuses = allowed_statuses.select {|st| st.is_closed?} | |
501 | assert !closed_statuses.empty? |
|
501 | assert !closed_statuses.empty? | |
502 | end |
|
502 | end | |
503 |
|
503 | |||
504 | def test_overdue |
|
504 | def test_overdue | |
505 | assert Issue.new(:due_date => 1.day.ago.to_date).overdue? |
|
505 | assert Issue.new(:due_date => 1.day.ago.to_date).overdue? | |
506 | assert !Issue.new(:due_date => Date.today).overdue? |
|
506 | assert !Issue.new(:due_date => Date.today).overdue? | |
507 | assert !Issue.new(:due_date => 1.day.from_now.to_date).overdue? |
|
507 | assert !Issue.new(:due_date => 1.day.from_now.to_date).overdue? | |
508 | assert !Issue.new(:due_date => nil).overdue? |
|
508 | assert !Issue.new(:due_date => nil).overdue? | |
509 | assert !Issue.new(:due_date => 1.day.ago.to_date, :status => IssueStatus.find(:first, :conditions => {:is_closed => true})).overdue? |
|
509 | assert !Issue.new(:due_date => 1.day.ago.to_date, :status => IssueStatus.find(:first, :conditions => {:is_closed => true})).overdue? | |
510 | end |
|
510 | end | |
511 |
|
511 | |||
512 | def test_assignable_users |
|
512 | def test_assignable_users | |
513 | assert_kind_of User, Issue.find(1).assignable_users.first |
|
513 | assert_kind_of User, Issue.find(1).assignable_users.first | |
514 | end |
|
514 | end | |
515 |
|
515 | |||
516 | def test_create_should_send_email_notification |
|
516 | def test_create_should_send_email_notification | |
517 | ActionMailer::Base.deliveries.clear |
|
517 | ActionMailer::Base.deliveries.clear | |
518 | issue = Issue.new(:project_id => 1, :tracker_id => 1, :author_id => 3, :status_id => 1, :priority => IssuePriority.all.first, :subject => 'test_create', :estimated_hours => '1:30') |
|
518 | issue = Issue.new(:project_id => 1, :tracker_id => 1, :author_id => 3, :status_id => 1, :priority => IssuePriority.all.first, :subject => 'test_create', :estimated_hours => '1:30') | |
519 |
|
519 | |||
520 | assert issue.save |
|
520 | assert issue.save | |
521 | assert_equal 1, ActionMailer::Base.deliveries.size |
|
521 | assert_equal 1, ActionMailer::Base.deliveries.size | |
522 | end |
|
522 | end | |
523 |
|
523 | |||
524 | def test_stale_issue_should_not_send_email_notification |
|
524 | def test_stale_issue_should_not_send_email_notification | |
525 | ActionMailer::Base.deliveries.clear |
|
525 | ActionMailer::Base.deliveries.clear | |
526 | issue = Issue.find(1) |
|
526 | issue = Issue.find(1) | |
527 | stale = Issue.find(1) |
|
527 | stale = Issue.find(1) | |
528 |
|
528 | |||
529 | issue.init_journal(User.find(1)) |
|
529 | issue.init_journal(User.find(1)) | |
530 | issue.subject = 'Subjet update' |
|
530 | issue.subject = 'Subjet update' | |
531 | assert issue.save |
|
531 | assert issue.save | |
532 | assert_equal 1, ActionMailer::Base.deliveries.size |
|
532 | assert_equal 1, ActionMailer::Base.deliveries.size | |
533 | ActionMailer::Base.deliveries.clear |
|
533 | ActionMailer::Base.deliveries.clear | |
534 |
|
534 | |||
535 | stale.init_journal(User.find(1)) |
|
535 | stale.init_journal(User.find(1)) | |
536 | stale.subject = 'Another subjet update' |
|
536 | stale.subject = 'Another subjet update' | |
537 | assert_raise ActiveRecord::StaleObjectError do |
|
537 | assert_raise ActiveRecord::StaleObjectError do | |
538 | stale.save |
|
538 | stale.save | |
539 | end |
|
539 | end | |
540 | assert ActionMailer::Base.deliveries.empty? |
|
540 | assert ActionMailer::Base.deliveries.empty? | |
541 | end |
|
541 | end | |
542 |
|
542 | |||
543 | context "#done_ratio" do |
|
543 | context "#done_ratio" do | |
544 | setup do |
|
544 | setup do | |
545 | @issue = Issue.find(1) |
|
545 | @issue = Issue.find(1) | |
546 | @issue_status = IssueStatus.find(1) |
|
546 | @issue_status = IssueStatus.find(1) | |
547 | @issue_status.update_attribute(:default_done_ratio, 50) |
|
547 | @issue_status.update_attribute(:default_done_ratio, 50) | |
548 | end |
|
548 | end | |
549 |
|
549 | |||
550 | context "with Setting.issue_done_ratio using the issue_field" do |
|
550 | context "with Setting.issue_done_ratio using the issue_field" do | |
551 | setup do |
|
551 | setup do | |
552 | Setting.issue_done_ratio = 'issue_field' |
|
552 | Setting.issue_done_ratio = 'issue_field' | |
553 | end |
|
553 | end | |
554 |
|
554 | |||
555 | should "read the issue's field" do |
|
555 | should "read the issue's field" do | |
556 | assert_equal 0, @issue.done_ratio |
|
556 | assert_equal 0, @issue.done_ratio | |
557 | end |
|
557 | end | |
558 | end |
|
558 | end | |
559 |
|
559 | |||
560 | context "with Setting.issue_done_ratio using the issue_status" do |
|
560 | context "with Setting.issue_done_ratio using the issue_status" do | |
561 | setup do |
|
561 | setup do | |
562 | Setting.issue_done_ratio = 'issue_status' |
|
562 | Setting.issue_done_ratio = 'issue_status' | |
563 | end |
|
563 | end | |
564 |
|
564 | |||
565 | should "read the Issue Status's default done ratio" do |
|
565 | should "read the Issue Status's default done ratio" do | |
566 | assert_equal 50, @issue.done_ratio |
|
566 | assert_equal 50, @issue.done_ratio | |
567 | end |
|
567 | end | |
568 | end |
|
568 | end | |
569 | end |
|
569 | end | |
570 |
|
570 | |||
571 | context "#update_done_ratio_from_issue_status" do |
|
571 | context "#update_done_ratio_from_issue_status" do | |
572 | setup do |
|
572 | setup do | |
573 | @issue = Issue.find(1) |
|
573 | @issue = Issue.find(1) | |
574 | @issue_status = IssueStatus.find(1) |
|
574 | @issue_status = IssueStatus.find(1) | |
575 | @issue_status.update_attribute(:default_done_ratio, 50) |
|
575 | @issue_status.update_attribute(:default_done_ratio, 50) | |
576 | end |
|
576 | end | |
577 |
|
577 | |||
578 | context "with Setting.issue_done_ratio using the issue_field" do |
|
578 | context "with Setting.issue_done_ratio using the issue_field" do | |
579 | setup do |
|
579 | setup do | |
580 | Setting.issue_done_ratio = 'issue_field' |
|
580 | Setting.issue_done_ratio = 'issue_field' | |
581 | end |
|
581 | end | |
582 |
|
582 | |||
583 | should "not change the issue" do |
|
583 | should "not change the issue" do | |
584 | @issue.update_done_ratio_from_issue_status |
|
584 | @issue.update_done_ratio_from_issue_status | |
585 |
|
585 | |||
586 | assert_equal 0, @issue.done_ratio |
|
586 | assert_equal 0, @issue.done_ratio | |
587 | end |
|
587 | end | |
588 | end |
|
588 | end | |
589 |
|
589 | |||
590 | context "with Setting.issue_done_ratio using the issue_status" do |
|
590 | context "with Setting.issue_done_ratio using the issue_status" do | |
591 | setup do |
|
591 | setup do | |
592 | Setting.issue_done_ratio = 'issue_status' |
|
592 | Setting.issue_done_ratio = 'issue_status' | |
593 | end |
|
593 | end | |
594 |
|
594 | |||
595 | should "not change the issue's done ratio" do |
|
595 | should "not change the issue's done ratio" do | |
596 | @issue.update_done_ratio_from_issue_status |
|
596 | @issue.update_done_ratio_from_issue_status | |
597 |
|
597 | |||
598 | assert_equal 50, @issue.done_ratio |
|
598 | assert_equal 50, @issue.done_ratio | |
599 | end |
|
599 | end | |
600 | end |
|
600 | end | |
601 | end |
|
601 | end | |
|
602 | ||||
|
603 | context ".allowed_target_projects_on_move" do | |||
|
604 | should "return all active projects for admin users" do | |||
|
605 | User.current = User.find(1) | |||
|
606 | assert_equal Project.active.count, Issue.allowed_target_projects_on_move.size | |||
|
607 | end | |||
|
608 | ||||
|
609 | should "return allowed projects for non admin users" do | |||
|
610 | User.current = User.find(2) | |||
|
611 | Role.non_member.remove_permission! :move_issues | |||
|
612 | assert_equal 3, Issue.allowed_target_projects_on_move.size | |||
|
613 | ||||
|
614 | Role.non_member.add_permission! :move_issues | |||
|
615 | assert_equal Project.active.count, Issue.allowed_target_projects_on_move.size | |||
|
616 | end | |||
|
617 | end | |||
602 | end |
|
618 | end |
General Comments 0
You need to be logged in to leave comments.
Login now