Project

General

Profile

« Previous | Next » 

Revision 13997

Removed IssuesController#update_form action, use #new and #edit instead.

View differences:

trunk/app/controllers/issues_controller.rb
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
  before_filter :find_project, :only => [:new, :create, :update_form]
24
  before_filter :find_project, :only => [:new, :create]
25 25
  before_filter :authorize, :except => [:index]
26 26
  before_filter :find_optional_project, :only => [:index]
27
  before_filter :build_new_issue_from_params, :only => [:new, :create, :update_form]
27
  before_filter :build_new_issue_from_params, :only => [:new, :create]
28 28
  accept_rss_auth :index, :show
29 29
  accept_api_auth :index, :show, :create, :update, :destroy
30 30

  
......
138 138
  def new
139 139
    respond_to do |format|
140 140
      format.html { render :action => 'new', :layout => !request.xhr? }
141
      format.js
141 142
    end
142 143
  end
143 144

  
......
176 177

  
177 178
    respond_to do |format|
178 179
      format.html { }
180
      format.js
179 181
      format.xml  { }
180 182
    end
181 183
  end
......
210 212
    end
211 213
  end
212 214

  
213
  # Updates the issue form when changing the project, status or tracker
214
  # on issue creation/update
215
  def update_form
216
  end
217

  
218 215
  # Bulk edit/copy a set of issues
219 216
  def bulk_edit
220 217
    @issues.sort!
......
419 416
  end
420 417

  
421 418
  # TODO: Refactor, lots of extra code in here
422
  # TODO: Changing tracker on an existing issue should not trigger this
423 419
  def build_new_issue_from_params
424
    if params[:id].blank?
425
      @issue = Issue.new
426
      if params[:copy_from]
427
        begin
428
          @issue.init_journal(User.current)
429
          @copy_from = Issue.visible.find(params[:copy_from])
430
          unless User.current.allowed_to?(:copy_issues, @copy_from.project)
431
            raise ::Unauthorized
432
          end
433
          @link_copy = link_copy?(params[:link_copy]) || request.get?
434
          @copy_attachments = params[:copy_attachments].present? || request.get?
435
          @copy_subtasks = params[:copy_subtasks].present? || request.get?
436
          @issue.copy_from(@copy_from, :attachments => @copy_attachments, :subtasks => @copy_subtasks, :link => @link_copy)
437
        rescue ActiveRecord::RecordNotFound
438
          render_404
439
          return
420
    @issue = Issue.new
421
    if params[:copy_from]
422
      begin
423
        @issue.init_journal(User.current)
424
        @copy_from = Issue.visible.find(params[:copy_from])
425
        unless User.current.allowed_to?(:copy_issues, @copy_from.project)
426
          raise ::Unauthorized
440 427
        end
428
        @link_copy = link_copy?(params[:link_copy]) || request.get?
429
        @copy_attachments = params[:copy_attachments].present? || request.get?
430
        @copy_subtasks = params[:copy_subtasks].present? || request.get?
431
        @issue.copy_from(@copy_from, :attachments => @copy_attachments, :subtasks => @copy_subtasks, :link => @link_copy)
432
      rescue ActiveRecord::RecordNotFound
433
        render_404
434
        return
441 435
      end
442
      @issue.project = @project
443
      @issue.author ||= User.current
444
      @issue.start_date ||= Date.today if Setting.default_issue_start_date_to_creation_date?
445
    else
446
      @issue = @project.issues.visible.find(params[:id])
447 436
    end
437
    @issue.project = @project
438
    @issue.author ||= User.current
439
    @issue.start_date ||= Date.today if Setting.default_issue_start_date_to_creation_date?
448 440

  
449 441
    if attrs = params[:issue].deep_dup
450 442
      if params[:was_default_status] == attrs[:status_id]
trunk/app/helpers/issues_helper.rb
199 199
    s.html_safe
200 200
  end
201 201

  
202
  # Returns the path for updating the issue form
203
  # with project as the current project
204
  def update_issue_form_path(project, issue)
205
    if issue.new_record?
206
      new_project_issue_path(project, :format => 'js')
207
    else
208
      edit_issue_path(issue, :format => 'js')
209
    end
210
  end
211

  
202 212
  # Returns the number of descendants for an array of issues
203 213
  def issues_descendant_count(issues)
204 214
    ids = issues.reject(&:leaf?).map {|issue| issue.descendants.ids}.flatten.uniq
trunk/app/views/issues/update_form.js.erb
1
replaceIssueFormWith('<%= escape_javascript(render :partial => 'form') %>');
2

  
3
<% if User.current.allowed_to?(:log_time, @issue.project) %>
4
  $('#log_time').show();
5
<% else %>
6
  $('#log_time').hide();
7
<% end %>
8 0

  
trunk/app/views/issues/_attributes.html.erb
4 4
<div class="splitcontentleft">
5 5
<% if @issue.safe_attribute?('status_id') && @allowed_statuses.present? %>
6 6
<p><%= f.select :status_id, (@allowed_statuses.collect {|p| [p.name, p.id]}), {:required => true},
7
                :onchange => "updateIssueFrom('#{escape_javascript project_issue_form_path(@project, :id => @issue, :format => 'js')}')" %></p>
