@@ -24,6 +24,7 class IssuesController < ApplicationController | |||
|
24 | 24 | before_filter :find_project, :only => [:new, :create, :update_form, :preview, :auto_complete] |
|
25 | 25 | before_filter :authorize, :except => [:index, :changes, :gantt, :calendar, :preview, :context_menu] |
|
26 | 26 | before_filter :find_optional_project, :only => [:index, :changes, :gantt, :calendar] |
|
27 | before_filter :build_new_issue_from_params, :only => [:new, :create] | |
|
27 | 28 | accept_key_auth :index, :show, :changes |
|
28 | 29 | |
|
29 | 30 | rescue_from Query::StatementInvalid, :with => :query_statement_invalid |
@@ -128,53 +129,10 class IssuesController < ApplicationController | |||
|
128 | 129 | # Add a new issue |
|
129 | 130 | # The new issue will be created from an existing one if copy_from parameter is given |
|
130 | 131 | def new |
|
131 | @issue = Issue.new | |
|
132 | @issue.copy_from(params[:copy_from]) if params[:copy_from] | |
|
133 | @issue.project = @project | |
|
134 | # Tracker must be set before custom field values | |
|
135 | @issue.tracker ||= @project.trackers.find((params[:issue] && params[:issue][:tracker_id]) || params[:tracker_id] || :first) | |
|
136 | if @issue.tracker.nil? | |
|
137 | render_error l(:error_no_tracker_in_project) | |
|
138 | return | |
|
139 | end | |
|
140 | if @issue.status.nil? | |
|
141 | render_error l(:error_no_default_issue_status) | |
|
142 | return | |
|
143 | end | |
|
144 | if params[:issue].is_a?(Hash) | |
|
145 | @issue.safe_attributes = params[:issue] | |
|
146 | @issue.watcher_user_ids = params[:issue]['watcher_user_ids'] if User.current.allowed_to?(:add_issue_watchers, @project) | |
|
147 | end | |
|
148 | @issue.author = User.current | |
|
149 | @issue.start_date ||= Date.today | |
|
150 | @priorities = IssuePriority.all | |
|
151 | @allowed_statuses = @issue.new_statuses_allowed_to(User.current, true) | |
|
152 | 132 | render :action => 'new', :layout => !request.xhr? |
|
153 | 133 | end |
|
154 | 134 | |
|
155 | 135 | def create |
|
156 | @issue = Issue.new | |
|
157 | @issue.copy_from(params[:copy_from]) if params[:copy_from] | |
|
158 | @issue.project = @project | |
|
159 | # Tracker must be set before custom field values | |
|
160 | @issue.tracker ||= @project.trackers.find((params[:issue] && params[:issue][:tracker_id]) || params[:tracker_id] || :first) | |
|
161 | if @issue.tracker.nil? | |
|
162 | render_error l(:error_no_tracker_in_project) | |
|
163 | return | |
|
164 | end | |
|
165 | if @issue.status.nil? | |
|
166 | render_error l(:error_no_default_issue_status) | |
|
167 | return | |
|
168 | end | |
|
169 | if params[:issue].is_a?(Hash) | |
|
170 | @issue.safe_attributes = params[:issue] | |
|
171 | @issue.watcher_user_ids = params[:issue]['watcher_user_ids'] if User.current.allowed_to?(:add_issue_watchers, @project) | |
|
172 | end | |
|
173 | @issue.author = User.current | |
|
174 | ||
|
175 | @priorities = IssuePriority.all | |
|
176 | @allowed_statuses = @issue.new_statuses_allowed_to(User.current, true) | |
|
177 | ||
|
178 | 136 | call_hook(:controller_issues_new_before_save, { :params => params, :issue => @issue }) |
|
179 | 137 | if @issue.save |
|
180 | 138 | attachments = Attachment.attach_files(@issue, params[:attachments]) |
@@ -588,6 +546,31 private | |||
|
588 | 546 | |
|
589 | 547 | end |
|
590 | 548 | |
|
549 | # TODO: Refactor, lots of extra code in here | |
|
550 | def build_new_issue_from_params | |
|
551 | @issue = Issue.new | |
|
552 | @issue.copy_from(params[:copy_from]) if params[:copy_from] | |
|
553 | @issue.project = @project | |
|
554 | # Tracker must be set before custom field values | |
|
555 | @issue.tracker ||= @project.trackers.find((params[:issue] && params[:issue][:tracker_id]) || params[:tracker_id] || :first) | |
|
556 | if @issue.tracker.nil? | |
|
557 | render_error l(:error_no_tracker_in_project) | |
|
558 | return false | |
|
559 | end | |
|
560 | if @issue.status.nil? | |
|
561 | render_error l(:error_no_default_issue_status) | |
|
562 | return false | |
|
563 | end | |
|
564 | if params[:issue].is_a?(Hash) | |
|
565 | @issue.safe_attributes = params[:issue] | |
|
566 | @issue.watcher_user_ids = params[:issue]['watcher_user_ids'] if User.current.allowed_to?(:add_issue_watchers, @project) | |
|
567 | end | |
|
568 | @issue.author = User.current | |
|
569 | @issue.start_date ||= Date.today | |
|
570 | @priorities = IssuePriority.all | |
|
571 | @allowed_statuses = @issue.new_statuses_allowed_to(User.current, true) | |
|
572 | end | |
|
573 | ||
|
591 | 574 | def set_flash_from_bulk_issue_save(issues, unsaved_issue_ids) |
|
592 | 575 | if unsaved_issue_ids.empty? |
|
593 | 576 | flash[:notice] = l(:notice_successful_update) unless issues.empty? |
General Comments 0
You need to be logged in to leave comments.
Login now