Defect #33419 » 0001-Take-into-account-the-setting-Setting.cross_project_.patch
app/helpers/issues_helper.rb | ||
---|---|---|
696 | 696 |
user_default_tab |
697 | 697 |
end |
698 | 698 |
end |
699 | ||
700 |
def projects_for_select(issue) |
|
701 |
if issue.parent_issue_id.present? |
|
702 |
issue.allowed_target_projects_for_subtask(User.current) |
|
703 |
elsif issue.new_record? && !issue.copy? |
|
704 |
issue.allowed_target_projects(User.current, 'descendants') |
|
705 |
else |
|
706 |
issue.allowed_target_projects(User.current) |
|
707 |
end |
|
708 |
end |
|
699 | 709 |
end |
app/models/issue.rb | ||
---|---|---|
1550 | 1550 |
end |
1551 | 1551 |
end |
1552 | 1552 | |
1553 |
# Returns a scope of projects that user can assign the subtask |
|
1554 |
def allowed_target_projects_for_subtask(user=User.current) |
|
1555 |
if parent_issue_id.present? |
|
1556 |
scope = filter_projects_scope(Setting.cross_project_subtasks) |
|
1557 |
end |
|
1558 | ||
1559 |
self.class.allowed_target_projects(user, project, scope) |
|
1560 |
end |
|
1561 | ||
1553 | 1562 |
# Returns a scope of projects that user can assign the issue to |
1554 |
def allowed_target_projects(user=User.current, context=nil) |
|
1555 |
if new_record? && context.is_a?(Project) && !copy? |
|
1556 |
current_project = context.self_and_descendants |
|
1557 |
elsif new_record? |
|
1558 |
current_project = nil |
|
1559 |
else |
|
1560 |
current_project = project |
|
1563 |
def allowed_target_projects(user=User.current, scope=nil) |
|
1564 |
current_project = new_record? ? nil : project |
|
1565 |
if scope |
|
1566 |
scope = filter_projects_scope(scope) |
|
1561 | 1567 |
end |
1562 | 1568 | |
1563 |
self.class.allowed_target_projects(user, current_project) |
|
1569 |
self.class.allowed_target_projects(user, current_project, scope)
|
|
1564 | 1570 |
end |
1565 | 1571 | |
1566 | 1572 |
# Returns a scope of projects that user can assign issues to |
1567 | 1573 |
# If current_project is given, it will be included in the scope |
1568 |
def self.allowed_target_projects(user=User.current, current_project=nil) |
|
1574 |
def self.allowed_target_projects(user=User.current, current_project=nil, scope=nil)
|
|
1569 | 1575 |
condition = Project.allowed_to_condition(user, :add_issues) |
1570 |
if current_project.is_a?(Project)
|
|
1576 |
if current_project |
|
1571 | 1577 |
condition = ["(#{condition}) OR #{Project.table_name}.id = ?", current_project.id] |
1572 |
elsif current_project |
|
1573 |
condition = ["(#{condition}) AND #{Project.table_name}.id IN (?)", current_project.map(&:id)] |
|
1574 | 1578 |
end |
1575 |
Project.where(condition).having_trackers |
|
1579 | ||
1580 |
if scope.nil? |
|
1581 |
scope = Project |
|
1582 |
end |
|
1583 | ||
1584 |
scope.where(condition).having_trackers |
|
1576 | 1585 |
end |
1577 | 1586 | |
1578 | 1587 |
# Returns a scope of trackers that user can assign the issue to |
... | ... | |
1906 | 1915 |
self.done_ratio ||= 0 |
1907 | 1916 |
end |
1908 | 1917 |
end |
1918 | ||
1919 |
def filter_projects_scope(scope=nil) |
|
1920 |
case scope |
|
1921 |
when 'system' |
|
1922 |
Project |
|
1923 |
when 'tree' |
|
1924 |
project.root.self_and_descendants |
|
1925 |
when 'hierarchy' |
|
1926 |
project.hierarchy |
|
1927 |
when 'descendants' |
|
1928 |
project.self_and_descendants |
|
1929 |
when '' |
|
1930 |
Project.where(:id => project.id) |
|
1931 |
else |
|
1932 |
Project |
|
1933 |
end |
|
1934 |
end |
|
1909 | 1935 |
end |
app/views/issues/_attributes.html.erb | ||
---|---|---|
61 | 61 |
<div class="splitcontentright"> |
62 | 62 |
<% if @issue.safe_attribute? 'parent_issue_id' %> |
63 | 63 |
<p id="parent_issue"><%= f.text_field :parent_issue_id, :size => 10, |
64 |
:required => @issue.required_attribute?('parent_issue_id') %></p> |
|
64 |
:required => @issue.required_attribute?('parent_issue_id'), |
|
65 |
:onchange => "updateIssueFrom('#{escape_javascript update_issue_form_path(@project, @issue)}', this)" %></p> |
|
65 | 66 |
<%= javascript_tag "observeAutocompleteField('issue_parent_issue_id', '#{escape_javascript(auto_complete_issues_path(:project_id => @issue.project, :scope => Setting.cross_project_subtasks, :status => @issue.closed? ? 'c' : 'o', :issue_id => @issue.id))}')" %> |
66 | 67 |
<% end %> |
67 | 68 |
app/views/issues/_form.html.erb | ||
---|---|---|
9 | 9 |
</p> |
10 | 10 |
<% end %> |
11 | 11 | |
12 |
<% projects = @issue.allowed_target_projects(User.current, @project) %>
|
|
12 |
<% projects = projects_for_select(@issue) %>
|
|
13 | 13 |
<% if (@issue.safe_attribute?('project_id') || @issue.project_id_changed?) && (@project.nil? || projects.length > 1 || @issue.copy?) %> |
14 | 14 |
<p><%= f.select :project_id, project_tree_options_for_select(projects, :selected => @issue.project), {:required => true}, |
15 | 15 |
:onchange => "updateIssueFrom('#{escape_javascript update_issue_form_path(@project, @issue)}', this)" %></p> |
test/functional/issues_controller_test.rb | ||
---|---|---|
3100 | 3100 |
assert_select 'select[name="issue[project_id]"]', 0 |
3101 | 3101 |
end |
3102 | 3102 | |
3103 |
def test_get_new_should_not_show_invalid_projects_when_issue_is_a_subtask |
|
3104 |
@request.session[:user_id] = 2 |
|
3105 |
issue = Issue.find(1) |
|
3106 |
issue.parent_id = 3 |
|
3107 |
issue.save |
|
3108 | ||
3109 |
with_settings :cross_project_subtasks => 'tree' do |
|
3110 |
get( |
|
3111 |
:new, |
|
3112 |
:params => { |
|
3113 |
:project_id => 1, |
|
3114 |
:parent_issue_id => 1 |
|
3115 |
} |
|
3116 |
) |
|
3117 |
end |
|
3118 |
assert_response :success |
|
3119 |
assert_select 'select[name="issue[project_id]"]' do |
|
3120 |
assert_select 'option', 3 |
|
3121 | ||
3122 |
# Onlinestore project should not be included |
|
3123 |
assert_select 'option[value=?]', '2', 0 |
|
3124 |
end |
|
3125 |
end |
|
3126 | ||
3103 | 3127 |
def test_get_new_with_minimal_permissions |
3104 | 3128 |
Role.find(1).update_attribute :permissions, [:add_issues] |
3105 | 3129 |
WorkflowTransition.where(:role_id => 1).delete_all |
test/unit/issue_test.rb | ||
---|---|---|
1708 | 1708 |
assert_not_include project, Issue.allowed_target_projects(User.find(1)) |
1709 | 1709 |
end |
1710 | 1710 | |
1711 |
def test_allowed_target_projects_for_subtask_should_not_include_invalid_projects |
|
1712 |
User.current = User.find(1) |
|
1713 |
issue = Issue.find(1) |
|
1714 |
issue.parent_id = 3 |
|
1715 | ||
1716 |
with_settings :cross_project_subtasks => 'tree' do |
|
1717 |
# Should include only the project tree |
|
1718 |
assert_equal [1, 3, 5], issue.allowed_target_projects_for_subtask.ids.sort |
|
1719 |
end |
|
1720 |
end |
|
1721 | ||
1711 | 1722 |
def test_allowed_target_trackers_with_one_role_allowed_on_all_trackers |
1712 | 1723 |
user = User.generate! |
1713 | 1724 |
role = Role.generate! |
... | ... | |
3343 | 3354 |
assert !child.reopenable? |
3344 | 3355 |
assert_equal l(:notice_issue_not_reopenable_by_closed_parent_issue), child.transition_warning |
3345 | 3356 |
end |
3357 | ||
3358 |
def test_filter_projects_scope |
|
3359 |
Issue.send(:public, :filter_projects_scope) |
|
3360 |
# Project eCookbook |
|
3361 |
issue = Issue.find(1) |
|
3362 | ||
3363 |
assert_equal Project, issue.filter_projects_scope |
|
3364 |
assert_equal Project, issue.filter_projects_scope('system') |
|
3365 | ||
3366 |
# Project Onlinestore (id 2) is not part of the tree |
|
3367 |
assert_equal [1, 3, 4, 5, 6], Issue.find(5).filter_projects_scope('tree').ids.sort |
|
3368 | ||
3369 |
# Project "Private child of eCookbook" |
|
3370 |
issue2 = Issue.find(9) |
|
3371 | ||
3372 |
# Projects "eCookbook Subproject 1" (id 3) and "eCookbook Subproject 1" (id 4) are not part of hierarchy |
|
3373 |
assert_equal [1, 5, 6], issue2.filter_projects_scope('hierarchy').ids.sort |
|
3374 | ||
3375 |
# Project "Child of private child" is descendant of "Private child of eCookbook" |
|
3376 |
assert_equal [5, 6], issue2.filter_projects_scope('descendants').ids.sort |
|
3377 | ||
3378 |
assert_equal [5], issue2.filter_projects_scope('').ids.sort |
|
3379 |
end |
|
3346 | 3380 |
end |