7
                :onchange => "updateIssueFrom('#{escape_javascript update_issue_form_path(@project, @issue)}')" %></p>
8 8
<%= hidden_field_tag 'was_default_status', @issue.status_id, :id => nil if @issue.status == @issue.default_status %>
9 9
<% else %>
10 10
<p><label><%= l(:field_status) %></label> <%= @issue.status %></p>
trunk/app/views/issues/_form.html.erb
9 9

  
10 10
<% if @issue.safe_attribute? 'project_id' %>
11 11
<p><%= f.select :project_id, project_tree_options_for_select(@issue.allowed_target_projects, :selected => @issue.project), {:required => true},
12
                :onchange => "updateIssueFrom('#{escape_javascript project_issue_form_path(@project, :id => @issue, :format => 'js')}')" %></p>
12
                :onchange => "updateIssueFrom('#{escape_javascript update_issue_form_path(@project, @issue)}')" %></p>
13 13
<% end %>
14 14

  
15 15
<% if @issue.safe_attribute? 'tracker_id' %>
16 16
<p><%= f.select :tracker_id, @issue.project.trackers.collect {|t| [t.name, t.id]}, {:required => true},
17
                :onchange => "updateIssueFrom('#{escape_javascript project_issue_form_path(@project, :id => @issue, :format => 'js')}')" %></p>
17
                :onchange => "updateIssueFrom('#{escape_javascript update_issue_form_path(@project, @issue)}')" %></p>
18 18
<% end %>
19 19

  
20 20
<% if @issue.safe_attribute? 'subject' %>
trunk/app/views/issues/edit.js.erb
1
replaceIssueFormWith('<%= escape_javascript(render :partial => 'form') %>');
2

  
3
<% if User.current.allowed_to?(:log_time, @issue.project) %>
4
  $('#log_time').show();
5
<% else %>
6
  $('#log_time').hide();
7
<% end %>
0 8

  
trunk/app/views/issues/new.js.erb
1
replaceIssueFormWith('<%= escape_javascript(render :partial => 'form') %>');
0 2

  
trunk/config/routes.rb
112 112

  
113 113
    get 'issues/:copy_from/copy', :to => 'issues#new', :as => 'copy_issue'
114 114
    resources :issues, :only => [:index, :new, :create]
115
    # issue form update
116
    match 'issues/update_form', :controller => 'issues', :action => 'update_form', :via => [:put, :patch, :post], :as => 'issue_form'
115
    # Used when updating the form of a new issue
116
    post 'issues/new', :to => 'issues#new'
117 117

  
118 118
    resources :files, :only => [:index, :new, :create]
119 119

  
......
168 168
  end
169 169

  
170 170
  resources :issues do
171
    member do
172
      # Used when updating the form of an existing issue
173
      patch 'edit', :to => 'issues#edit'
174
    end
171 175
    collection do
172 176
      match 'bulk_edit', :via => [:get, :post]
173 177
      post 'bulk_update'
trunk/lib/redmine.rb
98 98
                                  :queries => :index,
99 99
                                  :reports => [:issue_report, :issue_report_details]},
100 100
                                  :read => true
101
    map.permission :add_issues, {:issues => [:new, :create, :update_form], :attachments => :upload}
102
    map.permission :edit_issues, {:issues => [:edit, :update, :bulk_edit, :bulk_update, :update_form], :journals => [:new], :attachments => :upload}
103
    map.permission :copy_issues, {:issues => [:new, :create, :bulk_edit, :bulk_update, :update_form], :attachments => :upload}
101
    map.permission :add_issues, {:issues => [:new, :create], :attachments => :upload}
102
    map.permission :edit_issues, {:issues => [:edit, :update, :bulk_edit, :bulk_update], :journals => [:new], :attachments => :upload}
103
    map.permission :copy_issues, {:issues => [:new, :create, :bulk_edit, :bulk_update], :attachments => :upload}
104 104
    map.permission :manage_issue_relations, {:issue_relations => [:index, :show, :create, :destroy]}
105 105
    map.permission :manage_subtasks, {}
106 106
    map.permission :set_issues_private, {}
107 107
    map.permission :set_own_issues_private, {}, :require => :loggedin
108
    map.permission :add_issue_notes, {:issues => [:edit, :update, :update_form], :journals => [:new], :attachments => :upload}
108
    map.permission :add_issue_notes, {:issues => [:edit, :update], :journals => [:new], :attachments => :upload}
109 109
    map.permission :edit_issue_notes, {:journals => :edit}, :require => :loggedin
110 110
    map.permission :edit_own_issue_notes, {:journals => :edit}, :require => :loggedin
111 111
    map.permission :view_private_notes, {}, :read => true, :require => :member
trunk/test/functional/issues_controller_test.rb
1757 1757

  
1758 1758
  def test_update_form_for_new_issue
1759 1759
    @request.session[:user_id] = 2
