def status_by_options_for_select(value)
options_for_select(STATUS_BY_CRITERIAS.collect {|criteria| [l("field_#{criteria}".to_sym), criteria]}, value)
end
+
+ def link_to_new_issue(version, project)
+ if version.open? && User.current.allowed_to?(:add_issues, project)
+ trackers = Issue.allowed_target_trackers(project)
+
+ unless trackers.empty?
+ issue = Issue.new(:project => project)
+ new_issue_tracker = trackers.detect do |tracker|
+ issue.tracker = tracker
+ issue.safe_attribute?('fixed_version_id')
+ end
+ end
+
+ if new_issue_tracker
+ attrs = {
+ :tracker_id => new_issue_tracker,
+ :fixed_version_id => version.id
+ }
+ link_to l(:label_issue_new), new_project_issue_path(project, :issue => attrs), :class => 'icon icon-add'
+ end
+ end
+ end
end
<%= link_to(l(:button_edit), edit_version_path(@version), :class => 'icon icon-edit') if User.current.allowed_to?(:manage_versions, @version.project) %>
<%= link_to_if_authorized(l(:button_edit_associated_wikipage, :page_title => @version.wiki_page_title), {:controller => 'wiki', :action => 'edit', :project_id => @version.project, :id => Wiki.titleize(@version.wiki_page_title)}, :class => 'icon icon-edit') unless @version.wiki_page_title.blank? || @version.project.wiki.nil? %>
<%= delete_link version_path(@version, :back_url => url_for(:controller => 'versions', :action => 'index', :project_id => @version.project)) if User.current.allowed_to?(:manage_versions, @version.project) %>
+<%= link_to_new_issue(@version, @project) %>
<%= call_hook(:view_versions_show_contextual, { :version => @version, :project => @project }) %>
</div>
version.project = Project.find(5)
assert_match /^\/issues\?/, version_filtered_issues_path(version)
end
+
+ def test_link_to_new_issue_should_return_link_to_add_issue
+ version = Version.find(3)
+ project = Project.find(1)
+ User.current = User.find(1)
+
+ # href should contain the following params:
+ # fixed_version_id=3
+ # tracker_id=1
+ assert_select_in link_to_new_issue(version, project), '[href=?]', '/projects/ecookbook/issues/new?issue%5Bfixed_version_id%5D=3&issue%5Btracker_id%5D=1', :text => 'New issue'
+ end
+
+ def test_link_to_new_issue_should_return_nil_if_version_status_is_not_open
+ # locked version
+ version = Version.find(2)
+ project = Project.find(1)
+ User.current = User.find(1)
+
+ assert_nil link_to_new_issue(version, project)
+ end
+
+ def test_link_to_new_issue_should_return_nil_if_user_does_not_have_permission_to_add_issue
+ Role.find(1).remove_permission! :add_issues
+ version = Version.find(3)
+ project = Project.find(1)
+ User.current = User.find(2)
+
+ assert_nil link_to_new_issue(version, project)
+ end
+
+ def test_link_to_new_issue_should_return_nil_if_no_tracker_is_available_for_project
+ trackers = Tracker::CORE_FIELDS - %w(fixed_version_id)
+ # disable fixed_version_id field for all trackers
+ Tracker.all.each do |tracker|
+ tracker.core_fields = trackers
+ tracker.save!
+ end
+
+ version = Version.find(3)
+ project = Project.find(1)
+ User.current = User.find(2)
+
+ assert_nil link_to_new_issue(version, project)
+ end
+
+ def test_link_to_new_issue_should_take_into_account_user_permissions_on_fixed_version_id_field
+ WorkflowPermission.delete_all
+ WorkflowPermission.create!(:role_id => 1, :tracker_id => 1, :old_status_id => 1, :field_name => 'fixed_version_id', :rule => 'readonly')
+
+ version = Version.find(3)
+ project = Project.find(1)
+ User.current = User.find(2)
+
+ # href should contain param tracker_id=2 because for tracker_id 1, user has only readonly permissions on fixed_version_id
+ assert_select_in link_to_new_issue(version, project), '[href=?]', '/projects/ecookbook/issues/new?issue%5Bfixed_version_id%5D=3&issue%5Btracker_id%5D=2'
+ end
end