##// END OF EJS Templates
ProjectsController#add_issue moved to IssuesController#new....
Jean-Philippe Lang -
r1066:44ac1a0debc8
parent child
Show More
@@ -17,11 +17,13
17
17
18 class IssuesController < ApplicationController
18 class IssuesController < ApplicationController
19 layout 'base'
19 layout 'base'
20 before_filter :find_project, :authorize, :except => [:index, :changes, :preview]
20 before_filter :find_issue, :except => [:index, :changes, :preview, :new, :update_form]
21 before_filter :find_project, :only => [:new, :update_form]
22 before_filter :authorize, :except => [:index, :changes, :preview, :update_form]
21 before_filter :find_optional_project, :only => [:index, :changes]
23 before_filter :find_optional_project, :only => [:index, :changes]
22 accept_key_auth :index, :changes
24 accept_key_auth :index, :changes
23
25
24 cache_sweeper :issue_sweeper, :only => [ :edit, :update, :destroy ]
26 cache_sweeper :issue_sweeper, :only => [ :new, :edit, :update, :destroy ]
25
27
26 helper :projects
28 helper :projects
27 include ProjectsHelper
29 include ProjectsHelper
@@ -90,6 +92,51 class IssuesController < ApplicationController
90 end
92 end
91 end
93 end
92
94
95 # Add a new issue
96 # The new issue will be created from an existing one if copy_from parameter is given
97 def new
98 @issue = params[:copy_from] ? Issue.new.copy_from(params[:copy_from]) : Issue.new(params[:issue])
99 @issue.project = @project
100 @issue.author = User.current
101 @issue.tracker ||= @project.trackers.find(params[:tracker_id] ? params[:tracker_id] : :first)
102 if @issue.tracker.nil?
103 flash.now[:error] = 'No tracker is associated to this project. Please check the Project settings.'
104 render :nothing => true, :layout => true
105 return
106 end
107
108 default_status = IssueStatus.default
109 unless default_status
110 flash.now[:error] = 'No default issue status is defined. Please check your configuration (Go to "Administration -> Issue statuses").'
111 render :nothing => true, :layout => true
112 return
113 end
114 @issue.status = default_status
115 @allowed_statuses = ([default_status] + default_status.find_new_statuses_allowed_to(User.current.role_for_project(@project), @issue.tracker))
116
117 if request.get? || request.xhr?
118 @issue.start_date ||= Date.today
119 @custom_values = @issue.custom_values.empty? ?
120 @project.custom_fields_for_issues(@issue.tracker).collect { |x| CustomValue.new(:custom_field => x, :customized => @issue) } :
121 @issue.custom_values
122 else
123 requested_status = IssueStatus.find_by_id(params[:issue][:status_id])
124 # Check that the user is allowed to apply the requested status
125 @issue.status = (@allowed_statuses.include? requested_status) ? requested_status : default_status
126 @custom_values = @project.custom_fields_for_issues(@issue.tracker).collect { |x| CustomValue.new(:custom_field => x, :customized => @issue, :value => params["custom_fields"][x.id.to_s]) }
127 @issue.custom_values = @custom_values
128 if @issue.save
129 attach_files(@issue, params[:attachments])
130 flash[:notice] = l(:notice_successful_create)
131 Mailer.deliver_issue_add(@issue) if Setting.notified_events.include?('issue_added')
132 redirect_to :controller => 'issues', :action => 'index', :project_id => @project
133 return
134 end
135 end
136 @priorities = Enumeration::get_values('IPRI')
137 render :layout => !request.xhr?
138 end
139
93 def edit
140 def edit
94 @priorities = Enumeration::get_values('IPRI')
141 @priorities = Enumeration::get_values('IPRI')
95 @custom_values = []
142 @custom_values = []
@@ -185,6 +232,11 class IssuesController < ApplicationController
185 render :layout => false
232 render :layout => false
186 end
233 end
187
234
235 def update_form
236 @issue = Issue.new(params[:issue])
237 render :action => :new, :layout => false
238 end
239
188 def preview
240 def preview
189 issue = Issue.find_by_id(params[:id])
241 issue = Issue.find_by_id(params[:id])
190 @attachements = issue.attachments if issue
242 @attachements = issue.attachments if issue
@@ -193,13 +245,19 class IssuesController < ApplicationController
193 end
245 end
194
246
195 private
247 private
196 def find_project
248 def find_issue
197 @issue = Issue.find(params[:id], :include => [:project, :tracker, :status, :author, :priority, :category])
249 @issue = Issue.find(params[:id], :include => [:project, :tracker, :status, :author, :priority, :category])
198 @project = @issue.project
250 @project = @issue.project
199 rescue ActiveRecord::RecordNotFound
251 rescue ActiveRecord::RecordNotFound
200 render_404
252 render_404
201 end
253 end
202
254
255 def find_project
256 @project = Project.find(params[:project_id])
257 rescue ActiveRecord::RecordNotFound
258 render_404
259 end
260
203 def find_optional_project
261 def find_optional_project
204 return true unless params[:project_id]
262 return true unless params[:project_id]
205 @project = Project.find(params[:project_id])
263 @project = Project.find(params[:project_id])
@@ -22,7 +22,7 class ProjectsController < ApplicationController
22 menu_item :roadmap, :only => :roadmap
22 menu_item :roadmap, :only => :roadmap
23 menu_item :files, :only => [:list_files, :add_file]
23 menu_item :files, :only => [:list_files, :add_file]
24 menu_item :settings, :only => :settings
24 menu_item :settings, :only => :settings
25 menu_item :issues, :only => [:add_issue, :bulk_edit_issues, :changelog, :move_issues]
25 menu_item :issues, :only => [:bulk_edit_issues, :changelog, :move_issues]
26
26
27 before_filter :find_project, :except => [ :index, :list, :add ]
27 before_filter :find_project, :except => [ :index, :list, :add ]
28 before_filter :authorize, :except => [ :index, :list, :add, :archive, :unarchive, :destroy ]
28 before_filter :authorize, :except => [ :index, :list, :add, :archive, :unarchive, :destroy ]
@@ -30,7 +30,6 class ProjectsController < ApplicationController
30 accept_key_auth :activity, :calendar
30 accept_key_auth :activity, :calendar
31
31
32 cache_sweeper :project_sweeper, :only => [ :add, :edit, :archive, :unarchive, :destroy ]
32 cache_sweeper :project_sweeper, :only => [ :add, :edit, :archive, :unarchive, :destroy ]
33 cache_sweeper :issue_sweeper, :only => [ :add_issue ]
34 cache_sweeper :version_sweeper, :only => [ :add_version ]
33 cache_sweeper :version_sweeper, :only => [ :add_version ]
35
34
36 helper :sort
35 helper :sort
@@ -184,45 +183,6 class ProjectsController < ApplicationController
184 end
183 end
185 end
184 end
186
185
187 # Add a new issue to @project
188 # The new issue will be created from an existing one if copy_from parameter is given
189 def add_issue
190 @issue = params[:copy_from] ? Issue.new.copy_from(params[:copy_from]) : Issue.new(params[:issue])
191 @issue.project = @project
192 @issue.author = User.current
193 @issue.tracker ||= @project.trackers.find(params[:tracker_id])
194
195 default_status = IssueStatus.default
196 unless default_status
197 flash.now[:error] = 'No default issue status is defined. Please check your configuration (Go to "Administration -> Issue statuses").'
198 render :nothing => true, :layout => true
199 return
200 end
201 @issue.status = default_status
202 @allowed_statuses = ([default_status] + default_status.find_new_statuses_allowed_to(User.current.role_for_project(@project), @issue.tracker))
203
204 if request.get?
205 @issue.start_date ||= Date.today
206 @custom_values = @issue.custom_values.empty? ?
207 @project.custom_fields_for_issues(@issue.tracker).collect { |x| CustomValue.new(:custom_field => x, :customized => @issue) } :
208 @issue.custom_values
209 else
210 requested_status = IssueStatus.find_by_id(params[:issue][:status_id])
211 # Check that the user is allowed to apply the requested status
212 @issue.status = (@allowed_statuses.include? requested_status) ? requested_status : default_status
213 @custom_values = @project.custom_fields_for_issues(@issue.tracker).collect { |x| CustomValue.new(:custom_field => x, :customized => @issue, :value => params["custom_fields"][x.id.to_s]) }
214 @issue.custom_values = @custom_values
215 if @issue.save
216 attach_files(@issue, params[:attachments])
217 flash[:notice] = l(:notice_successful_create)
218 Mailer.deliver_issue_add(@issue) if Setting.notified_events.include?('issue_added')
219 redirect_to :controller => 'issues', :action => 'index', :project_id => @project
220 return
221 end
222 end
223 @priorities = Enumeration::get_values('IPRI')
224 end
225
226 # Bulk edit issues
186 # Bulk edit issues
227 def bulk_edit_issues
187 def bulk_edit_issues
228 if request.post?
188 if request.post?
@@ -194,6 +194,6 module ProjectsHelper
194 # can't use form tag inside helper
194 # can't use form tag inside helper
195 content_tag('form',
195 content_tag('form',
196 select_tag('tracker_id', '<option></option>' + options_from_collection_for_select(trackers, 'id', 'name'), :onchange => "if (this.value != '') {this.form.submit()}"),
196 select_tag('tracker_id', '<option></option>' + options_from_collection_for_select(trackers, 'id', 'name'), :onchange => "if (this.value != '') {this.form.submit()}"),
197 :action => url_for(:controller => 'projects', :action => 'add_issue', :id => @project), :method => 'get')
197 :action => url_for(:controller => 'issues', :action => 'new', :project_id => @project), :method => 'get')
198 end
198 end
199 end
199 end
@@ -1,6 +1,13
1 <%= error_messages_for 'issue' %>
1 <%= error_messages_for 'issue' %>
2 <div class="box">
2 <div class="box">
3
3
4 <% if @issue.new_record? %>
5 <p><%= f.select :tracker_id, @project.trackers.collect {|t| [t.name, t.id]}, :required => true %></p>
6 <%= observe_field :issue_tracker_id, :url => { :action => :new },
7 :update => :content,
8 :with => "Form.serialize('issue-form')" %>
9 <% end %>
10
4 <div class="splitcontentleft">
11 <div class="splitcontentleft">
5 <% if @issue.new_record? %>
12 <% if @issue.new_record? %>
6 <p><%= f.select :status_id, (@allowed_statuses.collect {|p| [p.name, p.id]}), :required => true %></p>
13 <p><%= f.select :status_id, (@allowed_statuses.collect {|p| [p.name, p.id]}), :required => true %></p>
@@ -1,4 +1,4
1 <% if authorize_for('projects', 'add_issue') && @project.trackers.any? %>
1 <% if authorize_for('issues', 'new') && @project.trackers.any? %>
2 <h3><%= l(:label_issue_new) %></h3>
2 <h3><%= l(:label_issue_new) %></h3>
3 <%= l(:label_tracker) %>: <%= new_issue_selector %>
3 <%= l(:label_tracker) %>: <%= new_issue_selector %>
4 <% end %>
4 <% end %>
@@ -31,7 +31,7
31 :selected => @issue.assigned_to.nil?, :disabled => !@can[:assign] %></li>
31 :selected => @issue.assigned_to.nil?, :disabled => !@can[:assign] %></li>
32 </ul>
32 </ul>
33 </li>
33 </li>
34 <li><%= context_menu_link l(:button_copy), {:controller => 'projects', :action => 'add_issue', :id => @project, :copy_from => @issue},
34 <li><%= context_menu_link l(:button_copy), {:controller => 'issues', :action => 'new', :project_id => @project, :copy_from => @issue},
35 :class => 'icon-copy', :disabled => !@can[:copy] %></li>
35 :class => 'icon-copy', :disabled => !@can[:copy] %></li>
36 <li><%= context_menu_link l(:button_move), {:controller => 'projects', :action => 'move_issues', :id => @project, "issue_ids[]" => @issue.id },
36 <li><%= context_menu_link l(:button_move), {:controller => 'projects', :action => 'move_issues', :id => @project, "issue_ids[]" => @issue.id },
37 :class => 'icon-move', :disabled => !@can[:move] %>
37 :class => 'icon-move', :disabled => !@can[:move] %>
@@ -1,9 +1,7
1 <h2><%=l(:label_issue_new)%>: <%= @issue.tracker %></h2>
1 <h2><%=l(:label_issue_new)%>: <%= @issue.tracker %></h2>
2
2
3 <% labelled_tabular_form_for :issue, @issue,
3 <% labelled_tabular_form_for :issue, @issue,
4 :url => {:action => 'add_issue'},
5 :html => {:multipart => true, :id => 'issue-form'} do |f| %>
4 :html => {:multipart => true, :id => 'issue-form'} do |f| %>
6 <%= f.hidden_field :tracker_id %>
7 <%= render :partial => 'issues/form', :locals => {:f => f} %>
5 <%= render :partial => 'issues/form', :locals => {:f => f} %>
8 <%= submit_tag l(:button_create) %>
6 <%= submit_tag l(:button_create) %>
9 <%= link_to_remote l(:label_preview),
7 <%= link_to_remote l(:label_preview),
@@ -3,7 +3,7
3 <%= link_to_if_authorized l(:button_edit), {:controller => 'issues', :action => 'edit', :id => @issue}, :class => 'icon icon-edit', :accesskey => accesskey(:edit) %>
3 <%= link_to_if_authorized l(:button_edit), {:controller => 'issues', :action => 'edit', :id => @issue}, :class => 'icon icon-edit', :accesskey => accesskey(:edit) %>
4 <%= link_to_if_authorized l(:button_log_time), {:controller => 'timelog', :action => 'edit', :issue_id => @issue}, :class => 'icon icon-time' %>
4 <%= link_to_if_authorized l(:button_log_time), {:controller => 'timelog', :action => 'edit', :issue_id => @issue}, :class => 'icon icon-time' %>
5 <%= watcher_tag(@issue, User.current) %>
5 <%= watcher_tag(@issue, User.current) %>
6 <%= link_to_if_authorized l(:button_copy), {:controller => 'projects', :action => 'add_issue', :id => @project, :copy_from => @issue }, :class => 'icon icon-copy' %>
6 <%= link_to_if_authorized l(:button_copy), {:controller => 'issues', :action => 'new', :project_id => @project, :copy_from => @issue }, :class => 'icon icon-copy' %>
7 <%= link_to_if_authorized l(:button_move), {:controller => 'projects', :action => 'move_issues', :id => @project, "issue_ids[]" => @issue.id }, :class => 'icon icon-move' %>
7 <%= link_to_if_authorized l(:button_move), {:controller => 'projects', :action => 'move_issues', :id => @project, "issue_ids[]" => @issue.id }, :class => 'icon icon-move' %>
8 <%= link_to_if_authorized l(:button_delete), {:controller => 'issues', :action => 'destroy', :id => @issue}, :confirm => l(:text_are_you_sure), :method => :post, :class => 'icon icon-del' %>
8 <%= link_to_if_authorized l(:button_delete), {:controller => 'issues', :action => 'destroy', :id => @issue}, :confirm => l(:text_are_you_sure), :method => :post, :class => 'icon icon-del' %>
9 </div>
9 </div>
@@ -56,7 +56,7
56 </div>
56 </div>
57
57
58 <% content_for :sidebar do %>
58 <% content_for :sidebar do %>
59 <% if authorize_for('projects', 'add_issue') && @project.trackers.any? %>
59 <% if authorize_for('issues', 'new') && @project.trackers.any? %>
60 <h3><%= l(:label_issue_new) %></h3>
60 <h3><%= l(:label_issue_new) %></h3>
61 <%= l(:label_tracker) %>: <%= new_issue_selector %>
61 <%= l(:label_tracker) %>: <%= new_issue_selector %>
62 <% end %>
62 <% end %>
@@ -30,7 +30,7 Redmine::AccessControl.map do |map|
30 :versions => [:show, :status_by],
30 :versions => [:show, :status_by],
31 :queries => :index,
31 :queries => :index,
32 :reports => :issue_report}, :public => true
32 :reports => :issue_report}, :public => true
33 map.permission :add_issues, {:projects => :add_issue}
33 map.permission :add_issues, {:issues => :new}
34 map.permission :edit_issues, {:projects => :bulk_edit_issues,
34 map.permission :edit_issues, {:projects => :bulk_edit_issues,
35 :issues => [:edit, :update, :destroy_attachment]}
35 :issues => [:edit, :update, :destroy_attachment]}
36 map.permission :manage_issue_relations, {:issue_relations => [:new, :destroy]}
36 map.permission :manage_issue_relations, {:issue_relations => [:new, :destroy]}
@@ -29,6 +29,7 class IssuesControllerTest < Test::Unit::TestCase
29 :issues,
29 :issues,
30 :issue_statuses,
30 :issue_statuses,
31 :trackers,
31 :trackers,
32 :projects_trackers,
32 :issue_categories,
33 :issue_categories,
33 :enabled_modules,
34 :enabled_modules,
34 :enumerations,
35 :enumerations,
@@ -126,6 +127,55 class IssuesControllerTest < Test::Unit::TestCase
126 :content => /Notes/ } }
127 :content => /Notes/ } }
127 end
128 end
128
129
130 def test_get_new
131 @request.session[:user_id] = 2
132 get :new, :project_id => 1, :tracker_id => 1
133 assert_response :success
134 assert_template 'new'
135 end
136
137 def test_get_new_without_tracker_id
138 @request.session[:user_id] = 2
139 get :new, :project_id => 1
140 assert_response :success
141 assert_template 'new'
142
143 issue = assigns(:issue)
144 assert_not_nil issue
145 assert_equal Project.find(1).trackers.first, issue.tracker
146 end
147
148 def test_update_new_form
149 @request.session[:user_id] = 2
150 xhr :post, :new, :project_id => 1,
151 :issue => {:tracker_id => 2,
152 :subject => 'This is the test_new issue',
153 :description => 'This is the description',
154 :priority_id => 5}
155 assert_response :success
156 assert_template 'new'
157 end
158
159 def test_post_new
160 @request.session[:user_id] = 2
161 post :new, :project_id => 1,
162 :issue => {:tracker_id => 1,
163 :subject => 'This is the test_new issue',
164 :description => 'This is the description',
165 :priority_id => 5}
166 assert_redirected_to 'projects/ecookbook/issues'
167 assert Issue.find_by_subject('This is the test_new issue')
168 end
169
170 def test_copy_issue
171 @request.session[:user_id] = 2
172 get :new, :project_id => 1, :copy_from => 1
173 assert_template 'new'
174 assert_not_nil assigns(:issue)
175 orig = Issue.find(1)
176 assert_equal orig.subject, assigns(:issue).subject
177 end
178
129 def test_get_edit
179 def test_get_edit
130 @request.session[:user_id] = 2
180 @request.session[:user_id] = 2
131 get :edit, :id => 1
181 get :edit, :id => 1
@@ -236,23 +236,4 class ProjectsControllerTest < Test::Unit::TestCase
236 assert_redirected_to 'admin/projects'
236 assert_redirected_to 'admin/projects'
237 assert Project.find(1).active?
237 assert Project.find(1).active?
238 end
238 end
239
240 def test_add_issue
241 @request.session[:user_id] = 2
242 get :add_issue, :id => 1, :tracker_id => 1
243 assert_response :success
244 assert_template 'add_issue'
245 post :add_issue, :id => 1, :issue => {:tracker_id => 1, :subject => 'This is the test_add_issue issue', :description => 'This is the description', :priority_id => 5}
246 assert_redirected_to 'projects/ecookbook/issues'
247 assert Issue.find_by_subject('This is the test_add_issue issue')
248 end
249
250 def test_copy_issue
251 @request.session[:user_id] = 2
252 get :add_issue, :id => 1, :copy_from => 1
253 assert_template 'add_issue'
254 assert_not_nil assigns(:issue)
255 orig = Issue.find(1)
256 assert_equal orig.subject, assigns(:issue).subject
257 end
258 end
239 end
@@ -6,11 +6,11 class IssuesTest < ActionController::IntegrationTest
6 # create an issue
6 # create an issue
7 def test_add_issue
7 def test_add_issue
8 log_user('jsmith', 'jsmith')
8 log_user('jsmith', 'jsmith')
9 get "projects/add_issue/1", :tracker_id => "1"
9 get 'projects/1/issues/new', :tracker_id => '1'
10 assert_response :success
10 assert_response :success
11 assert_template "projects/add_issue"
11 assert_template 'issues/new'
12
12
13 post "projects/add_issue/1", :tracker_id => "1",
13 post 'projects/1/issues/new', :tracker_id => "1",
14 :issue => { :start_date => "2006-12-26",
14 :issue => { :start_date => "2006-12-26",
15 :priority_id => "3",
15 :priority_id => "3",
16 :subject => "new test issue",
16 :subject => "new test issue",
General Comments 0
You need to be logged in to leave comments. Login now