|
@@
-1,514
+1,514
|
|
1
|
1
|
# Redmine - project management software
|
|
2
|
2
|
# Copyright (C) 2006-2015 Jean-Philippe Lang
|
|
3
|
3
|
#
|
|
4
|
4
|
# This program is free software; you can redistribute it and/or
|
|
5
|
5
|
# modify it under the terms of the GNU General Public License
|
|
6
|
6
|
# as published by the Free Software Foundation; either version 2
|
|
7
|
7
|
# of the License, or (at your option) any later version.
|
|
8
|
8
|
#
|
|
9
|
9
|
# This program is distributed in the hope that it will be useful,
|
|
10
|
10
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
11
|
11
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
12
|
12
|
# GNU General Public License for more details.
|
|
13
|
13
|
#
|
|
14
|
14
|
# You should have received a copy of the GNU General Public License
|
|
15
|
15
|
# along with this program; if not, write to the Free Software
|
|
16
|
16
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
17
|
17
|
|
|
18
|
18
|
class IssuesController < ApplicationController
|
|
19
|
19
|
menu_item :new_issue, :only => [:new, :create]
|
|
20
|
20
|
default_search_scope :issues
|
|
21
|
21
|
|
|
22
|
22
|
before_filter :find_issue, :only => [:show, :edit, :update]
|
|
23
|
23
|
before_filter :find_issues, :only => [:bulk_edit, :bulk_update, :destroy]
|
|
24
|
24
|
before_filter :authorize, :except => [:index, :new, :create]
|
|
25
|
25
|
before_filter :find_optional_project, :only => [:index, :new, :create]
|
|
26
|
26
|
before_filter :build_new_issue_from_params, :only => [:new, :create]
|
|
27
|
27
|
accept_rss_auth :index, :show
|
|
28
|
28
|
accept_api_auth :index, :show, :create, :update, :destroy
|
|
29
|
29
|
|
|
30
|
30
|
rescue_from Query::StatementInvalid, :with => :query_statement_invalid
|
|
31
|
31
|
|
|
32
|
32
|
helper :journals
|
|
33
|
33
|
helper :projects
|
|
34
|
34
|
helper :custom_fields
|
|
35
|
35
|
helper :issue_relations
|
|
36
|
36
|
helper :watchers
|
|
37
|
37
|
helper :attachments
|
|
38
|
38
|
helper :queries
|
|
39
|
39
|
include QueriesHelper
|
|
40
|
40
|
helper :repositories
|
|
41
|
41
|
helper :sort
|
|
42
|
42
|
include SortHelper
|
|
43
|
43
|
helper :timelog
|
|
44
|
44
|
|
|
45
|
45
|
def index
|
|
46
|
46
|
retrieve_query
|
|
47
|
47
|
sort_init(@query.sort_criteria.empty? ? [['id', 'desc']] : @query.sort_criteria)
|
|
48
|
48
|
sort_update(@query.sortable_columns)
|
|
49
|
49
|
@query.sort_criteria = sort_criteria.to_a
|
|
50
|
50
|
|
|
51
|
51
|
if @query.valid?
|
|
52
|
52
|
case params[:format]
|
|
53
|
53
|
when 'csv', 'pdf'
|
|
54
|
54
|
@limit = Setting.issues_export_limit.to_i
|
|
55
|
55
|
if params[:columns] == 'all'
|
|
56
|
56
|
@query.column_names = @query.available_inline_columns.map(&:name)
|
|
57
|
57
|
end
|
|
58
|
58
|
when 'atom'
|
|
59
|
59
|
@limit = Setting.feeds_limit.to_i
|
|
60
|
60
|
when 'xml', 'json'
|
|
61
|
61
|
@offset, @limit = api_offset_and_limit
|
|
62
|
62
|
@query.column_names = %w(author)
|
|
63
|
63
|
else
|
|
64
|
64
|
@limit = per_page_option
|
|
65
|
65
|
end
|
|
66
|
66
|
|
|
67
|
67
|
@issue_count = @query.issue_count
|
|
68
|
68
|
@issue_pages = Paginator.new @issue_count, @limit, params['page']
|
|
69
|
69
|
@offset ||= @issue_pages.offset
|
|
70
|
70
|
@issues = @query.issues(:include => [:assigned_to, :tracker, :priority, :category, :fixed_version],
|
|
71
|
71
|
:order => sort_clause,
|
|
72
|
72
|
:offset => @offset,
|
|
73
|
73
|
:limit => @limit)
|
|
74
|
74
|
@issue_count_by_group = @query.issue_count_by_group
|
|
75
|
75
|
|
|
76
|
76
|
respond_to do |format|
|
|
77
|
77
|
format.html { render :template => 'issues/index', :layout => !request.xhr? }
|
|
78
|
78
|
format.api {
|
|
79
|
79
|
Issue.load_visible_relations(@issues) if include_in_api_response?('relations')
|
|
80
|
80
|
}
|
|
81
|
81
|
format.atom { render_feed(@issues, :title => "#{@project || Setting.app_title}: #{l(:label_issue_plural)}") }
|
|
82
|
82
|
format.csv { send_data(query_to_csv(@issues, @query, params), :type => 'text/csv; header=present', :filename => 'issues.csv') }
|
|
83
|
83
|
format.pdf { send_file_headers! :type => 'application/pdf', :filename => 'issues.pdf' }
|
|
84
|
84
|
end
|
|
85
|
85
|
else
|
|
86
|
86
|
respond_to do |format|
|
|
87
|
87
|
format.html { render(:template => 'issues/index', :layout => !request.xhr?) }
|
|
88
|
88
|
format.any(:atom, :csv, :pdf) { render(:nothing => true) }
|
|
89
|
89
|
format.api { render_validation_errors(@query) }
|
|
90
|
90
|
end
|
|
91
|
91
|
end
|
|
92
|
92
|
rescue ActiveRecord::RecordNotFound
|
|
93
|
93
|
render_404
|
|
94
|
94
|
end
|
|
95
|
95
|
|
|
96
|
96
|
def show
|
|
97
|
97
|
@journals = @issue.journals.includes(:user, :details).
|
|
98
|
98
|
references(:user, :details).
|
|
99
|
99
|
reorder("#{Journal.table_name}.id ASC").to_a
|
|
100
|
100
|
@journals.each_with_index {|j,i| j.indice = i+1}
|
|
101
|
101
|
@journals.reject!(&:private_notes?) unless User.current.allowed_to?(:view_private_notes, @issue.project)
|
|
102
|
102
|
Journal.preload_journals_details_custom_fields(@journals)
|
|
103
|
103
|
@journals.select! {|journal| journal.notes? || journal.visible_details.any?}
|
|
104
|
104
|
@journals.reverse! if User.current.wants_comments_in_reverse_order?
|
|
105
|
105
|
|
|
106
|
106
|
@changesets = @issue.changesets.visible.to_a
|
|
107
|
107
|
@changesets.reverse! if User.current.wants_comments_in_reverse_order?
|
|
108
|
108
|
|
|
109
|
109
|
@relations = @issue.relations.select {|r| r.other_issue(@issue) && r.other_issue(@issue).visible? }
|
|
110
|
110
|
@allowed_statuses = @issue.new_statuses_allowed_to(User.current)
|
|
111
|
111
|
@priorities = IssuePriority.active
|
|
112
|
112
|
@time_entry = TimeEntry.new(:issue => @issue, :project => @issue.project)
|
|
113
|
113
|
@relation = IssueRelation.new
|
|
114
|
114
|
|
|
115
|
115
|
respond_to do |format|
|
|
116
|
116
|
format.html {
|
|
117
|
117
|
retrieve_previous_and_next_issue_ids
|
|
118
|
118
|
render :template => 'issues/show'
|
|
119
|
119
|
}
|
|
120
|
120
|
format.api
|
|
121
|
121
|
format.atom { render :template => 'journals/index', :layout => false, :content_type => 'application/atom+xml' }
|
|
122
|
122
|
format.pdf {
|
|
123
|
123
|
send_file_headers! :type => 'application/pdf', :filename => "#{@project.identifier}-#{@issue.id}.pdf"
|
|
124
|
124
|
}
|
|
125
|
125
|
end
|
|
126
|
126
|
end
|
|
127
|
127
|
|
|
128
|
128
|
def new
|
|
129
|
129
|
respond_to do |format|
|
|
130
|
130
|
format.html { render :action => 'new', :layout => !request.xhr? }
|
|
131
|
131
|
format.js
|
|
132
|
132
|
end
|
|
133
|
133
|
end
|
|
134
|
134
|
|
|
135
|
135
|
def create
|
|
136
|
136
|
unless User.current.allowed_to?(:add_issues, @issue.project, :global => true)
|
|
137
|
137
|
raise ::Unauthorized
|
|
138
|
138
|
end
|
|
139
|
139
|
call_hook(:controller_issues_new_before_save, { :params => params, :issue => @issue })
|
|
140
|
140
|
@issue.save_attachments(params[:attachments] || (params[:issue] && params[:issue][:uploads]))
|
|
141
|
141
|
if @issue.save
|
|
142
|
142
|
call_hook(:controller_issues_new_after_save, { :params => params, :issue => @issue})
|
|
143
|
143
|
respond_to do |format|
|
|
144
|
144
|
format.html {
|
|
145
|
145
|
render_attachment_warning_if_needed(@issue)
|
|
146
|
146
|
flash[:notice] = l(:notice_issue_successful_create, :id => view_context.link_to("##{@issue.id}", issue_path(@issue), :title => @issue.subject))
|
|
147
|
147
|
redirect_after_create
|
|
148
|
148
|
}
|
|
149
|
149
|
format.api { render :action => 'show', :status => :created, :location => issue_url(@issue) }
|
|
150
|
150
|
end
|
|
151
|
151
|
return
|
|
152
|
152
|
else
|
|
153
|
153
|
respond_to do |format|
|
|
154
|
154
|
format.html {
|
|
155
|
155
|
if @issue.project.nil?
|
|
156
|
156
|
render_error :status => 422
|
|
157
|
157
|
else
|
|
158
|
158
|
render :action => 'new'
|
|
159
|
159
|
end
|
|
160
|
160
|
}
|
|
161
|
161
|
format.api { render_validation_errors(@issue) }
|
|
162
|
162
|
end
|
|
163
|
163
|
end
|
|
164
|
164
|
end
|
|
165
|
165
|
|
|
166
|
166
|
def edit
|
|
167
|
167
|
return unless update_issue_from_params
|
|
168
|
168
|
|
|
169
|
169
|
respond_to do |format|
|
|
170
|
170
|
format.html { }
|
|
171
|
171
|
format.js
|
|
172
|
172
|
end
|
|
173
|
173
|
end
|
|
174
|
174
|
|
|
175
|
175
|
def update
|
|
176
|
176
|
return unless update_issue_from_params
|
|
177
|
177
|
@issue.save_attachments(params[:attachments] || (params[:issue] && params[:issue][:uploads]))
|
|
178
|
178
|
saved = false
|
|
179
|
179
|
begin
|
|
180
|
180
|
saved = save_issue_with_child_records
|
|
181
|
181
|
rescue ActiveRecord::StaleObjectError
|
|
182
|
182
|
@conflict = true
|
|
183
|
183
|
if params[:last_journal_id]
|
|
184
|
184
|
@conflict_journals = @issue.journals_after(params[:last_journal_id]).to_a
|
|
185
|
185
|
@conflict_journals.reject!(&:private_notes?) unless User.current.allowed_to?(:view_private_notes, @issue.project)
|
|
186
|
186
|
end
|
|
187
|
187
|
end
|
|
188
|
188
|
|
|
189
|
189
|
if saved
|
|
190
|
190
|
render_attachment_warning_if_needed(@issue)
|
|
191
|
191
|
flash[:notice] = l(:notice_successful_update) unless @issue.current_journal.new_record?
|
|
192
|
192
|
|
|
193
|
193
|
respond_to do |format|
|
|
194
|
194
|
format.html { redirect_back_or_default issue_path(@issue) }
|
|
195
|
195
|
format.api { render_api_ok }
|
|
196
|
196
|
end
|
|
197
|
197
|
else
|
|
198
|
198
|
respond_to do |format|
|
|
199
|
199
|
format.html { render :action => 'edit' }
|
|
200
|
200
|
format.api { render_validation_errors(@issue) }
|
|
201
|
201
|
end
|
|
202
|
202
|
end
|
|
203
|
203
|
end
|
|
204
|
204
|
|
|
205
|
205
|
# Bulk edit/copy a set of issues
|
|
206
|
206
|
def bulk_edit
|
|
207
|
207
|
@issues.sort!
|
|
208
|
208
|
@copy = params[:copy].present?
|
|
209
|
209
|
@notes = params[:notes]
|
|
210
|
210
|
|
|
211
|
211
|
if @copy
|
|
212
|
212
|
unless User.current.allowed_to?(:copy_issues, @projects)
|
|
213
|
213
|
raise ::Unauthorized
|
|
214
|
214
|
end
|
|
215
|
215
|
end
|
|
216
|
216
|
|
|
217
|
217
|
@allowed_projects = Issue.allowed_target_projects
|
|
218
|
218
|
if params[:issue]
|
|
219
|
219
|
@target_project = @allowed_projects.detect {|p| p.id.to_s == params[:issue][:project_id].to_s}
|
|
220
|
220
|
if @target_project
|
|
221
|
221
|
target_projects = [@target_project]
|
|
222
|
222
|
end
|
|
223
|
223
|
end
|
|
224
|
224
|
target_projects ||= @projects
|
|
225
|
225
|
|
|
226
|
226
|
if @copy
|
|
227
|
227
|
# Copied issues will get their default statuses
|
|
228
|
228
|
@available_statuses = []
|
|
229
|
229
|
else
|
|
230
|
230
|
@available_statuses = @issues.map(&:new_statuses_allowed_to).reduce(:&)
|
|
231
|
231
|
end
|
|
232
|
|
@custom_fields = target_projects.map{|p|p.all_issue_custom_fields.visible}.reduce(:&)
|
|
|
232
|
@custom_fields = @issues.map{|i|i.editable_custom_fields}.reduce(:&)
|
|
233
|
233
|
@assignables = target_projects.map(&:assignable_users).reduce(:&)
|
|
234
|
234
|
@trackers = target_projects.map(&:trackers).reduce(:&)
|
|
235
|
235
|
@versions = target_projects.map {|p| p.shared_versions.open}.reduce(:&)
|
|
236
|
236
|
@categories = target_projects.map {|p| p.issue_categories}.reduce(:&)
|
|
237
|
237
|
if @copy
|
|
238
|
238
|
@attachments_present = @issues.detect {|i| i.attachments.any?}.present?
|
|
239
|
239
|
@subtasks_present = @issues.detect {|i| !i.leaf?}.present?
|
|
240
|
240
|
end
|
|
241
|
241
|
|
|
242
|
242
|
@safe_attributes = @issues.map(&:safe_attribute_names).reduce(:&)
|
|
243
|
243
|
|
|
244
|
244
|
@issue_params = params[:issue] || {}
|
|
245
|
245
|
@issue_params[:custom_field_values] ||= {}
|
|
246
|
246
|
end
|
|
247
|
247
|
|
|
248
|
248
|
def bulk_update
|
|
249
|
249
|
@issues.sort!
|
|
250
|
250
|
@copy = params[:copy].present?
|
|
251
|
251
|
attributes = parse_params_for_bulk_issue_attributes(params)
|
|
252
|
252
|
|
|
253
|
253
|
if @copy
|
|
254
|
254
|
unless User.current.allowed_to?(:copy_issues, @projects)
|
|
255
|
255
|
raise ::Unauthorized
|
|
256
|
256
|
end
|
|
257
|
257
|
target_projects = @projects
|
|
258
|
258
|
if attributes['project_id'].present?
|
|
259
|
259
|
target_projects = Project.where(:id => attributes['project_id']).to_a
|
|
260
|
260
|
end
|
|
261
|
261
|
unless User.current.allowed_to?(:add_issues, target_projects)
|
|
262
|
262
|
raise ::Unauthorized
|
|
263
|
263
|
end
|
|
264
|
264
|
end
|
|
265
|
265
|
|
|
266
|
266
|
unsaved_issues = []
|
|
267
|
267
|
saved_issues = []
|
|
268
|
268
|
|
|
269
|
269
|
if @copy && params[:copy_subtasks].present?
|
|
270
|
270
|
# Descendant issues will be copied with the parent task
|
|
271
|
271
|
# Don't copy them twice
|
|
272
|
272
|
@issues.reject! {|issue| @issues.detect {|other| issue.is_descendant_of?(other)}}
|
|
273
|
273
|
end
|
|
274
|
274
|
|
|
275
|
275
|
@issues.each do |orig_issue|
|
|
276
|
276
|
orig_issue.reload
|
|
277
|
277
|
if @copy
|
|
278
|
278
|
issue = orig_issue.copy({},
|
|
279
|
279
|
:attachments => params[:copy_attachments].present?,
|
|
280
|
280
|
:subtasks => params[:copy_subtasks].present?,
|
|
281
|
281
|
:link => link_copy?(params[:link_copy])
|
|
282
|
282
|
)
|
|
283
|
283
|
else
|
|
284
|
284
|
issue = orig_issue
|
|
285
|
285
|
end
|
|
286
|
286
|
journal = issue.init_journal(User.current, params[:notes])
|
|
287
|
287
|
issue.safe_attributes = attributes
|
|
288
|
288
|
call_hook(:controller_issues_bulk_edit_before_save, { :params => params, :issue => issue })
|
|
289
|
289
|
if issue.save
|
|
290
|
290
|
saved_issues << issue
|
|
291
|
291
|
else
|
|
292
|
292
|
unsaved_issues << orig_issue
|
|
293
|
293
|
end
|
|
294
|
294
|
end
|
|
295
|
295
|
|
|
296
|
296
|
if unsaved_issues.empty?
|
|
297
|
297
|
flash[:notice] = l(:notice_successful_update) unless saved_issues.empty?
|
|
298
|
298
|
if params[:follow]
|
|
299
|
299
|
if @issues.size == 1 && saved_issues.size == 1
|
|
300
|
300
|
redirect_to issue_path(saved_issues.first)
|
|
301
|
301
|
elsif saved_issues.map(&:project).uniq.size == 1
|
|
302
|
302
|
redirect_to project_issues_path(saved_issues.map(&:project).first)
|
|
303
|
303
|
end
|
|
304
|
304
|
else
|
|
305
|
305
|
redirect_back_or_default _project_issues_path(@project)
|
|
306
|
306
|
end
|
|
307
|
307
|
else
|
|
308
|
308
|
@saved_issues = @issues
|
|
309
|
309
|
@unsaved_issues = unsaved_issues
|
|
310
|
310
|
@issues = Issue.visible.where(:id => @unsaved_issues.map(&:id)).to_a
|
|
311
|
311
|
bulk_edit
|
|
312
|
312
|
render :action => 'bulk_edit'
|
|
313
|
313
|
end
|
|
314
|
314
|
end
|
|
315
|
315
|
|
|
316
|
316
|
def destroy
|
|
317
|
317
|
@hours = TimeEntry.where(:issue_id => @issues.map(&:id)).sum(:hours).to_f
|
|
318
|
318
|
if @hours > 0
|
|
319
|
319
|
case params[:todo]
|
|
320
|
320
|
when 'destroy'
|
|
321
|
321
|
# nothing to do
|
|
322
|
322
|
when 'nullify'
|
|
323
|
323
|
TimeEntry.where(['issue_id IN (?)', @issues]).update_all('issue_id = NULL')
|
|
324
|
324
|
when 'reassign'
|
|
325
|
325
|
reassign_to = @project.issues.find_by_id(params[:reassign_to_id])
|
|
326
|
326
|
if reassign_to.nil?
|
|
327
|
327
|
flash.now[:error] = l(:error_issue_not_found_in_project)
|
|
328
|
328
|
return
|
|
329
|
329
|
else
|
|
330
|
330
|
TimeEntry.where(['issue_id IN (?)', @issues]).
|
|
331
|
331
|
update_all("issue_id = #{reassign_to.id}")
|
|
332
|
332
|
end
|
|
333
|
333
|
else
|
|
334
|
334
|
# display the destroy form if it's a user request
|
|
335
|
335
|
return unless api_request?
|
|
336
|
336
|
end
|
|
337
|
337
|
end
|
|
338
|
338
|
@issues.each do |issue|
|
|
339
|
339
|
begin
|
|
340
|
340
|
issue.reload.destroy
|
|
341
|
341
|
rescue ::ActiveRecord::RecordNotFound # raised by #reload if issue no longer exists
|
|
342
|
342
|
# nothing to do, issue was already deleted (eg. by a parent)
|
|
343
|
343
|
end
|
|
344
|
344
|
end
|
|
345
|
345
|
respond_to do |format|
|
|
346
|
346
|
format.html { redirect_back_or_default _project_issues_path(@project) }
|
|
347
|
347
|
format.api { render_api_ok }
|
|
348
|
348
|
end
|
|
349
|
349
|
end
|
|
350
|
350
|
|
|
351
|
351
|
private
|
|
352
|
352
|
|
|
353
|
353
|
def retrieve_previous_and_next_issue_ids
|
|
354
|
354
|
retrieve_query_from_session
|
|
355
|
355
|
if @query
|
|
356
|
356
|
sort_init(@query.sort_criteria.empty? ? [['id', 'desc']] : @query.sort_criteria)
|
|
357
|
357
|
sort_update(@query.sortable_columns, 'issues_index_sort')
|
|
358
|
358
|
limit = 500
|
|
359
|
359
|
issue_ids = @query.issue_ids(:order => sort_clause, :limit => (limit + 1), :include => [:assigned_to, :tracker, :priority, :category, :fixed_version])
|
|
360
|
360
|
if (idx = issue_ids.index(@issue.id)) && idx < limit
|
|
361
|
361
|
if issue_ids.size < 500
|
|
362
|
362
|
@issue_position = idx + 1
|
|
363
|
363
|
@issue_count = issue_ids.size
|
|
364
|
364
|
end
|
|
365
|
365
|
@prev_issue_id = issue_ids[idx - 1] if idx > 0
|
|
366
|
366
|
@next_issue_id = issue_ids[idx + 1] if idx < (issue_ids.size - 1)
|
|
367
|
367
|
end
|
|
368
|
368
|
end
|
|
369
|
369
|
end
|
|
370
|
370
|
|
|
371
|
371
|
# Used by #edit and #update to set some common instance variables
|
|
372
|
372
|
# from the params
|
|
373
|
373
|
def update_issue_from_params
|
|
374
|
374
|
@time_entry = TimeEntry.new(:issue => @issue, :project => @issue.project)
|
|
375
|
375
|
if params[:time_entry]
|
|
376
|
376
|
@time_entry.attributes = params[:time_entry]
|
|
377
|
377
|
end
|
|
378
|
378
|
|
|
379
|
379
|
@issue.init_journal(User.current)
|
|
380
|
380
|
|
|
381
|
381
|
issue_attributes = params[:issue]
|
|
382
|
382
|
if issue_attributes && params[:conflict_resolution]
|
|
383
|
383
|
case params[:conflict_resolution]
|
|
384
|
384
|
when 'overwrite'
|
|
385
|
385
|
issue_attributes = issue_attributes.dup
|
|
386
|
386
|
issue_attributes.delete(:lock_version)
|
|
387
|
387
|
when 'add_notes'
|
|
388
|
388
|
issue_attributes = issue_attributes.slice(:notes)
|
|
389
|
389
|
when 'cancel'
|
|
390
|
390
|
redirect_to issue_path(@issue)
|
|
391
|
391
|
return false
|
|
392
|
392
|
end
|
|
393
|
393
|
end
|
|
394
|
394
|
@issue.safe_attributes = issue_attributes
|
|
395
|
395
|
@priorities = IssuePriority.active
|
|
396
|
396
|
@allowed_statuses = @issue.new_statuses_allowed_to(User.current)
|
|
397
|
397
|
true
|
|
398
|
398
|
end
|
|
399
|
399
|
|
|
400
|
400
|
# Used by #new and #create to build a new issue from the params
|
|
401
|
401
|
# The new issue will be copied from an existing one if copy_from parameter is given
|
|
402
|
402
|
def build_new_issue_from_params
|
|
403
|
403
|
@issue = Issue.new
|
|
404
|
404
|
if params[:copy_from]
|
|
405
|
405
|
begin
|
|
406
|
406
|
@issue.init_journal(User.current)
|
|
407
|
407
|
@copy_from = Issue.visible.find(params[:copy_from])
|
|
408
|
408
|
unless User.current.allowed_to?(:copy_issues, @copy_from.project)
|
|
409
|
409
|
raise ::Unauthorized
|
|
410
|
410
|
end
|
|
411
|
411
|
@link_copy = link_copy?(params[:link_copy]) || request.get?
|
|
412
|
412
|
@copy_attachments = params[:copy_attachments].present? || request.get?
|
|
413
|
413
|
@copy_subtasks = params[:copy_subtasks].present? || request.get?
|
|
414
|
414
|
@issue.copy_from(@copy_from, :attachments => @copy_attachments, :subtasks => @copy_subtasks, :link => @link_copy)
|
|
415
|
415
|
rescue ActiveRecord::RecordNotFound
|
|
416
|
416
|
render_404
|
|
417
|
417
|
return
|
|
418
|
418
|
end
|
|
419
|
419
|
end
|
|
420
|
420
|
@issue.project = @project
|
|
421
|
421
|
if request.get?
|
|
422
|
422
|
@issue.project ||= @issue.allowed_target_projects.first
|
|
423
|
423
|
end
|
|
424
|
424
|
@issue.author ||= User.current
|
|
425
|
425
|
@issue.start_date ||= Date.today if Setting.default_issue_start_date_to_creation_date?
|
|
426
|
426
|
|
|
427
|
427
|
if attrs = params[:issue].deep_dup
|
|
428
|
428
|
if params[:was_default_status] == attrs[:status_id]
|
|
429
|
429
|
attrs.delete(:status_id)
|
|
430
|
430
|
end
|
|
431
|
431
|
@issue.safe_attributes = attrs
|
|
432
|
432
|
end
|
|
433
|
433
|
if @issue.project
|
|
434
|
434
|
@issue.tracker ||= @issue.project.trackers.first
|
|
435
|
435
|
if @issue.tracker.nil?
|
|
436
|
436
|
render_error l(:error_no_tracker_in_project)
|
|
437
|
437
|
return false
|
|
438
|
438
|
end
|
|
439
|
439
|
if @issue.status.nil?
|
|
440
|
440
|
render_error l(:error_no_default_issue_status)
|
|
441
|
441
|
return false
|
|
442
|
442
|
end
|
|
443
|
443
|
end
|
|
444
|
444
|
|
|
445
|
445
|
@priorities = IssuePriority.active
|
|
446
|
446
|
@allowed_statuses = @issue.new_statuses_allowed_to(User.current, @issue.new_record?)
|
|
447
|
447
|
end
|
|
448
|
448
|
|
|
449
|
449
|
def parse_params_for_bulk_issue_attributes(params)
|
|
450
|
450
|
attributes = (params[:issue] || {}).reject {|k,v| v.blank?}
|
|
451
|
451
|
attributes.keys.each {|k| attributes[k] = '' if attributes[k] == 'none'}
|
|
452
|
452
|
if custom = attributes[:custom_field_values]
|
|
453
|
453
|
custom.reject! {|k,v| v.blank?}
|
|
454
|
454
|
custom.keys.each do |k|
|
|
455
|
455
|
if custom[k].is_a?(Array)
|
|
456
|
456
|
custom[k] << '' if custom[k].delete('__none__')
|
|
457
|
457
|
else
|
|
458
|
458
|
custom[k] = '' if custom[k] == '__none__'
|
|
459
|
459
|
end
|
|
460
|
460
|
end
|
|
461
|
461
|
end
|
|
462
|
462
|
attributes
|
|
463
|
463
|
end
|
|
464
|
464
|
|
|
465
|
465
|
# Saves @issue and a time_entry from the parameters
|
|
466
|
466
|
def save_issue_with_child_records
|
|
467
|
467
|
Issue.transaction do
|
|
468
|
468
|
if params[:time_entry] && (params[:time_entry][:hours].present? || params[:time_entry][:comments].present?) && User.current.allowed_to?(:log_time, @issue.project)
|
|
469
|
469
|
time_entry = @time_entry || TimeEntry.new
|
|
470
|
470
|
time_entry.project = @issue.project
|
|
471
|
471
|
time_entry.issue = @issue
|
|
472
|
472
|
time_entry.user = User.current
|
|
473
|
473
|
time_entry.spent_on = User.current.today
|
|
474
|
474
|
time_entry.attributes = params[:time_entry]
|
|
475
|
475
|
@issue.time_entries << time_entry
|
|
476
|
476
|
end
|
|
477
|
477
|
|
|
478
|
478
|
call_hook(:controller_issues_edit_before_save, { :params => params, :issue => @issue, :time_entry => time_entry, :journal => @issue.current_journal})
|
|
479
|
479
|
if @issue.save
|
|
480
|
480
|
call_hook(:controller_issues_edit_after_save, { :params => params, :issue => @issue, :time_entry => time_entry, :journal => @issue.current_journal})
|
|
481
|
481
|
else
|
|
482
|
482
|
raise ActiveRecord::Rollback
|
|
483
|
483
|
end
|
|
484
|
484
|
end
|
|
485
|
485
|
end
|
|
486
|
486
|
|
|
487
|
487
|
# Returns true if the issue copy should be linked
|
|
488
|
488
|
# to the original issue
|
|
489
|
489
|
def link_copy?(param)
|
|
490
|
490
|
case Setting.link_copied_issue
|
|
491
|
491
|
when 'yes'
|
|
492
|
492
|
true
|
|
493
|
493
|
when 'no'
|
|
494
|
494
|
false
|
|
495
|
495
|
when 'ask'
|
|
496
|
496
|
param == '1'
|
|
497
|
497
|
end
|
|
498
|
498
|
end
|
|
499
|
499
|
|
|
500
|
500
|
# Redirects user after a successful issue creation
|
|
501
|
501
|
def redirect_after_create
|
|
502
|
502
|
if params[:continue]
|
|
503
|
503
|
attrs = {:tracker_id => @issue.tracker, :parent_issue_id => @issue.parent_issue_id}.reject {|k,v| v.nil?}
|
|
504
|
504
|
if params[:project_id]
|
|
505
|
505
|
redirect_to new_project_issue_path(@issue.project, :issue => attrs)
|
|
506
|
506
|
else
|
|
507
|
507
|
attrs.merge! :project_id => @issue.project_id
|
|
508
|
508
|
redirect_to new_issue_path(:issue => attrs)
|
|
509
|
509
|
end
|
|
510
|
510
|
else
|
|
511
|
511
|
redirect_to issue_path(@issue)
|
|
512
|
512
|
end
|
|
513
|
513
|
end
|
|
514
|
514
|
end
|