Feature #27988 » 0002-Add-subtask-link-should-open-the-new-issue-form-with-v2.patch
app/helpers/issues_helper.rb | ||
---|---|---|
183 | 183 |
# Returns a link for adding a new subtask to the given issue |
184 | 184 |
def link_to_new_subtask(issue) |
185 | 185 |
attrs = { |
186 |
:parent_issue_id => issue |
|
186 |
:parent_issue_id => issue, |
|
187 |
:parent_tracker_id => issue.tracker_id |
|
187 | 188 |
} |
188 |
attrs[:tracker_id] = issue.tracker unless issue.tracker.disabled_core_fields.include?('parent_issue_id') |
|
189 | 189 |
link_to(l(:button_add), new_project_issue_path(issue.project, :issue => attrs, :back_url => issue_path(issue))) |
190 | 190 |
end |
191 | 191 | |
192 | 192 |
def trackers_options_for_select(issue) |
193 | 193 |
trackers = issue.allowed_target_trackers |
194 | 194 |
if issue.new_record? && issue.parent_issue_id.present? |
195 |
trackers = trackers.reject do |tracker| |
|
196 |
issue.tracker_id != tracker.id && tracker.disabled_core_fields.include?('parent_issue_id') |
|
195 |
if params['issue'].present? && params['issue']['parent_tracker_id'].present? |
|
196 |
parent_tracker_id = params['issue']['parent_tracker_id'].to_i |
|
197 |
else |
|
198 |
parent_tracker_id = Issue.find_by_id(issue.parent_issue_id).tracker.id |
|
197 | 199 |
end |
200 | ||
201 |
allowed_subtask_ids = Tracker.find(parent_tracker_id).allowed_subtask_ids |
|
202 |
trackers = trackers.reject {|t| !allowed_subtask_ids.include?(t.id)} |
|
203 |
issue.tracker_id = trackers.detect{|t| t.id == parent_tracker_id} ? parent_tracker_id : trackers.first unless params['issue']['tracker_id'].present? |
|
198 | 204 |
end |
199 | 205 |
trackers.collect {|t| [t.name, t.id]} |
200 | 206 |
end |
app/models/tracker.rb | ||
---|---|---|
141 | 141 |
end |
142 | 142 |
end |
143 |
def allowed_subtask_ids |
|
144 |
self.subtasks.map(&:id) |
|
145 |
end |
|
146 | ||
143 | 147 |
def allowed_subtask?(subtask_id) |
144 | 148 |
self.subtasks.where(:trackers_subtasks => { :subtask_id => subtask_id }).exists? |
145 | 149 |
end |
150 |
def can_have_subtasks? |
|
151 |
@can_have_subtasks ||= self.subtasks.any? |
|
152 |
end |
|
146 | 153 |
private |
147 | 154 |
def check_integrity |
148 | 155 |
raise Exception.new("Cannot delete tracker") if Issue.where(:tracker_id => self.id).any? |
app/views/issues/show.html.erb | ||
---|---|---|
96 | 96 |
<%= call_hook(:view_issues_show_description_bottom, :issue => @issue) %> |
97 |
<% if !@issue.leaf? || User.current.allowed_to?(:manage_subtasks, @project) %>
|
|
97 |
<% if !@issue.leaf? || (User.current.allowed_to?(:manage_subtasks, @project) && @issue.tracker.can_have_subtasks?) %>
|
|
98 | 98 |
<hr /> |
99 | 99 |
<div id="issue_tree"> |
100 | 100 |
<div class="contextual"> |
101 |
<%= link_to_new_subtask(@issue) if User.current.allowed_to?(:manage_subtasks, @project) %> |
|
101 |
<%= link_to_new_subtask(@issue) if User.current.allowed_to?(:manage_subtasks, @project) && @issue.tracker.can_have_subtasks? %>
|
|
102 | 102 |
</div> |
103 | 103 |
<p><strong><%=l(:label_subtask_plural)%></strong></p> |
104 | 104 |
<%= form_tag({}, :data => {:cm_url => issues_context_menu_path}) do %> |
test/functional/issues_controller_test.rb | ||
---|---|---|
28 | 28 |
:issue_relations, |
29 | 29 |
:versions, |
30 | 30 |
:trackers, |
31 |
:trackers_subtasks, |
|
31 | 32 |
:projects_trackers, |
32 | 33 |
:issue_categories, |
33 | 34 |
:enabled_modules, |
... | ... | |
2477 | 2478 |
end |
2478 | 2479 |
end |
2479 |
def test_new_with_parent_issue_id_should_default_to_first_tracker_without_disabled_parent_field
|
|
2480 |
def test_new_with_parent_issue_id_should_default_to_first_valid_tracker
|
|
2480 | 2481 |
tracker = Tracker.find(1) |
2481 | 2482 |
tracker.core_fields -= ['parent_issue_id'] |
2483 |
tracker.subtask_ids = [2] |
|
2482 | 2484 |
tracker.save! |
2483 | 2485 |
@request.session[:user_id] = 2 |
... | ... | |
2491 | 2493 |
} |
2492 | 2494 |
assert_response :success |
2493 | 2495 |
assert_select 'select[name=?]', 'issue[tracker_id]' do |
2494 |
assert_select 'option', 2
|
|
2496 |
assert_select 'option', 1
|
|
2495 | 2497 |
assert_select 'option[value="2"][selected=selected]' |
2498 |
assert_select 'option[value="3"]', 0 |
|
2496 | 2499 |
assert_select 'option[value="1"]', 0 |
2497 | 2500 |
end |
2498 | 2501 |
end |
2502 |
def test_new_with_parent_issue_id_should_default_to_same_tracker_if_is_valid |
|
2503 |
@request.session[:user_id] = 2 |
|
2504 |
get :new, :params => { |
|
2505 |
:project_id => 1, |
|
2506 |
:issue => { |
|
2507 |
:parent_issue_id => 2 |
|
2508 |
} |
|
2509 |
} |
|
2510 |
assert_response :success |
|
2511 |
assert_select 'select[name=?]', 'issue[tracker_id]' do |
|
2512 |
assert_select 'option', 3 |
|
2513 |
assert_select 'option[value="2"][selected=selected]' |
|
2514 |
end |
|
2515 |
end |
|
2516 | ||
2499 | 2517 |
def test_new_without_allowed_trackers_should_respond_with_403 |
2500 | 2518 |
role = Role.find(1) |
2501 | 2519 |
role.set_permission_trackers 'add_issues', [] |
... | ... | |
6574 | 6592 |
end |
6575 | 6593 |
end |
6576 | 6594 |
end |
6595 | ||
6596 |
def test_show_should_display_subtasks_section_for_issue_with_subtasks_and_which_cannot_have_subtasks |
|
6597 |
Issue.create!(:project_id => 1, :author_id => 1, :tracker_id => 1, :parent_issue_id => 1, :subject => 'Child Issue') |
|
6598 |
tracker = Tracker.find(1) |
|
6599 |
tracker.subtask_ids = [''] |
|
6600 |
tracker.save! |
|
6601 | ||
6602 |
@request.session[:user_id] = 1 |
|
6603 |
get :show, :params => { |
|
6604 |
:id => 1 |
|
6605 |
} |
|
6606 |
assert_response :success |
|
6607 | ||
6608 |
assert_select 'div#issue_tree' do |
|
6609 |
# assert that the subtasks are listed |
|
6610 |
assert_select 'td.subject', :text => /Child Issue/ |
|
6611 |
# assert that the link for adding subtask is not shown |
|
6612 |
assert_select 'div.contextual a', 0 |
|
6613 |
end |
|
6614 |
end |
|
6615 | ||
6616 |
def test_show_should_not_display_subtasks_section_for_issue_without_subtasks_and_which_cannot_have_subtasks |
|
6617 |
tracker = Tracker.find(1) |
|
6618 |
tracker.subtask_ids = [''] |
|
6619 |
tracker.save! |
|
6620 | ||
6621 |
@request.session[:user_id] = 1 |
|
6622 |
get :show, :params => { |
|
6623 |
:id => 1 |
|
6624 |
} |
|
6625 |
assert_response :success |
|
6626 | ||
6627 |
assert_select 'div#issue_tree', 0 |
|
6628 |
end |
|
6629 | ||
6630 |
def test_show_add_subtask_link_should_include_parent_tracker_id |
|
6631 |
@request.session[:user_id] = 1 |
|
6632 |
get :show, :params => { |
|
6633 |
:id => 1 |
|
6634 |
} |
|
6635 |
assert_response :success |
|
6636 | ||
6637 |
assert_select 'div#issue_tree div.contextual a[href*=?]', "parent_tracker_id%5D=1" |
|
6638 |
end |
|
6639 | ||
6640 | ||
6577 | 6641 |
end |
- « Previous
- 1
- …
- 5
- 6
- 7
- Next »