Feature #31322 » 20200131-collapse.diff
| app/controllers/issues_controller.rb | ||
|---|---|---|
| 181 | 181 |
end |
| 182 | 182 | |
| 183 | 183 |
def update |
| 184 |
if request.xhr? |
|
| 185 |
if params[:check_go_to_close_confirm] |
|
| 186 |
result = true |
|
| 187 |
status = nil |
|
| 188 |
status_id = params[:status_id].to_i |
|
| 189 |
can_close_all_descendants = true |
|
| 190 |
if status_id <= 0 |
|
| 191 |
result = false |
|
| 192 |
else |
|
| 193 |
status = IssueStatus.find(status_id) |
|
| 194 |
if !status.is_closed |
|
| 195 |
result = false |
|
| 196 |
else |
|
| 197 |
opened_descendants = [] |
|
| 198 |
@issue.descendants.open.sort_by(&:lft).each do |issue| |
|
| 199 |
unless issue.visible? |
|
| 200 |
can_close_all_descendants = false |
|
| 201 |
break |
|
| 202 |
end |
|
| 203 | ||
| 204 |
unless issue.new_statuses_allowed_to.map{|i| i.id}.include?(status.id)
|
|
| 205 |
can_close_all_descendants = false |
|
| 206 |
break |
|
| 207 |
end |
|
| 208 | ||
| 209 |
opened_descendants << issue |
|
| 210 |
end |
|
| 211 |
if can_close_all_descendants && opened_descendants.empty? |
|
| 212 |
result = false |
|
| 213 |
can_close_all_descendants = false |
|
| 214 |
end |
|
| 215 |
end |
|
| 216 |
if result |
|
| 217 |
session[:can_close_descendant] = {}
|
|
| 218 |
session[:can_close_descendant][:can_close_all] = can_close_all_descendants |
|
| 219 |
if can_close_all_descendants |
|
| 220 |
session[:can_close_descendant][:status_id] = status.id |
|
| 221 |
session[:can_close_descendant][:status_name] = status.name |
|
| 222 |
session[:can_close_descendant][:ids] = opened_descendants.map{|i| i.id}
|
|
| 223 |
end |
|
| 224 |
end |
|
| 225 |
end |
|
| 226 |
render :json => {:result => result}
|
|
| 227 |
return |
|
| 228 |
end |
|
| 229 | ||
| 230 |
if !session.has_key?(:can_close_descendant) |
|
| 231 |
return |
|
| 232 |
end |
|
| 233 | ||
| 234 |
render_data = {
|
|
| 235 |
:status_name => session[:can_close_descendant][:status_name], |
|
| 236 |
:can_close_all => session[:can_close_descendant][:can_close_all] |
|
| 237 |
} |
|
| 238 |
render( |
|
| 239 |
:partial => 'close_confirm', |
|
| 240 |
:layout => false, |
|
| 241 |
:locals => render_data |
|
| 242 |
) |
|
| 243 |
return |
|
| 244 |
end |
|
| 245 | ||
| 184 | 246 |
return unless update_issue_from_params |
| 185 | 247 | |
| 186 | 248 |
@issue.save_attachments(params[:attachments] || |
| ... | ... | |
| 200 | 262 | |
| 201 | 263 |
if saved |
| 202 | 264 |
render_attachment_warning_if_needed(@issue) |
| 265 |
if params[:close_descendants] && session.has_key?(:can_close_descendant) |
|
| 266 |
close_descendant_ids = session[:can_close_descendant][:ids] |
|
| 267 |
session.delete(:can_close_descendant) |
|
| 268 |
close_descendant_ids.each do |id| |
|
| 269 |
issue = Issue.find(id) |
|
| 270 |
issue.init_journal(User.current, params[:issue][:notes]) |
|
| 271 |
issue.safe_attributes = {'status_id' => params[:issue][:status_id].to_i}
|
|
| 272 |
issue.save |
|
| 273 |
end |
|
| 274 |
end |
|
| 275 | ||
| 203 | 276 |
unless @issue.current_journal.new_record? || params[:no_flash] |
| 204 | 277 |
flash[:notice] = l(:notice_successful_update) |
| 205 | 278 |
end |
| app/views/issues/_close_confirm.js.erb | ||
|---|---|---|
| 1 |
$('#ajax-modal').html(
|
|
| 2 |
'<%= escape_javascript( |
|
| 3 |
render( |
|
| 4 |
:partial => 'close_confirm_dialog', |
|
| 5 |
:locals => {
|
|
| 6 |
:status_name => status_name, |
|
| 7 |
:can_close_all => can_close_all |
|
| 8 |
} |
|
| 9 |
) |
|
| 10 |
) |
|
| 11 |
%>' |
|
| 12 |
); |
|
| 13 |
showModal('ajax-modal', '400px');
|
|
| app/views/issues/_close_confirm_dialog.html.erb | ||
|---|---|---|
| 1 |
<h3 class="title"> </h3> |
|
| 2 |
<% if can_close_all %> |
|
| 3 |
<p> |
|
| 4 |
<%= l(:text_close_parent_issue_and_open_subtasks, |
|
| 5 |
:issue_id => params[:id]) %> |
|
| 6 |
</p> |
|
| 7 |
<p> |
|
| 8 |
<label class="block"> |
|
| 9 |
<%= radio_button_tag 'choice', '1' %> |
|
| 10 |
<%= l(:text_close_parent_issue_and_open_subtasks_choice_close_also_all_subtasks, |
|
| 11 |
:status => status_name) %> |
|
| 12 |
</label> |
|
| 13 |
<label class="block"> |
|
| 14 |
<%= radio_button_tag 'choice', '2', true %> |
|
| 15 |
<%= l(:text_close_parent_issue_and_open_subtasks_choice_close_only_parent, |
|
| 16 |
:issue_id => params[:id]) %> |
|
| 17 |
</label> |
|
| 18 |
</p> |
|
| 19 |
<% else %> |
|
| 20 |
<p> |
|
| 21 |
<%= l(:text_close_parent_issue_with_open_subtasks_confirmation) %> |
|
| 22 |
</p> |
|
| 23 |
<% end %> |
|
| 24 |
<p class="buttons"> |
|
| 25 |
<%= button_tag l(:button_apply), :type => "button", :onclick => "run_submit();" %> |
|
| 26 |
<%= link_to_function l(:button_cancel), "hideModal(this);" %> |
|
| 27 |
</p> |
|
| 28 | ||
| 29 |
<%= javascript_tag do %> |
|
| 30 |
function run_submit() {
|
|
| 31 |
var canCloseAll = <%= can_close_all %>; |
|
| 32 |
if (canCloseAll) {
|
|
| 33 |
var radioVal = $("input[name='choice']:checked").val();
|
|
| 34 |
if (radioVal == '1') {
|
|
| 35 |
$('<input />').attr('type', 'hidden')
|
|
| 36 |
.attr('name', "close_descendants")
|
|
| 37 |
.appendTo('#issue-form');
|
|
| 38 |
} |
|
| 39 |
} |
|
| 40 |
$("#issue-form").off('submit');
|
|
| 41 |
$("#issue-form").submit();
|
|
| 42 |
} |
|
| 43 |
<% end %> |
|
| app/views/issues/_edit.html.erb | ||
|---|---|---|
| 82 | 82 |
<%= hidden_field_tag 'issue_position', @issue_position if @issue_position %> |
| 83 | 83 |
<%= hidden_field_tag 'issue_count', @issue_count if @issue_count %> |
| 84 | 84 |
<% end %> |
| 85 |
<%= javascript_tag do %> |
|
| 86 |
$('#issue-form').submit(function(){
|
|
| 87 |
var status_id = 0; |
|
| 88 |
if ($("#issue_status_id").length > 0) {
|
|
| 89 |
status_id = $("#issue_status_id").val();
|
|
| 90 |
} |
|
| 91 |
$.ajax({
|
|
| 92 |
url: $("#issue-form").attr('action'),
|
|
| 93 |
type: 'patch', |
|
| 94 |
data: {
|
|
| 95 |
"check_go_to_close_confirm": "", |
|
| 96 |
"status_id": status_id |
|
| 97 |
}, |
|
| 98 |
}) |
|
| 99 |
.then( |
|
| 100 |
function(data){
|
|
| 101 |
if (data["result"]) {
|
|
| 102 |
$.ajax({
|
|
| 103 |
url: $("#issue-form").attr('action'),
|
|
| 104 |
type: 'patch', |
|
| 105 |
data: {}
|
|
| 106 |
}); |
|
| 107 |
} else {
|
|
| 108 |
$("#issue-form").off('submit');
|
|
| 109 |
$("#issue-form").submit();
|
|
| 110 |
} |
|
| 111 |
} |
|
| 112 |
); |
|
| 113 |
return false; |
|
| 114 |
}); |
|
| 115 |
<% end %> |
|
| config/locales/en.yml | ||
|---|---|---|
| 1193 | 1193 |
text_issues_destroy_confirmation: 'Are you sure you want to delete the selected issue(s)?' |
| 1194 | 1194 |
text_issues_destroy_descendants_confirmation: "This will also delete %{count} subtask(s)."
|
| 1195 | 1195 |
text_close_parent_issue_with_open_subtasks_confirmation: Are you sure you want to close parent issue with open subtasks? |
| 1196 |
text_close_parent_issue_and_open_subtasks: Issue %{issue_id} has open subtasks.
|
|
| 1197 |
text_close_parent_issue_and_open_subtasks_choice_close_also_all_subtasks: Close all open subtasks by "%{status}" status too
|
|
| 1198 |
text_close_parent_issue_and_open_subtasks_choice_close_only_parent: Close only issue %{issue_id}
|
|
| 1196 | 1199 |
text_time_entries_destroy_confirmation: 'Are you sure you want to delete the selected time entr(y/ies)?' |
| 1197 | 1200 |
text_select_project_modules: 'Select modules to enable for this project:' |
| 1198 | 1201 |
text_default_administrator_account_changed: Default administrator account changed |
| test/functional/issues_controller_test.rb | ||
|---|---|---|
| 6242 | 6242 |
assert_equal 2, issue.reload.assigned_to_id |
| 6243 | 6243 |
end |
| 6244 | 6244 | |
| 6245 |
test "check_go_to_close_confirm returns false if status_id is not close" do |
|
| 6246 |
issue = Issue.find(1) |
|
| 6247 |
user = User.find(2) |
|
| 6248 |
assert issue.visible?(user) |
|
| 6249 |
assert_not issue.closed? |
|
| 6250 |
@request.session[:user_id] = user.id |
|
| 6251 |
put( |
|
| 6252 |
:update, |
|
| 6253 |
:params => {
|
|
| 6254 |
:id => issue.id, |
|
| 6255 |
:check_go_to_close_confirm => "", |
|
| 6256 |
:status_id => 1 |
|
| 6257 |
}, |
|
| 6258 |
:xhr => true |
|
| 6259 |
) |
|
| 6260 |
assert_response :success |
|
| 6261 |
assert_equal 'application/json', response.content_type |
|
| 6262 |
json = ActiveSupport::JSON.decode(response.body) |
|
| 6263 |
assert_equal({"result" => false}, json)
|
|
| 6264 |
assert_not session.has_key?(:can_close_descendant) |
|
| 6265 |
end |
|
| 6266 | ||
| 6267 |
test "check_go_to_close_confirm returns false if status_id is 0" do |
|
| 6268 |
issue = Issue.find(1) |
|
| 6269 |
user = User.find(2) |
|
| 6270 |
assert issue.visible?(user) |
|
| 6271 |
assert_not issue.closed? |
|
| 6272 |
@request.session[:user_id] = user.id |
|
| 6273 |
put( |
|
| 6274 |
:update, |
|
| 6275 |
:params => {
|
|
| 6276 |
:id => issue.id, |
|
| 6277 |
:check_go_to_close_confirm => "", |
|
| 6278 |
:status_id => 0 |
|
| 6279 |
}, |
|
| 6280 |
:xhr => true |
|
| 6281 |
) |
|
| 6282 |
assert_response :success |
|
| 6283 |
assert_equal 'application/json', response.content_type |
|
| 6284 |
json = ActiveSupport::JSON.decode(response.body) |
|
| 6285 |
assert_equal({"result" => false}, json)
|
|
| 6286 |
assert_not session.has_key?(:can_close_descendant) |
|
| 6287 |
end |
|
| 6288 | ||
| 6289 |
test "check_go_to_close_confirm returns false if issue does not have child" do |
|
| 6290 |
issue = Issue.generate! |
|
| 6291 |
user = User.find(2) |
|
| 6292 |
assert issue.visible?(user) |
|
| 6293 |
assert_not issue.closed? |
|
| 6294 |
@request.session[:user_id] = user.id |
|
| 6295 |
put( |
|
| 6296 |
:update, |
|
| 6297 |
:params => {
|
|
| 6298 |
:id => issue.id, |
|
| 6299 |
:check_go_to_close_confirm => "", |
|
| 6300 |
:status_id => 5 |
|
| 6301 |
}, |
|
| 6302 |
:xhr => true |
|
| 6303 |
) |
|
| 6304 |
assert_response :success |
|
| 6305 |
assert_equal 'application/json', response.content_type |
|
| 6306 |
json = ActiveSupport::JSON.decode(response.body) |
|
| 6307 | ||
| 6308 |
assert_equal 1, issue.reload.status.id |
|
| 6309 |
assert_equal({"result" => false}, json)
|
|
| 6310 |
assert_not session.has_key?(:can_close_descendant) |
|
| 6311 |
end |
|
| 6312 | ||
| 6313 |
test "check_go_to_close_confirm returns true if issue have open child" do |
|
| 6314 |
parent = Issue.generate! |
|
| 6315 |
child = Issue.generate!(:parent_issue_id => parent.id) |
|
| 6316 |
user = User.find(2) |
|
| 6317 |
assert parent.reload.visible?(user) |
|
| 6318 |
assert_not parent.closed? |
|
| 6319 |
assert child.reload.visible?(user) |
|
| 6320 |
assert_not child.closed? |
|
| 6321 | ||
| 6322 |
@request.session[:user_id] = user.id |
|
| 6323 |
put( |
|
| 6324 |
:update, |
|
| 6325 |
:params => {
|
|
| 6326 |
:id => parent.id, |
|
| 6327 |
:check_go_to_close_confirm => "", |
|
| 6328 |
:status_id => 5 |
|
| 6329 |
}, |
|
| 6330 |
:xhr => true |
|
| 6331 |
) |
|
| 6332 |
assert_response :success |
|
| 6333 |
assert_equal 'application/json', response.content_type |
|
| 6334 |
json = ActiveSupport::JSON.decode(response.body) |
|
| 6335 | ||
| 6336 |
assert_equal 1, parent.reload.status.id |
|
| 6337 |
assert_equal({"result" => true}, json)
|
|
| 6338 |
assert session.has_key?(:can_close_descendant) |
|
| 6339 |
end |
|
| 6340 | ||
| 6341 |
test "check_go_to_close_confirm returns false if child is closed" do |
|
| 6342 |
parent = Issue.generate! |
|
| 6343 |
child = Issue. |
|
| 6344 |
generate!( |
|
| 6345 |
:parent_issue_id => parent.id, |
|
| 6346 |
:status_id => 5 |
|
| 6347 |
) |
|
| 6348 |
user = User.find(2) |
|
| 6349 |
assert parent.reload.visible?(user) |
|
| 6350 |
assert_not parent.closed? |
|
| 6351 |
assert child.reload.visible?(user) |
|
| 6352 |
assert child.closed? |
|
| 6353 | ||
| 6354 |
@request.session[:user_id] = user.id |
|
| 6355 |
put( |
|
| 6356 |
:update, |
|
| 6357 |
:params => {
|
|
| 6358 |
:id => parent.id, |
|
| 6359 |
:check_go_to_close_confirm => "", |
|
| 6360 |
:status_id => 5 |
|
| 6361 |
}, |
|
| 6362 |
:xhr => true |
|
| 6363 |
) |
|
| 6364 |
assert_response :success |
|
| 6365 |
assert_equal 'application/json', response.content_type |
|
| 6366 |
json = ActiveSupport::JSON.decode(response.body) |
|
| 6367 | ||
| 6368 |
assert_equal 1, parent.reload.status.id |
|
| 6369 |
assert_equal({"result" => false}, json)
|
|
| 6370 |
assert_not session.has_key?(:can_close_descendant) |
|
| 6371 |
end |
|
| 6372 | ||
| 6373 |
test "check_go_to_close_confirm returns true if child is open and not visible" do |
|
| 6374 |
user = User.generate! |
|
| 6375 |
project = Project.generate! |
|
| 6376 |
role = Role.generate! |
|
| 6377 |
role.add_permission! :view_issues, :edit_issues |
|
| 6378 |
role.set_permission_trackers :view_issues, [2] |
|
| 6379 |
role.set_permission_trackers :edit_issues, [2] |
|
| 6380 |
role.save! |
|
| 6381 |
User.add_to_project(user, project, role) |
|
| 6382 |
parent = Issue. |
|
| 6383 |
generate!( |
|
| 6384 |
:project => project, |
|
| 6385 |
:tracker_id => 2, |
|
| 6386 |
:status_id => 1 |
|
| 6387 |
) |
|
| 6388 |
child = Issue. |
|
| 6389 |
generate!( |
|
| 6390 |
:project => project, |
|
| 6391 |
:tracker_id => 1, |
|
| 6392 |
:parent_issue_id => parent.id, |
|
| 6393 |
:status_id => 1 |
|
| 6394 |
) |
|
| 6395 |
assert parent.reload.visible?(user) |
|
| 6396 |
assert_not parent.closed? |
|
| 6397 |
assert_not child.reload.visible?(user) |
|
| 6398 |
assert_not child.closed? |
|
| 6399 | ||
| 6400 |
@request.session[:user_id] = user.id |
|
| 6401 |
put( |
|
| 6402 |
:update, |
|
| 6403 |
:params => {
|
|
| 6404 |
:id => parent.id, |
|
| 6405 |
:check_go_to_close_confirm => "", |
|
| 6406 |
:status_id => 5 |
|
| 6407 |
}, |
|
| 6408 |
:xhr => true |
|
| 6409 |
) |
|
| 6410 |
assert_response :success |
|
| 6411 |
assert_equal 'application/json', response.content_type |
|
| 6412 |
json = ActiveSupport::JSON.decode(response.body) |
|
| 6413 | ||
| 6414 |
assert_equal 1, parent.reload.status.id |
|
| 6415 |
assert_equal({"result" => true}, json)
|
|
| 6416 |
assert session.has_key?(:can_close_descendant) |
|
| 6417 |
assert_not session[:can_close_descendant][:can_close_all] |
|
| 6418 |
end |
|
| 6419 | ||
| 6420 |
test "close all descendants which are open" do |
|
| 6421 |
with_settings :closed_parent_issues_with_open_subtasks => 1 do |
|
| 6422 |
parent = Issue.generate! |
|
| 6423 |
child = |
|
| 6424 |
Issue. |
|
| 6425 |
generate!( |
|
| 6426 |
:parent_issue_id => parent.id |
|
| 6427 |
) |
|
| 6428 |
grandchild1 = |
|
| 6429 |
Issue. |
|
| 6430 |
generate!( |
|
| 6431 |
:parent_issue_id => child.id |
|
| 6432 |
) |
|
| 6433 |
grandchild2 = |
|
| 6434 |
Issue. |
|
| 6435 |
generate!( |
|
| 6436 |
:parent_issue_id => child.id, |
|
| 6437 |
:status_id => 6 |
|
| 6438 |
) |
|
| 6439 |
user = User.find(2) |
|
| 6440 |
assert parent.reload.visible?(user) |
|
| 6441 |
assert_not parent.closed? |
|
| 6442 |
assert child.reload.visible?(user) |
|
| 6443 |
assert_not child.closed? |
|
| 6444 |
assert grandchild1.reload.visible?(user) |
|
| 6445 |
assert_not grandchild1.closed? |
|
| 6446 |
assert grandchild2.reload.visible?(user) |
|
| 6447 |
assert grandchild2.closed? |
|
| 6448 | ||
| 6449 |
assert [parent, child, grandchild1, grandchild2]. |
|
| 6450 |
map{|i| i.new_statuses_allowed_to(user)}.
|
|
| 6451 |
reduce(:&).map{|i| i.id}.include?(5)
|
|
| 6452 |
@request.session[:user_id] = user.id |
|
| 6453 |
put( |
|
| 6454 |
:update, |
|
| 6455 |
:params => {
|
|
| 6456 |
:id => parent.id, |
|
| 6457 |
:check_go_to_close_confirm => "", |
|
| 6458 |
:status_id => 5 |
|
| 6459 |
}, |
|
| 6460 |
:xhr => true |
|
| 6461 |
) |
|
| 6462 |
assert_response :success |
|
| 6463 |
assert_equal 'application/json', response.content_type |
|
| 6464 |
json = ActiveSupport::JSON.decode(response.body) |
|
| 6465 | ||
| 6466 |
assert_equal 1, parent.reload.status.id |
|
| 6467 |
assert_equal({"result" => true}, json)
|
|
| 6468 |
assert session.has_key?(:can_close_descendant) |
|
| 6469 |
assert session[:can_close_descendant][:can_close_all] |
|
| 6470 |
assert_equal [child.id, grandchild1.id], session[:can_close_descendant][:ids] |
|
| 6471 | ||
| 6472 |
notes = 'close all' |
|
| 6473 | ||
| 6474 |
assert_difference( |
|
| 6475 |
-> {parent.journals.count} => 1,
|
|
| 6476 |
-> {child.journals.count} => 1,
|
|
| 6477 |
-> {grandchild1.journals.count} => 1,
|
|
| 6478 |
-> {grandchild2.journals.count} => 0
|
|
| 6479 |
) do |
|
| 6480 |
put( |
|
| 6481 |
:update, |
|
| 6482 |
:params => {
|
|
| 6483 |
:id => parent.id, |
|
| 6484 |
:close_descendants => "", |
|
| 6485 |
:issue => {
|
|
| 6486 |
:status_id => 5, |
|
| 6487 |
:notes => notes |
|
| 6488 |
} |
|
| 6489 |
} |
|
| 6490 |
) |
|
| 6491 |
assert_response 302 |
|
| 6492 |
end |
|
| 6493 |
assert 5, parent.reload.status.id |
|
| 6494 |
assert_equal notes, parent.journals.last.notes |
|
| 6495 |
assert 5, child.reload.status.id |
|
| 6496 |
assert_equal notes, child.journals.last.notes |
|
| 6497 |
assert 5, grandchild1.reload.status.id |
|
| 6498 |
assert_equal notes, grandchild1.journals.last.notes |
|
| 6499 |
assert 6, grandchild2.reload.status.id |
|
| 6500 |
end |
|
| 6501 |
end |
|
| 6502 | ||
| 6503 |
test "session generated by check_go_to_close_confirm should respect subtask statuses" do |
|
| 6504 |
with_settings :closed_parent_issues_with_open_subtasks => 1 do |
|
| 6505 |
WorkflowTransition.delete_all |
|
| 6506 |
WorkflowTransition.create!(:role_id => 1, :tracker_id => 1, |
|
| 6507 |
:old_status_id => 1, :new_status_id => 5) |
|
| 6508 |
WorkflowTransition.create!(:role_id => 1, :tracker_id => 1, |
|
| 6509 |
:old_status_id => 1, :new_status_id => 6) |
|
| 6510 |
WorkflowTransition.create!(:role_id => 1, :tracker_id => 2, |
|
| 6511 |
:old_status_id => 1, :new_status_id => 6) |
|
| 6512 |
user = User.find(2) |
|
| 6513 |
parent = |
|
| 6514 |
Issue. |
|
| 6515 |
generate!( |
|
| 6516 |
:author_id => 2, |
|
| 6517 |
:tracker_id => 1, |
|
| 6518 |
:status_id => 1 |
|
| 6519 |
) |
|
| 6520 |
child1 = |
|
| 6521 |
Issue. |
|
| 6522 |
generate!( |
|
| 6523 |
:author_id => 2, |
|
| 6524 |
:parent_issue_id => parent.id, |
|
| 6525 |
:tracker_id => 1, |
|
| 6526 |
:status_id => 1 |
|
| 6527 |
) |
|
| 6528 |
child2 = |
|
| 6529 |
Issue. |
|
| 6530 |
generate!( |
|
| 6531 |
:author_id => 2, |
|
| 6532 |
:parent_issue_id => parent.id, |
|
| 6533 |
:tracker_id => 2, |
|
| 6534 |
:status_id => 1 |
|
| 6535 |
) |
|
| 6536 |
assert parent.reload.visible?(user) |
|
| 6537 |
assert child1.reload.visible?(user) |
|
| 6538 |
assert child2.reload.visible?(user) |
|
| 6539 | ||
| 6540 |
assert [5, 6].all? do |id| |
|
| 6541 |
parent.new_statuses_allowed_to(user).map{|s| s.id}.include?(id)
|
|
| 6542 |
end |
|
| 6543 |
assert [5, 6].all? do |id| |
|
| 6544 |
child1.new_statuses_allowed_to(user).map{|s| s.id}.include?(id)
|
|
| 6545 |
end |
|
| 6546 |
assert_not child2.new_statuses_allowed_to(user).map{|s| s.id}.include?(5)
|
|
| 6547 |
assert child2.new_statuses_allowed_to(user).map{|s| s.id}.include?(6)
|
|
| 6548 | ||
| 6549 |
@request.session[:user_id] = user.id |
|
| 6550 |
put( |
|
| 6551 |
:update, |
|
| 6552 |
:params => {
|
|
| 6553 |
:id => parent.id, |
|
| 6554 |
:check_go_to_close_confirm => "", |
|
| 6555 |
:status_id => 6 |
|
| 6556 |
}, |
|
| 6557 |
:xhr => true |
|
| 6558 |
) |
|
| 6559 |
assert_response :success |
|
| 6560 |
assert_equal 'application/json', response.content_type |
|
| 6561 |
json = ActiveSupport::JSON.decode(response.body) |
|
| 6562 | ||
| 6563 |
assert_equal 1, parent.reload.status.id |
|
| 6564 |
assert_equal({"result" => true}, json)
|
|
| 6565 |
assert session.has_key?(:can_close_descendant) |
|
| 6566 |
assert session[:can_close_descendant][:can_close_all] |
|
| 6567 |
assert_equal [child1.id, child2.id], session[:can_close_descendant][:ids] |
|
| 6568 | ||
| 6569 |
@request.session.delete(:can_close_descendant) |
|
| 6570 | ||
| 6571 |
@request.session[:user_id] = user.id |
|
| 6572 |
put( |
|
| 6573 |
:update, |
|
| 6574 |
:params => {
|
|
| 6575 |
:id => parent.id, |
|
| 6576 |
:check_go_to_close_confirm => "", |
|
| 6577 |
:status_id => 5 |
|
| 6578 |
}, |
|
| 6579 |
:xhr => true |
|
| 6580 |
) |
|
| 6581 |
assert_response :success |
|
| 6582 |
assert_equal 'application/json', response.content_type |
|
| 6583 |
json = ActiveSupport::JSON.decode(response.body) |
|
| 6584 | ||
| 6585 |
assert_equal 1, parent.reload.status.id |
|
| 6586 |
assert_equal({"result" => true}, json)
|
|
| 6587 |
assert session.has_key?(:can_close_descendant) |
|
| 6588 |
assert_not session[:can_close_descendant][:can_close_all] |
|
| 6589 |
assert_not session[:can_close_descendant].has_key?(:ids) |
|
| 6590 |
end |
|
| 6591 |
end |
|
| 6592 | ||
| 6245 | 6593 |
def test_get_bulk_edit |
| 6246 | 6594 |
@request.session[:user_id] = 2 |
| 6247 | 6595 |
get(:bulk_edit, :params => {:ids => [1, 3]})
|
| test/system/issues_test.rb | ||
|---|---|---|
| 234 | 234 |
assert_equal 5, issue.reload.status.id |
| 235 | 235 |
end |
| 236 | 236 | |
| 237 |
test "add confirm dialog to issue submit button" do |
|
| 238 |
parent = Issue.generate!(:project_id => 1) |
|
| 239 |
child = Issue.generate!(:project_id => 1, :parent_issue_id => parent.id) |
|
| 240 |
hidden_child = |
|
| 241 |
Issue. |
|
| 242 |
generate!( |
|
| 243 |
:project_id => 1, |
|
| 244 |
:parent_issue_id => parent.id, |
|
| 245 |
:author_id => 2, |
|
| 246 |
:is_private => true |
|
| 247 |
) |
|
| 248 |
assert_not hidden_child.visible?(User.find(3)) |
|
| 249 |
with_settings :closed_parent_issues_with_open_subtasks => 1 do |
|
| 250 |
log_user('dlopper', 'foo')
|
|
| 251 |
visit "/issues/#{parent.id}"
|
|
| 252 | ||
| 253 |
page.first(:link, 'Edit').click |
|
| 254 |
assert page.has_select?("issue_status_id", {:selected => "New"})
|
|
| 255 |
page.find("#issue_status_id").select("Closed")
|
|
| 256 |
assert_no_difference ['Issue.count', 'child.journals.count'] do |
|
| 257 |
assert_no_difference 'parent.journals.count' do |
|
| 258 |
page.first(:button, 'Submit').click |
|
| 259 |
within('#ajax-modal') do
|
|
| 260 |
assert page.has_text?(/Are you sure/) |
|
| 261 |
page.first(:link, 'Cancel').click |
|
| 262 |
end |
|
| 263 |
assert_equal 1, parent.reload.status.id |
|
| 264 |
end |
|
| 265 |
assert_difference 'parent.journals.count' do |
|
| 266 |
page.first(:button, 'Submit').click |
|
| 267 |
within('#ajax-modal') do
|
|
| 268 |
assert page.has_text?(/Are you sure/) |
|
| 269 |
page.first(:button, 'Apply').click |
|
| 270 |
end |
|
| 271 |
assert page.has_css?('#flash_notice')
|
|
| 272 |
assert_equal 5, parent.reload.status.id |
|
| 273 |
end |
|
| 274 |
end |
|
| 275 | ||
| 276 |
page.first(:link, 'Edit').click |
|
| 277 |
assert page.has_select?("issue_status_id", {:selected => "Closed"})
|
|
| 278 |
fill_in 'Subject', :with => 'test of confirm dialog' |
|
| 279 |
assert_no_difference ['Issue.count', 'child.journals.count'] do |
|
| 280 |
assert_no_difference 'parent.journals.count' do |
|
| 281 |
page.first(:button, 'Submit').click |
|
| 282 |
within('#ajax-modal') do
|
|
| 283 |
assert page.has_text?(/Are you sure/) |
|
| 284 |
page.first(:link, 'Cancel').click |
|
| 285 |
end |
|
| 286 |
assert_equal 5, parent.reload.status.id |
|
| 287 |
end |
|
| 288 |
assert_difference 'parent.journals.count' do |
|
| 289 |
page.first(:button, 'Submit').click |
|
| 290 |
within('#ajax-modal') do
|
|
| 291 |
assert page.has_text?(/Are you sure/) |
|
| 292 |
page.first(:button, 'Apply').click |
|
| 293 |
end |
|
| 294 |
assert page.has_css?('#flash_notice')
|
|
| 295 |
assert_equal 5, parent.reload.status.id |
|
| 296 |
assert_equal 'test of confirm dialog', parent.reload.subject |
|
| 297 |
end |
|
| 298 |
end |
|
| 299 | ||
| 300 |
page.first(:link, 'Edit').click |
|
| 301 |
assert page.has_select?("issue_status_id", {:selected => "Closed"})
|
|
| 302 |
page.find("#issue_status_id").select("New")
|
|
| 303 |
assert_no_difference ['Issue.count', 'child.journals.count'] do |
|
| 304 |
assert_difference 'parent.journals.count' do |
|
| 305 |
page.first(:button, 'Submit').click |
|
| 306 |
assert page.has_css?('#flash_notice')
|
|
| 307 |
assert_equal 1, parent.reload.status.id |
|
| 308 |
end |
|
| 309 |
end |
|
| 310 | ||
| 311 |
visit "/issues/#{child.id}"
|
|
| 312 |
page.first(:link, 'Edit').click |
|
| 313 |
assert page.has_select?("issue_status_id", {:selected => "New"})
|
|
| 314 |
page.find("#issue_status_id").select("Closed")
|
|
| 315 |
assert_no_difference ['Issue.count', 'parent.journals.count'] do |
|
| 316 |
assert_difference 'child.journals.count' do |
|
| 317 |
page.first(:button, 'Submit').click |
|
| 318 |
assert page.has_css?('#flash_notice')
|
|
| 319 |
assert_equal 5, child.reload.status.id |
|
| 320 |
end |
|
| 321 |
end |
|
| 322 | ||
| 323 |
hidden_child.status_id = 5 |
|
| 324 |
hidden_child.save! |
|
| 325 | ||
| 326 |
visit "/issues/#{parent.id}"
|
|
| 327 |
page.first(:link, 'Edit').click |
|
| 328 |
assert page.has_select?("issue_status_id", {:selected => "New"})
|
|
| 329 |
page.find("#issue_status_id").select("Closed")
|
|
| 330 |
assert_no_difference ['Issue.count', 'child.journals.count'] do |
|
| 331 |
assert_difference 'parent.journals.count' do |
|
| 332 |
page.first(:button, 'Submit').click |
|
| 333 |
assert page.has_css?('#flash_notice')
|
|
| 334 |
assert_equal 5, parent.reload.status.id |
|
| 335 |
end |
|
| 336 |
end |
|
| 337 |
end |
|
| 338 |
end |
|
| 339 | ||
| 340 |
test "close all open subtasks" do |
|
| 341 |
parent = Issue.generate!(:project_id => 1) |
|
| 342 |
child = Issue.generate!(:project_id => 1, :parent_issue_id => parent.id) |
|
| 343 |
close_only_text = "Close only issue #{parent.id}"
|
|
| 344 | ||
| 345 |
with_settings :closed_parent_issues_with_open_subtasks => 1 do |
|
| 346 |
log_user('dlopper', 'foo')
|
|
| 347 |
visit "/issues/#{parent.id}"
|
|
| 348 |
page.first(:link, 'Edit').click |
|
| 349 |
assert page.has_select?("issue_status_id", {:selected => "New"})
|
|
| 350 |
page.find("#issue_status_id").select("Closed")
|
|
| 351 |
assert_no_difference ['Issue.count', 'child.journals.count'] do |
|
| 352 |
assert_no_difference 'parent.journals.count' do |
|
| 353 |
page.first(:button, 'Submit').click |
|
| 354 |
within('#ajax-modal') do
|
|
| 355 |
assert page.has_text?(/has open subtasks/) |
|
| 356 |
assert page.has_checked_field?(close_only_text) |
|
| 357 |
page.first(:link, 'Cancel').click |
|
| 358 |
end |
|
| 359 |
assert_equal 1, parent.reload.status.id |
|
| 360 |
end |
|
| 361 |
assert_difference 'parent.journals.count' do |
|
| 362 |
page.first(:button, 'Submit').click |
|
| 363 |
within('#ajax-modal') do
|
|
| 364 |
assert page.has_text?(/has open subtasks/) |
|
| 365 |
assert page.has_checked_field?(close_only_text) |
|
| 366 |
page.first(:button, 'Apply').click |
|
| 367 |
end |
|
| 368 |
assert page.has_css?('#flash_notice')
|
|
| 369 |
assert_equal 5, parent.reload.status.id |
|
| 370 |
end |
|
| 371 |
end |
|
| 372 |
page.first(:link, 'Edit').click |
|
| 373 |
assert page.has_select?("issue_status_id", {:selected => "Closed"})
|
|
| 374 |
page.find("#issue_status_id").select("New")
|
|
| 375 |
assert_no_difference ['Issue.count', 'child.journals.count'] do |
|
| 376 |
assert_difference 'parent.journals.count' do |
|
| 377 |
page.first(:button, 'Submit').click |
|
| 378 |
assert page.has_css?('#flash_notice')
|
|
| 379 |
assert_equal 1, parent.reload.status.id |
|
| 380 |
end |
|
| 381 |
end |
|
| 382 |
page.first(:link, 'Edit').click |
|
| 383 |
assert page.has_select?("issue_status_id", {:selected => "New"})
|
|
| 384 |
page.find("#issue_status_id").select("Closed")
|
|
| 385 |
assert_no_difference 'Issue.count' do |
|
| 386 |
assert_difference ['parent.journals.count', 'child.journals.count'] do |
|
| 387 |
page.first(:button, 'Submit').click |
|
| 388 |
within('#ajax-modal') do
|
|
| 389 |
all_text = 'Close all open subtasks by "Closed" status' |
|
| 390 |
assert page.has_text?(/has open subtasks/) |
|
| 391 |
assert page.has_checked_field?(close_only_text) |
|
| 392 |
page.choose(all_text) |
|
| 393 |
assert page.has_checked_field?(all_text) |
|
| 394 |
page.first(:button, 'Apply').click |
|
| 395 |
end |
|
| 396 |
assert page.has_css?('#flash_notice')
|
|
| 397 |
assert_equal 5, parent.reload.status.id |
|
| 398 |
assert_equal 5, child.reload.status.id |
|
| 399 |
end |
|
| 400 |
end |
|
| 401 |
end |
|
| 402 |
end |
|
| 403 | ||
| 237 | 404 |
test "removing issue shows confirm dialog" do |
| 238 | 405 |
log_user('jsmith', 'jsmith')
|
| 239 | 406 |
visit '/issues/1' |