@@ -21,7 +21,7 class IssuesController < ApplicationController | |||||
21 |
|
21 | |||
22 | before_filter :find_issue, :only => [:show, :edit, :update, :reply] |
|
22 | before_filter :find_issue, :only => [:show, :edit, :update, :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, :auto_complete] |
|
24 | before_filter :find_project, :only => [:new, :create, :update_form, :preview, :auto_complete] | |
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 | |
@@ -51,6 +51,7 class IssuesController < ApplicationController | |||||
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 | verify :method => :post, :only => :create, :render => {:nothing => true, :status => :method_not_allowed } | |||
54 | verify :method => :put, :only => :update, :render => {:nothing => true, :status => :method_not_allowed } |
|
55 | verify :method => :put, :only => :update, :render => {:nothing => true, :status => :method_not_allowed } | |
55 |
|
56 | |||
56 | def index |
|
57 | def index | |
@@ -145,35 +146,55 class IssuesController < ApplicationController | |||||
145 | @issue.watcher_user_ids = params[:issue]['watcher_user_ids'] if User.current.allowed_to?(:add_issue_watchers, @project) |
|
146 | @issue.watcher_user_ids = params[:issue]['watcher_user_ids'] if User.current.allowed_to?(:add_issue_watchers, @project) | |
146 | end |
|
147 | end | |
147 | @issue.author = User.current |
|
148 | @issue.author = User.current | |
148 |
|
149 | @issue.start_date ||= Date.today | ||
149 | if request.get? || request.xhr? |
|
150 | @priorities = IssuePriority.all | |
150 | @issue.start_date ||= Date.today |
|
151 | @allowed_statuses = @issue.new_statuses_allowed_to(User.current, true) | |
151 | else |
|
152 | render :action => 'new', :layout => !request.xhr? | |
152 | call_hook(:controller_issues_new_before_save, { :params => params, :issue => @issue }) |
|
153 | end | |
153 | if @issue.save |
|
154 | ||
154 | attachments = Attachment.attach_files(@issue, params[:attachments]) |
|
155 | def create | |
155 | render_attachment_warning_if_needed(@issue) |
|
156 | @issue = Issue.new | |
156 | flash[:notice] = l(:notice_successful_create) |
|
157 | @issue.copy_from(params[:copy_from]) if params[:copy_from] | |
157 | call_hook(:controller_issues_new_after_save, { :params => params, :issue => @issue}) |
|
158 | @issue.project = @project | |
158 | respond_to do |format| |
|
159 | # Tracker must be set before custom field values | |
159 | format.html { |
|
160 | @issue.tracker ||= @project.trackers.find((params[:issue] && params[:issue][:tracker_id]) || params[:tracker_id] || :first) | |
160 | redirect_to(params[:continue] ? { :action => 'new', :issue => {:tracker_id => @issue.tracker, |
|
161 | if @issue.tracker.nil? | |
161 | :parent_issue_id => @issue.parent_issue_id}.reject {|k,v| v.nil?} } : |
|
162 | render_error l(:error_no_tracker_in_project) | |
162 | { :action => 'show', :id => @issue }) |
|
163 | return | |
163 | } |
|
164 | end | |
164 | format.xml { render :action => 'show', :status => :created, :location => url_for(:controller => 'issues', :action => 'show', :id => @issue) } |
|
165 | if @issue.status.nil? | |
165 | end |
|
166 | render_error l(:error_no_default_issue_status) | |
166 |
|
|
167 | return | |
167 | else |
|
168 | end | |
168 | respond_to do |format| |
|
169 | if params[:issue].is_a?(Hash) | |
169 | format.html { } |
|
170 | @issue.safe_attributes = params[:issue] | |
170 | format.xml { render(:xml => @issue.errors, :status => :unprocessable_entity); return } |
|
171 | @issue.watcher_user_ids = params[:issue]['watcher_user_ids'] if User.current.allowed_to?(:add_issue_watchers, @project) | |
171 |
|
|
172 | end | |
172 | end |
|
173 | @issue.author = User.current | |
173 | end |
|
174 | ||
174 | @priorities = IssuePriority.all |
|
175 | @priorities = IssuePriority.all | |
175 | @allowed_statuses = @issue.new_statuses_allowed_to(User.current, true) |
|
176 | @allowed_statuses = @issue.new_statuses_allowed_to(User.current, true) | |
176 | render :layout => !request.xhr? |
|
177 | ||
|
178 | call_hook(:controller_issues_new_before_save, { :params => params, :issue => @issue }) | |||
|
179 | if @issue.save | |||
|
180 | attachments = Attachment.attach_files(@issue, params[:attachments]) | |||
|
181 | render_attachment_warning_if_needed(@issue) | |||
|
182 | flash[:notice] = l(:notice_successful_create) | |||
|
183 | call_hook(:controller_issues_new_after_save, { :params => params, :issue => @issue}) | |||
|
184 | respond_to do |format| | |||
|
185 | format.html { | |||
|
186 | redirect_to(params[:continue] ? { :action => 'new', :issue => {:tracker_id => @issue.tracker, :parent_issue_id => @issue.parent_issue_id}.reject {|k,v| v.nil?} } : | |||
|
187 | { :action => 'show', :id => @issue }) | |||
|
188 | } | |||
|
189 | format.xml { render :action => 'show', :status => :created, :location => url_for(:controller => 'issues', :action => 'show', :id => @issue) } | |||
|
190 | end | |||
|
191 | return | |||
|
192 | else | |||
|
193 | respond_to do |format| | |||
|
194 | format.html { render :action => 'new' } | |||
|
195 | format.xml { render(:xml => @issue.errors, :status => :unprocessable_entity); return } | |||
|
196 | end | |||
|
197 | end | |||
177 | end |
|
198 | end | |
178 |
|
199 | |||
179 | # Attributes that can be updated on workflow transition (without :edit permission) |
|
200 | # Attributes that can be updated on workflow transition (without :edit permission) |
@@ -1,6 +1,6 | |||||
1 | <h2><%=l(:label_issue_new)%></h2> |
|
1 | <h2><%=l(:label_issue_new)%></h2> | |
2 |
|
2 | |||
3 | <% labelled_tabular_form_for :issue, @issue, |
|
3 | <% labelled_tabular_form_for :issue, @issue, :url => {:controller => 'issues', :action => 'create', :project_id => @project}, | |
4 | :html => {:multipart => true, :id => 'issue-form'} do |f| %> |
|
4 | :html => {:multipart => true, :id => 'issue-form'} do |f| %> | |
5 | <%= error_messages_for 'issue' %> |
|
5 | <%= error_messages_for 'issue' %> | |
6 | <div class="box"> |
|
6 | <div class="box"> |
@@ -120,10 +120,10 ActionController::Routing::Routes.draw do |map| | |||||
120 | end |
|
120 | end | |
121 | issues_routes.with_options :conditions => {:method => :post} do |issues_actions| |
|
121 | issues_routes.with_options :conditions => {:method => :post} do |issues_actions| | |
122 | issues_actions.connect 'issues', :action => 'index' |
|
122 | issues_actions.connect 'issues', :action => 'index' | |
123 |
issues_actions.connect 'projects/:project_id/issues', :action => ' |
|
123 | issues_actions.connect 'projects/:project_id/issues', :action => 'create' | |
124 | issues_actions.connect 'issues/:id/quoted', :action => 'reply', :id => /\d+/ |
|
124 | issues_actions.connect 'issues/:id/quoted', :action => 'reply', :id => /\d+/ | |
125 | issues_actions.connect 'issues/:id/:action', :action => /edit|move|destroy/, :id => /\d+/ |
|
125 | issues_actions.connect 'issues/:id/:action', :action => /edit|move|destroy/, :id => /\d+/ | |
126 |
issues_actions.connect 'issues.:format', :action => ' |
|
126 | issues_actions.connect 'issues.:format', :action => 'create', :format => /xml/ | |
127 | end |
|
127 | end | |
128 | issues_routes.with_options :conditions => {:method => :put} do |issues_actions| |
|
128 | issues_routes.with_options :conditions => {:method => :put} do |issues_actions| | |
129 | issues_actions.connect 'issues/:id/edit', :action => 'update', :id => /\d+/ |
|
129 | issues_actions.connect 'issues/:id/edit', :action => 'update', :id => /\d+/ |
@@ -62,7 +62,7 Redmine::AccessControl.map do |map| | |||||
62 | :versions => [:show, :status_by], |
|
62 | :versions => [:show, :status_by], | |
63 | :queries => :index, |
|
63 | :queries => :index, | |
64 | :reports => [:issue_report, :issue_report_details]} |
|
64 | :reports => [:issue_report, :issue_report_details]} | |
65 | map.permission :add_issues, {:issues => [:new, :update_form]} |
|
65 | map.permission :add_issues, {:issues => [:new, :create, :update_form]} | |
66 | map.permission :edit_issues, {:issues => [:edit, :update, :reply, :bulk_edit, :update_form]} |
|
66 | map.permission :edit_issues, {:issues => [:edit, :update, :reply, :bulk_edit, :update_form]} | |
67 | map.permission :manage_issue_relations, {:issue_relations => [:new, :destroy]} |
|
67 | map.permission :manage_issue_relations, {:issue_relations => [:new, :destroy]} | |
68 | map.permission :manage_subtasks, {} |
|
68 | map.permission :manage_subtasks, {} |
@@ -446,10 +446,10 class IssuesControllerTest < ActionController::TestCase | |||||
446 | assert_equal 'This is the test_new issue', issue.subject |
|
446 | assert_equal 'This is the test_new issue', issue.subject | |
447 | end |
|
447 | end | |
448 |
|
448 | |||
449 |
def test_post_ |
|
449 | def test_post_create | |
450 | @request.session[:user_id] = 2 |
|
450 | @request.session[:user_id] = 2 | |
451 | assert_difference 'Issue.count' do |
|
451 | assert_difference 'Issue.count' do | |
452 |
post : |
|
452 | post :create, :project_id => 1, | |
453 | :issue => {:tracker_id => 3, |
|
453 | :issue => {:tracker_id => 3, | |
454 | :status_id => 2, |
|
454 | :status_id => 2, | |
455 | :subject => 'This is the test_new issue', |
|
455 | :subject => 'This is the test_new issue', | |
@@ -471,9 +471,9 class IssuesControllerTest < ActionController::TestCase | |||||
471 | assert_equal 'Value for field 2', v.value |
|
471 | assert_equal 'Value for field 2', v.value | |
472 | end |
|
472 | end | |
473 |
|
473 | |||
474 |
def test_post_ |
|
474 | def test_post_create_and_continue | |
475 | @request.session[:user_id] = 2 |
|
475 | @request.session[:user_id] = 2 | |
476 |
post : |
|
476 | post :create, :project_id => 1, | |
477 | :issue => {:tracker_id => 3, |
|
477 | :issue => {:tracker_id => 3, | |
478 | :subject => 'This is first issue', |
|
478 | :subject => 'This is first issue', | |
479 | :priority_id => 5}, |
|
479 | :priority_id => 5}, | |
@@ -481,10 +481,10 class IssuesControllerTest < ActionController::TestCase | |||||
481 | assert_redirected_to :controller => 'issues', :action => 'new', :issue => {:tracker_id => 3} |
|
481 | assert_redirected_to :controller => 'issues', :action => 'new', :issue => {:tracker_id => 3} | |
482 | end |
|
482 | end | |
483 |
|
483 | |||
484 |
def test_post_ |
|
484 | def test_post_create_without_custom_fields_param | |
485 | @request.session[:user_id] = 2 |
|
485 | @request.session[:user_id] = 2 | |
486 | assert_difference 'Issue.count' do |
|
486 | assert_difference 'Issue.count' do | |
487 |
post : |
|
487 | post :create, :project_id => 1, | |
488 | :issue => {:tracker_id => 1, |
|
488 | :issue => {:tracker_id => 1, | |
489 | :subject => 'This is the test_new issue', |
|
489 | :subject => 'This is the test_new issue', | |
490 | :description => 'This is the description', |
|
490 | :description => 'This is the description', | |
@@ -493,12 +493,12 class IssuesControllerTest < ActionController::TestCase | |||||
493 | assert_redirected_to :controller => 'issues', :action => 'show', :id => Issue.last.id |
|
493 | assert_redirected_to :controller => 'issues', :action => 'show', :id => Issue.last.id | |
494 | end |
|
494 | end | |
495 |
|
495 | |||
496 |
def test_post_ |
|
496 | def test_post_create_with_required_custom_field_and_without_custom_fields_param | |
497 | field = IssueCustomField.find_by_name('Database') |
|
497 | field = IssueCustomField.find_by_name('Database') | |
498 | field.update_attribute(:is_required, true) |
|
498 | field.update_attribute(:is_required, true) | |
499 |
|
499 | |||
500 | @request.session[:user_id] = 2 |
|
500 | @request.session[:user_id] = 2 | |
501 |
post : |
|
501 | post :create, :project_id => 1, | |
502 | :issue => {:tracker_id => 1, |
|
502 | :issue => {:tracker_id => 1, | |
503 | :subject => 'This is the test_new issue', |
|
503 | :subject => 'This is the test_new issue', | |
504 | :description => 'This is the description', |
|
504 | :description => 'This is the description', | |
@@ -510,12 +510,12 class IssuesControllerTest < ActionController::TestCase | |||||
510 | assert_equal I18n.translate('activerecord.errors.messages.invalid'), issue.errors.on(:custom_values) |
|
510 | assert_equal I18n.translate('activerecord.errors.messages.invalid'), issue.errors.on(:custom_values) | |
511 | end |
|
511 | end | |
512 |
|
512 | |||
513 |
def test_post_ |
|
513 | def test_post_create_with_watchers | |
514 | @request.session[:user_id] = 2 |
|
514 | @request.session[:user_id] = 2 | |
515 | ActionMailer::Base.deliveries.clear |
|
515 | ActionMailer::Base.deliveries.clear | |
516 |
|
516 | |||
517 | assert_difference 'Watcher.count', 2 do |
|
517 | assert_difference 'Watcher.count', 2 do | |
518 |
post : |
|
518 | post :create, :project_id => 1, | |
519 | :issue => {:tracker_id => 1, |
|
519 | :issue => {:tracker_id => 1, | |
520 | :subject => 'This is a new issue with watchers', |
|
520 | :subject => 'This is a new issue with watchers', | |
521 | :description => 'This is the description', |
|
521 | :description => 'This is the description', | |
@@ -535,11 +535,11 class IssuesControllerTest < ActionController::TestCase | |||||
535 | assert [mail.bcc, mail.cc].flatten.include?(User.find(3).mail) |
|
535 | assert [mail.bcc, mail.cc].flatten.include?(User.find(3).mail) | |
536 | end |
|
536 | end | |
537 |
|
537 | |||
538 |
def test_post_ |
|
538 | def test_post_create_subissue | |
539 | @request.session[:user_id] = 2 |
|
539 | @request.session[:user_id] = 2 | |
540 |
|
540 | |||
541 | assert_difference 'Issue.count' do |
|
541 | assert_difference 'Issue.count' do | |
542 |
post : |
|
542 | post :create, :project_id => 1, | |
543 | :issue => {:tracker_id => 1, |
|
543 | :issue => {:tracker_id => 1, | |
544 | :subject => 'This is a child issue', |
|
544 | :subject => 'This is a child issue', | |
545 | :parent_issue_id => 2} |
|
545 | :parent_issue_id => 2} | |
@@ -549,11 +549,11 class IssuesControllerTest < ActionController::TestCase | |||||
549 | assert_equal Issue.find(2), issue.parent |
|
549 | assert_equal Issue.find(2), issue.parent | |
550 | end |
|
550 | end | |
551 |
|
551 | |||
552 |
def test_post_ |
|
552 | def test_post_create_should_send_a_notification | |
553 | ActionMailer::Base.deliveries.clear |
|
553 | ActionMailer::Base.deliveries.clear | |
554 | @request.session[:user_id] = 2 |
|
554 | @request.session[:user_id] = 2 | |
555 | assert_difference 'Issue.count' do |
|
555 | assert_difference 'Issue.count' do | |
556 |
post : |
|
556 | post :create, :project_id => 1, | |
557 | :issue => {:tracker_id => 3, |
|
557 | :issue => {:tracker_id => 3, | |
558 | :subject => 'This is the test_new issue', |
|
558 | :subject => 'This is the test_new issue', | |
559 | :description => 'This is the description', |
|
559 | :description => 'This is the description', | |
@@ -566,9 +566,9 class IssuesControllerTest < ActionController::TestCase | |||||
566 | assert_equal 1, ActionMailer::Base.deliveries.size |
|
566 | assert_equal 1, ActionMailer::Base.deliveries.size | |
567 | end |
|
567 | end | |
568 |
|
568 | |||
569 | def test_post_should_preserve_fields_values_on_validation_failure |
|
569 | def test_post_create_should_preserve_fields_values_on_validation_failure | |
570 | @request.session[:user_id] = 2 |
|
570 | @request.session[:user_id] = 2 | |
571 |
post : |
|
571 | post :create, :project_id => 1, | |
572 | :issue => {:tracker_id => 1, |
|
572 | :issue => {:tracker_id => 1, | |
573 | # empty subject |
|
573 | # empty subject | |
574 | :subject => '', |
|
574 | :subject => '', | |
@@ -593,10 +593,10 class IssuesControllerTest < ActionController::TestCase | |||||
593 | :value => 'Value for field 2'} |
|
593 | :value => 'Value for field 2'} | |
594 | end |
|
594 | end | |
595 |
|
595 | |||
596 |
def test_post_ |
|
596 | def test_post_create_should_ignore_non_safe_attributes | |
597 | @request.session[:user_id] = 2 |
|
597 | @request.session[:user_id] = 2 | |
598 | assert_nothing_raised do |
|
598 | assert_nothing_raised do | |
599 |
post : |
|
599 | post :create, :project_id => 1, :issue => { :tracker => "A param can not be a Tracker" } | |
600 | end |
|
600 | end | |
601 | end |
|
601 | end | |
602 |
|
602 | |||
@@ -619,7 +619,7 class IssuesControllerTest < ActionController::TestCase | |||||
619 |
|
619 | |||
620 | should "accept default status" do |
|
620 | should "accept default status" do | |
621 | assert_difference 'Issue.count' do |
|
621 | assert_difference 'Issue.count' do | |
622 |
post : |
|
622 | post :create, :project_id => 1, | |
623 | :issue => {:tracker_id => 1, |
|
623 | :issue => {:tracker_id => 1, | |
624 | :subject => 'This is an issue', |
|
624 | :subject => 'This is an issue', | |
625 | :status_id => 1} |
|
625 | :status_id => 1} | |
@@ -630,7 +630,7 class IssuesControllerTest < ActionController::TestCase | |||||
630 |
|
630 | |||
631 | should "ignore unauthorized status" do |
|
631 | should "ignore unauthorized status" do | |
632 | assert_difference 'Issue.count' do |
|
632 | assert_difference 'Issue.count' do | |
633 |
post : |
|
633 | post :create, :project_id => 1, | |
634 | :issue => {:tracker_id => 1, |
|
634 | :issue => {:tracker_id => 1, | |
635 | :subject => 'This is an issue', |
|
635 | :subject => 'This is an issue', | |
636 | :status_id => 3} |
|
636 | :status_id => 3} |
@@ -70,7 +70,8 class RoutingTest < ActionController::IntegrationTest | |||||
70 | should_route :get, "/issues/64.xml", :controller => 'issues', :action => 'show', :id => '64', :format => 'xml' |
|
70 | should_route :get, "/issues/64.xml", :controller => 'issues', :action => 'show', :id => '64', :format => 'xml' | |
71 |
|
71 | |||
72 | should_route :get, "/projects/23/issues/new", :controller => 'issues', :action => 'new', :project_id => '23' |
|
72 | should_route :get, "/projects/23/issues/new", :controller => 'issues', :action => 'new', :project_id => '23' | |
73 |
should_route :post, "/issues |
|
73 | should_route :post, "/projects/23/issues", :controller => 'issues', :action => 'create', :project_id => '23' | |
|
74 | should_route :post, "/issues.xml", :controller => 'issues', :action => 'create', :format => 'xml' | |||
74 |
|
75 | |||
75 | should_route :get, "/issues/64/edit", :controller => 'issues', :action => 'edit', :id => '64' |
|
76 | should_route :get, "/issues/64/edit", :controller => 'issues', :action => 'edit', :id => '64' | |
76 | # TODO: Should use PUT |
|
77 | # TODO: Should use PUT |
General Comments 0
You need to be logged in to leave comments.
Login now