Feature #12704 » 12704_allow_selecting_subprojects_on_new_issue_page_17216.patch
app/models/issue.rb | ||
---|---|---|
1514 | 1514 |
end |
1515 | 1515 | |
1516 | 1516 |
# Returns a scope of projects that user can assign the issue to |
1517 |
def allowed_target_projects(user=User.current) |
|
1518 |
current_project = new_record? ? nil : project |
|
1517 |
def allowed_target_projects(user=User.current, context=nil) |
|
1518 |
if new_record? && context.is_a?(Project) && !copy? |
|
1519 |
current_project = context.self_and_descendants |
|
1520 |
elsif new_record? |
|
1521 |
current_project = nil |
|
1522 |
else |
|
1523 |
current_project = project |
|
1524 |
end |
|
1525 | ||
1519 | 1526 |
self.class.allowed_target_projects(user, current_project) |
1520 | 1527 |
end |
1521 | 1528 | |
... | ... | |
1523 | 1530 |
# If current_project is given, it will be included in the scope |
1524 | 1531 |
def self.allowed_target_projects(user=User.current, current_project=nil) |
1525 | 1532 |
condition = Project.allowed_to_condition(user, :add_issues) |
1526 |
if current_project |
|
1533 |
if current_project.is_a?(Project)
|
|
1527 | 1534 |
condition = ["(#{condition}) OR #{Project.table_name}.id = ?", current_project.id] |
1535 |
elsif current_project |
|
1536 |
condition = ["(#{condition}) AND #{Project.table_name}.id IN (?)", current_project.map(&:id)] |
|
1528 | 1537 |
end |
1529 | 1538 |
Project.where(condition).having_trackers |
1530 | 1539 |
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.length > 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 | ||
---|---|---|
2302 | 2302 |
assert_select 'form#issue-form[action=?]', '/projects/ecookbook/issues' |
2303 | 2303 |
assert_select 'form#issue-form' do |
2304 | 2304 |
assert_select 'input[name=?]', 'issue[is_private]' |
2305 |
assert_select 'select[name=?]', 'issue[project_id]', 0
|
|
2305 |
assert_select 'select[name=?]', 'issue[project_id]' |
|
2306 | 2306 |
assert_select 'select[name=?]', 'issue[tracker_id]' |
2307 | 2307 |
assert_select 'input[name=?]', 'issue[subject]' |
2308 | 2308 |
assert_select 'textarea[name=?]', 'issue[description]' |
... | ... | |
2326 | 2326 |
end |
2327 | 2327 |
end |
2328 | 2328 | |
2329 |
def test_get_new_should_show_project_selector_for_project_with_subprojects |
|
2330 |
@request.session[:user_id] = 2 |
|
2331 |
get :new, :params => { |
|
2332 |
:project_id => 1, |
|
2333 |
:tracker_id => 1 |
|
2334 |
} |
|
2335 |
assert_response :success |
|
2336 | ||
2337 |
assert_select 'select[name="issue[project_id]"]' do |
|
2338 |
assert_select 'option', 3 |
|
2339 |
assert_select 'option[selected=selected]', :text => 'eCookbook' |
|
2340 |
assert_select 'option[value=?]', '5', :text => ' » Private child of eCookbook' |
|
2341 |
assert_select 'option[value=?]', '3', :text => ' » eCookbook Subproject 1' |
|
2342 | ||
2343 |
# user_id 2 is not allowed to add issues on project_id 4 (it's not a member) |
|
2344 |
assert_select 'option[value=?]', '4', 0 |
|
2345 |
end |
|
2346 |
end |
|
2347 | ||
2348 |
def test_get_new_should_not_show_project_selector_for_project_without_subprojects |
|
2349 |
@request.session[:user_id] = 2 |
|
2350 |
get :new, :params => { |
|
2351 |
:project_id => 2, |
|
2352 |
:tracker_id => 1 |
|
2353 |
} |
|
2354 |
assert_response :success |
|
2355 | ||
2356 |
assert_select 'select[name="issue[project_id]"]', 0 |
|
2357 |
end |
|
2358 | ||
2329 | 2359 |
def test_get_new_with_minimal_permissions |
2330 | 2360 |
Role.find(1).update_attribute :permissions, [:add_issues] |
2331 | 2361 |
WorkflowTransition.where(:role_id => 1).delete_all |
... | ... | |
2339 | 2369 | |
2340 | 2370 |
assert_select 'form#issue-form' do |
2341 | 2371 |
assert_select 'input[name=?]', 'issue[is_private]', 0 |
2342 |
assert_select 'select[name=?]', 'issue[project_id]', 0
|
|
2372 |
assert_select 'select[name=?]', 'issue[project_id]' |
|
2343 | 2373 |
assert_select 'select[name=?]', 'issue[tracker_id]' |
2344 | 2374 |
assert_select 'input[name=?]', 'issue[subject]' |
2345 | 2375 |
assert_select 'textarea[name=?]', 'issue[description]' |
- « Previous
- 1
- …
- 4
- 5
- 6
- Next »