Feature #27988 » 0002-Add-subtask-link-should-open-the-new-issue-form-with-v2.patch
| app/helpers/issues_helper.rb | ||
|---|---|---|
|
# Returns a link for adding a new subtask to the given issue
|
||
|
def link_to_new_subtask(issue)
|
||
|
attrs = {
|
||
|
:parent_issue_id => issue
|
||
|
:parent_issue_id => issue,
|
||
|
:parent_tracker_id => issue.tracker_id
|
||
|
}
|
||
|
attrs[:tracker_id] = issue.tracker unless issue.tracker.disabled_core_fields.include?('parent_issue_id')
|
||
|
link_to(l(:button_add), new_project_issue_path(issue.project, :issue => attrs, :back_url => issue_path(issue)))
|
||
|
end
|
||
|
def trackers_options_for_select(issue)
|
||
|
trackers = issue.allowed_target_trackers
|
||
|
if issue.new_record? && issue.parent_issue_id.present?
|
||
|
trackers = trackers.reject do |tracker|
|
||
|
issue.tracker_id != tracker.id && tracker.disabled_core_fields.include?('parent_issue_id')
|
||
|
if params['issue'].present? && params['issue']['parent_tracker_id'].present?
|
||
|
parent_tracker_id = params['issue']['parent_tracker_id'].to_i
|
||
|
else
|
||
|
parent_tracker_id = Issue.find_by_id(issue.parent_issue_id).tracker.id
|
||
|
end
|
||
|
allowed_subtask_ids = Tracker.find(parent_tracker_id).allowed_subtask_ids
|
||
|
trackers = trackers.reject {|t| !allowed_subtask_ids.include?(t.id)}
|
||
|
issue.tracker_id = trackers.detect{|t| t.id == parent_tracker_id} ? parent_tracker_id : trackers.first unless params['issue']['tracker_id'].present?
|
||
|
end
|
||
|
trackers.collect {|t| [t.name, t.id]}
|
||
|
end
|
||
| app/models/tracker.rb | ||
|---|---|---|
|
end
|
||
|
end
|
||
|
def allowed_subtask_ids
|
||
|
self.subtasks.map(&:id)
|
||
|
end
|
||
|
def allowed_subtask?(subtask_id)
|
||
|
self.subtasks.where(:trackers_subtasks => { :subtask_id => subtask_id }).exists?
|
||
|
end
|
||
|
def can_have_subtasks?
|
||
|
@can_have_subtasks ||= self.subtasks.any?
|
||
|
end
|
||
|
private
|
||
|
def check_integrity
|
||
|
raise Exception.new("Cannot delete tracker") if Issue.where(:tracker_id => self.id).any?
|
||
| app/views/issues/show.html.erb | ||
|---|---|---|
|
<%= call_hook(:view_issues_show_description_bottom, :issue => @issue) %>
|
||
|
<% if !@issue.leaf? || User.current.allowed_to?(:manage_subtasks, @project) %>
|
||
|
<% if !@issue.leaf? || (User.current.allowed_to?(:manage_subtasks, @project) && @issue.tracker.can_have_subtasks?) %>
|
||
|
<hr />
|
||
|
<div id="issue_tree">
|
||
|
<div class="contextual">
|
||
|
<%= link_to_new_subtask(@issue) if User.current.allowed_to?(:manage_subtasks, @project) %>
|
||
|
<%= link_to_new_subtask(@issue) if User.current.allowed_to?(:manage_subtasks, @project) && @issue.tracker.can_have_subtasks? %>
|
||
|
</div>
|
||
|
<p><strong><%=l(:label_subtask_plural)%></strong></p>
|
||
|
<%= form_tag({}, :data => {:cm_url => issues_context_menu_path}) do %>
|
||
| test/functional/issues_controller_test.rb | ||
|---|---|---|
|
:issue_relations,
|
||
|
:versions,
|
||
|
:trackers,
|
||
|
:trackers_subtasks,
|
||
|
:projects_trackers,
|
||
|
:issue_categories,
|
||
|
:enabled_modules,
|
||
| ... | ... | |
|
end
|
||
|
end
|
||
|
def test_new_with_parent_issue_id_should_default_to_first_tracker_without_disabled_parent_field
|
||
|
def test_new_with_parent_issue_id_should_default_to_first_valid_tracker
|
||
|
tracker = Tracker.find(1)
|
||
|
tracker.core_fields -= ['parent_issue_id']
|
||
|
tracker.subtask_ids = [2]
|
||
|
tracker.save!
|
||
|
@request.session[:user_id] = 2
|
||
| ... | ... | |
|
}
|
||
|
assert_response :success
|
||
|
assert_select 'select[name=?]', 'issue[tracker_id]' do
|
||
|
assert_select 'option', 2
|
||
|
assert_select 'option', 1
|
||
|
assert_select 'option[value="2"][selected=selected]'
|
||
|
assert_select 'option[value="3"]', 0
|
||
|
assert_select 'option[value="1"]', 0
|
||
|
end
|
||
|
end
|
||
|
def test_new_with_parent_issue_id_should_default_to_same_tracker_if_is_valid
|
||
|
@request.session[:user_id] = 2
|
||
|
get :new, :params => {
|
||
|
:project_id => 1,
|
||
|
:issue => {
|
||
|
:parent_issue_id => 2
|
||
|
}
|
||
|
}
|
||
|
assert_response :success
|
||
|
assert_select 'select[name=?]', 'issue[tracker_id]' do
|
||
|
assert_select 'option', 3
|
||
|
assert_select 'option[value="2"][selected=selected]'
|
||
|
end
|
||
|
end
|
||
|
def test_new_without_allowed_trackers_should_respond_with_403
|
||
|
role = Role.find(1)
|
||
|
role.set_permission_trackers 'add_issues', []
|
||
| ... | ... | |
|
end
|
||
|
end
|
||
|
end
|
||
|
def test_show_should_display_subtasks_section_for_issue_with_subtasks_and_which_cannot_have_subtasks
|
||
|
Issue.create!(:project_id => 1, :author_id => 1, :tracker_id => 1, :parent_issue_id => 1, :subject => 'Child Issue')
|
||
|
tracker = Tracker.find(1)
|
||
|
tracker.subtask_ids = ['']
|
||
|
tracker.save!
|
||
|
@request.session[:user_id] = 1
|
||
|
get :show, :params => {
|
||
|
:id => 1
|
||
|
}
|
||
|
assert_response :success
|
||
|
assert_select 'div#issue_tree' do
|
||
|
# assert that the subtasks are listed
|
||
|
assert_select 'td.subject', :text => /Child Issue/
|
||
|
# assert that the link for adding subtask is not shown
|
||
|
assert_select 'div.contextual a', 0
|
||
|
end
|
||
|
end
|
||
|
def test_show_should_not_display_subtasks_section_for_issue_without_subtasks_and_which_cannot_have_subtasks
|
||
|
tracker = Tracker.find(1)
|
||
|
tracker.subtask_ids = ['']
|
||
|
tracker.save!
|
||
|
@request.session[:user_id] = 1
|
||
|
get :show, :params => {
|
||
|
:id => 1
|
||
|
}
|
||
|
assert_response :success
|
||
|
assert_select 'div#issue_tree', 0
|
||
|
end
|
||
|
def test_show_add_subtask_link_should_include_parent_tracker_id
|
||
|
@request.session[:user_id] = 1
|
||
|
get :show, :params => {
|
||
|
:id => 1
|
||
|
}
|
||
|
assert_response :success
|
||
|
assert_select 'div#issue_tree div.contextual a[href*=?]', "parent_tracker_id%5D=1"
|
||
|
end
|
||
|
end
|
||
- « Previous
- 1
- …
- 5
- 6
- 7
- Next »