1760
    xhr :post, :update_form, :project_id => 1,
1760
    xhr :post, :new, :project_id => 1,
1761 1761
                     :issue => {:tracker_id => 2,
1762 1762
                                :subject => 'This is the test_new issue',
1763 1763
                                :description => 'This is the description',
1764 1764
                                :priority_id => 5}
1765 1765
    assert_response :success
1766
    assert_template 'update_form'
1766
    assert_template 'new'
1767 1767
    assert_template :partial => '_form'
1768 1768
    assert_equal 'text/javascript', response.content_type
1769 1769

  
......
1781 1781
    WorkflowTransition.create!(:role_id => 1, :tracker_id => 1, :old_status_id => 1, :new_status_id => 5)
1782 1782
    WorkflowTransition.create!(:role_id => 1, :tracker_id => 1, :old_status_id => 5, :new_status_id => 4)
1783 1783

  
1784
    xhr :post, :update_form, :project_id => 1,
1784
    xhr :post, :new, :project_id => 1,
1785 1785
                     :issue => {:tracker_id => 1,
1786 1786
                                :status_id => 5,
1787 1787
                                :subject => 'This is an issue'}
......
1796 1796
    tracker.update! :default_status_id => 2
1797 1797
    tracker.generate_transitions! 2, 1, :clear => true
1798 1798

  
1799
    xhr :post, :update_form, :project_id => 1,
1799
    xhr :post, :new, :project_id => 1,
1800 1800
                     :issue => {:tracker_id => 2,
1801 1801
                                :status_id => 1},
1802 1802
                     :was_default_status => 1
......
2776 2776

  
2777 2777
  def test_update_form_for_existing_issue
2778 2778
    @request.session[:user_id] = 2
2779
    xhr :put, :update_form, :project_id => 1,
2780
                             :id => 1,
2779
    xhr :patch, :edit, :id => 1,
2781 2780
                             :issue => {:tracker_id => 2,
2782 2781
                                        :subject => 'This is the test_new issue',
2783 2782
                                        :description => 'This is the description',
2784 2783
                                        :priority_id => 5}
2785 2784
    assert_response :success
2786 2785
    assert_equal 'text/javascript', response.content_type
2787
    assert_template 'update_form'
2786
    assert_template 'edit'
2788 2787
    assert_template :partial => '_form'
2789 2788

  
2790 2789
    issue = assigns(:issue)
......
2797 2796

  
2798 2797
  def test_update_form_for_existing_issue_should_keep_issue_author
2799 2798
    @request.session[:user_id] = 3
2800
    xhr :put, :update_form, :project_id => 1, :id => 1, :issue => {:subject => 'Changed'}
2799
    xhr :patch, :edit, :id => 1, :issue => {:subject => 'Changed'}
2801 2800
    assert_response :success
2802 2801
    assert_equal 'text/javascript', response.content_type
2803 2802

  
......
2814 2813
    WorkflowTransition.create!(:role_id => 1, :tracker_id => 2, :old_status_id => 2, :new_status_id => 5)
2815 2814
    WorkflowTransition.create!(:role_id => 1, :tracker_id => 2, :old_status_id => 5, :new_status_id => 4)
2816 2815

  
2817
    xhr :put, :update_form, :project_id => 1,
2818
                    :id => 2,
2816
    xhr :patch, :edit, :id => 2,
2819 2817
                    :issue => {:tracker_id => 2,
2820 2818
                               :status_id => 5,
2821 2819
                               :subject => 'This is an issue'}
......
2826 2824

  
2827 2825
  def test_update_form_for_existing_issue_with_project_change
2828 2826
    @request.session[:user_id] = 2
2829
    xhr :put, :update_form, :project_id => 1,
2830
                             :id => 1,
2827
    xhr :patch, :edit, :id => 1,
2831 2828
                             :issue => {:project_id => 2,
2832 2829
                                        :tracker_id => 2,
2833 2830
                                        :subject => 'This is the test_new issue',
......
2849 2846
    WorkflowTransition.delete_all
2850 2847
    WorkflowTransition.create!(:role_id => 1, :tracker_id => 2, :old_status_id => 2, :new_status_id => 3)
2851 2848

  
2852
    xhr :put, :update_form, :project_id => 1, :id => 2
2849
    xhr :patch, :edit, :id => 2
2853 2850
    assert_response :success
2854 2851
    assert_equal [2,3], assigns(:allowed_statuses).map(&:id).sort
2855 2852
  end
trunk/test/integration/routing/issues_test.rb
50 50
  end
51 51

  
52 52
  def test_issues_form_update
53
    should_route 'POST /projects/23/issues/update_form' => 'issues#update_form', :project_id => '23'
54
    should_route 'PUT /projects/23/issues/update_form' => 'issues#update_form', :project_id => '23'
53
    should_route 'POST /projects/23/issues/new' => 'issues#new', :project_id => '23'
54
    should_route 'PATCH /issues/23/edit' => 'issues#edit', :id => '23'
55 55
  end
56 56
end

Also available in: Unified diff