Feature #12704 » 12704_allow_selecting_subprojects_on_new_issue_page.patch
app/models/issue.rb | ||
---|---|---|
1505 | 1505 |
end |
1506 | 1506 | |
1507 | 1507 |
# Returns a scope of projects that user can assign the issue to |
1508 |
def allowed_target_projects(user=User.current) |
|
1509 |
current_project = new_record? ? nil : project |
|
1508 |
def allowed_target_projects(user=User.current, context=nil) |
|
1509 |
if new_record? && context.is_a?(Project) && !copy? |
|
1510 |
current_project = context.self_and_descendants |
|
1511 |
elsif new_record? |
|
1512 |
current_project = nil |
|
1513 |
else |
|
1514 |
current_project = project |
|
1515 |
end |
|
1516 | ||
1510 | 1517 |
self.class.allowed_target_projects(user, current_project) |
1511 | 1518 |
end |
1512 | 1519 | |
... | ... | |
1514 | 1521 |
# If current_project is given, it will be included in the scope |
1515 | 1522 |
def self.allowed_target_projects(user=User.current, current_project=nil) |
1516 | 1523 |
condition = Project.allowed_to_condition(user, :add_issues) |
1517 |
if current_project |
|
1524 |
if current_project.is_a?(Project)
|
|
1518 | 1525 |
condition = ["(#{condition}) OR #{Project.table_name}.id = ?", current_project.id] |
1526 |
elsif current_project |
|
1527 |
condition = ["(#{condition}) AND #{Project.table_name}.id IN (?)", current_project.map(&:id)] |
|
1519 | 1528 |
end |
1520 | 1529 |
Project.where(condition).having_trackers |
1521 | 1530 |
end |
app/views/issues/_form.html.erb | ||
---|---|---|
9 | 9 |
</p> |
10 | 10 |
<% end %> |
11 | 11 | |
12 |
<% if (@issue.safe_attribute?('project_id') || @issue.project_id_changed?) && (!@issue.new_record? || @project.nil? || @issue.copy?) %> |
|
13 |
<p><%= f.select :project_id, project_tree_options_for_select(@issue.allowed_target_projects, :selected => @issue.project), {:required => true}, |
|
12 |
<% projects = @issue.allowed_target_projects(User.current, @project) %> |
|
13 |
<% if (@issue.safe_attribute?('project_id') || @issue.project_id_changed?) && (@project.nil? || projects.count > 1 || @issue.copy?) %> |
|
14 |
<p><%= f.select :project_id, project_tree_options_for_select(projects, :selected => @issue.project), {:required => true}, |
|
14 | 15 |
:onchange => "updateIssueFrom('#{escape_javascript update_issue_form_path(@project, @issue)}', this)" %></p> |
15 | 16 |
<% end %> |
16 | 17 |
test/functional/issues_controller_test.rb | ||
---|---|---|
1812 | 1812 |
assert_select 'form#issue-form[action=?]', '/projects/ecookbook/issues' |
1813 | 1813 |
assert_select 'form#issue-form' do |
1814 | 1814 |
assert_select 'input[name=?]', 'issue[is_private]' |
1815 |
assert_select 'select[name=?]', 'issue[project_id]', 0
|
|
1815 |
assert_select 'select[name=?]', 'issue[project_id]' |
|
1816 | 1816 |
assert_select 'select[name=?]', 'issue[tracker_id]' |
1817 | 1817 |
assert_select 'input[name=?]', 'issue[subject]' |
1818 | 1818 |
assert_select 'textarea[name=?]', 'issue[description]' |
... | ... | |
1836 | 1836 |
end |
1837 | 1837 |
end |
1838 | 1838 | |
1839 |
def test_get_new_should_show_project_selector_for_project_with_subprojects |
|
1840 |
@request.session[:user_id] = 2 |
|
1841 |
get :new, :project_id => 1, :tracker_id => 1 |
|
1842 |
assert_response :success |
|
1843 | ||
1844 |
assert_select 'select[name="issue[project_id]"]' do |
|
1845 |
assert_select 'option', 3 |
|
1846 |
assert_select 'option[selected=selected]', :text => 'eCookbook' |
|
1847 |
assert_select 'option[value=?]', '5', :text => ' » Private child of eCookbook' |
|
1848 |
assert_select 'option[value=?]', '3', :text => ' » eCookbook Subproject 1' |
|
1849 | ||
1850 |
# user_id 2 is not allowed to add issues on project_id 4 (it's not a member) |
|
1851 |
assert_select 'option[value=?]', '4', 0 |
|
1852 |
end |
|
1853 |
end |
|
1854 | ||
1855 |
def test_get_new_should_not_show_project_selector_for_project_without_subprojects |
|
1856 |
@request.session[:user_id] = 2 |
|
1857 |
get :new, :project_id => 2, :tracker_id => 1 |
|
1858 |
assert_response :success |
|
1859 | ||
1860 |
assert_select 'select[name="issue[project_id]"]', 0 |
|
1861 |
end |
|
1862 | ||
1839 | 1863 |
def test_get_new_with_minimal_permissions |
1840 | 1864 |
Role.find(1).update_attribute :permissions, [:add_issues] |
1841 | 1865 |
WorkflowTransition.where(:role_id => 1).delete_all |
... | ... | |
1846 | 1870 | |
1847 | 1871 |
assert_select 'form#issue-form' do |
1848 | 1872 |
assert_select 'input[name=?]', 'issue[is_private]', 0 |
1849 |
assert_select 'select[name=?]', 'issue[project_id]', 0
|
|
1873 |
assert_select 'select[name=?]', 'issue[project_id]' |
|
1850 | 1874 |
assert_select 'select[name=?]', 'issue[tracker_id]' |
1851 | 1875 |
assert_select 'input[name=?]', 'issue[subject]' |
1852 | 1876 |
assert_select 'textarea[name=?]', 'issue[description]' |
test/unit/issue_test.rb | ||
---|---|---|
354 | 354 |
:subject => 'Assignment test', |
355 | 355 |
:assigned_to => group, |
356 | 356 |
:is_private => true) |
357 |
|
|
357 | ||
358 | 358 |
Role.find(2).update! :issues_visibility => 'default' |
359 | 359 |
issues = Issue.visible(User.find(8)).to_a |
360 | 360 |
assert issues.any? |
361 | 361 |
assert issues.include?(issue) |
362 |
|
|
362 | ||
363 | 363 |
Role.find(2).update! :issues_visibility => 'own' |
364 | 364 |
issues = Issue.visible(User.find(8)).to_a |
365 | 365 |
assert issues.any? |