Kaynağa Gözat

Allow selecting subprojects on new issue form (#12704).

Patch by Marius BALTEANU.


git-svn-id: http://svn.redmine.org/redmine/trunk@17217 e93f8b46-1217-0410-a6f0-8f06a7374b81
tags/4.0.0
Go MAEDA 6 yıl önce
ebeveyn
işleme
a175f9ded9

+ 12
- 3
app/models/issue.rb Dosyayı Görüntüle

end end


# Returns a scope of projects that user can assign the issue to # Returns a scope of projects that user can assign the issue to
def allowed_target_projects(user=User.current)
current_project = new_record? ? nil : project
def allowed_target_projects(user=User.current, context=nil)
if new_record? && context.is_a?(Project) && !copy?
current_project = context.self_and_descendants
elsif new_record?
current_project = nil
else
current_project = project
end

self.class.allowed_target_projects(user, current_project) self.class.allowed_target_projects(user, current_project)
end end


# If current_project is given, it will be included in the scope # If current_project is given, it will be included in the scope
def self.allowed_target_projects(user=User.current, current_project=nil) def self.allowed_target_projects(user=User.current, current_project=nil)
condition = Project.allowed_to_condition(user, :add_issues) condition = Project.allowed_to_condition(user, :add_issues)
if current_project
if current_project.is_a?(Project)
condition = ["(#{condition}) OR #{Project.table_name}.id = ?", current_project.id] condition = ["(#{condition}) OR #{Project.table_name}.id = ?", current_project.id]
elsif current_project
condition = ["(#{condition}) AND #{Project.table_name}.id IN (?)", current_project.map(&:id)]
end end
Project.where(condition).having_trackers Project.where(condition).having_trackers
end end

+ 3
- 2
app/views/issues/_form.html.erb Dosyayı Görüntüle

</p> </p>
<% end %> <% end %>


<% if (@issue.safe_attribute?('project_id') || @issue.project_id_changed?) && (!@issue.new_record? || @project.nil? || @issue.copy?) %>
<p><%= f.select :project_id, project_tree_options_for_select(@issue.allowed_target_projects, :selected => @issue.project), {:required => true},
<% projects = @issue.allowed_target_projects(User.current, @project) %>
<% if (@issue.safe_attribute?('project_id') || @issue.project_id_changed?) && (@project.nil? || projects.length > 1 || @issue.copy?) %>
<p><%= f.select :project_id, project_tree_options_for_select(projects, :selected => @issue.project), {:required => true},
:onchange => "updateIssueFrom('#{escape_javascript update_issue_form_path(@project, @issue)}', this)" %></p> :onchange => "updateIssueFrom('#{escape_javascript update_issue_form_path(@project, @issue)}', this)" %></p>
<% end %> <% end %>



+ 32
- 2
test/functional/issues_controller_test.rb Dosyayı Görüntüle

assert_select 'form#issue-form[action=?]', '/projects/ecookbook/issues' assert_select 'form#issue-form[action=?]', '/projects/ecookbook/issues'
assert_select 'form#issue-form' do assert_select 'form#issue-form' do
assert_select 'input[name=?]', 'issue[is_private]' assert_select 'input[name=?]', 'issue[is_private]'
assert_select 'select[name=?]', 'issue[project_id]', 0
assert_select 'select[name=?]', 'issue[project_id]'
assert_select 'select[name=?]', 'issue[tracker_id]' assert_select 'select[name=?]', 'issue[tracker_id]'
assert_select 'input[name=?]', 'issue[subject]' assert_select 'input[name=?]', 'issue[subject]'
assert_select 'textarea[name=?]', 'issue[description]' assert_select 'textarea[name=?]', 'issue[description]'
end end
end end


def test_get_new_should_show_project_selector_for_project_with_subprojects
@request.session[:user_id] = 2
get :new, :params => {
:project_id => 1,
:tracker_id => 1
}
assert_response :success

assert_select 'select[name="issue[project_id]"]' do
assert_select 'option', 3
assert_select 'option[selected=selected]', :text => 'eCookbook'
assert_select 'option[value=?]', '5', :text => '  » Private child of eCookbook'
assert_select 'option[value=?]', '3', :text => '  » eCookbook Subproject 1'

# user_id 2 is not allowed to add issues on project_id 4 (it's not a member)
assert_select 'option[value=?]', '4', 0
end
end

def test_get_new_should_not_show_project_selector_for_project_without_subprojects
@request.session[:user_id] = 2
get :new, :params => {
:project_id => 2,
:tracker_id => 1
}
assert_response :success

assert_select 'select[name="issue[project_id]"]', 0
end

def test_get_new_with_minimal_permissions def test_get_new_with_minimal_permissions
Role.find(1).update_attribute :permissions, [:add_issues] Role.find(1).update_attribute :permissions, [:add_issues]
WorkflowTransition.where(:role_id => 1).delete_all WorkflowTransition.where(:role_id => 1).delete_all


assert_select 'form#issue-form' do assert_select 'form#issue-form' do
assert_select 'input[name=?]', 'issue[is_private]', 0 assert_select 'input[name=?]', 'issue[is_private]', 0
assert_select 'select[name=?]', 'issue[project_id]', 0
assert_select 'select[name=?]', 'issue[project_id]'
assert_select 'select[name=?]', 'issue[tracker_id]' assert_select 'select[name=?]', 'issue[tracker_id]'
assert_select 'input[name=?]', 'issue[subject]' assert_select 'input[name=?]', 'issue[subject]'
assert_select 'textarea[name=?]', 'issue[description]' assert_select 'textarea[name=?]', 'issue[description]'

Loading…
İptal
Kaydet