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