]> source.dussan.org Git - redmine.git/commitdiff
Display new issue link in version page (#28138).
authorJean-Philippe Lang <jp_lang@yahoo.fr>
Sat, 19 Oct 2019 10:22:16 +0000 (10:22 +0000)
committerJean-Philippe Lang <jp_lang@yahoo.fr>
Sat, 19 Oct 2019 10:22:16 +0000 (10:22 +0000)
Patch by Marius BALTEANU.

git-svn-id: http://svn.redmine.org/redmine/trunk@18755 e93f8b46-1217-0410-a6f0-8f06a7374b81

app/helpers/versions_helper.rb
app/views/versions/show.html.erb
test/functional/versions_controller_test.rb
test/helpers/version_helper_test.rb

index bca980227efff5f331bcaa6124dfab0b20a40b30..cb7b61ffcd1f2869f1f5e77d482ee255d44bb572 100644 (file)
@@ -82,4 +82,26 @@ module VersionsHelper
   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
index e1b27ee0d87f49c510756a85fcdb36ab6cf3c389..d73485a8c4088014bb57db5cfa8a726da5ee27ec 100644 (file)
@@ -2,6 +2,7 @@
 <%= 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>
 
index 8981c69321b2842e09fd20410ad2e0f36ab6e269..44c683d7a07f3046f05a58da2a32a7c52dd9588c 100644 (file)
@@ -208,6 +208,14 @@ class VersionsControllerTest < Redmine::ControllerTest
     end
   end
 
+  def test_show_should_display_link_to_new_issue
+    @request.session[:user_id] = 1
+    get :show, :params => {:id => 3}
+
+    assert_response :success
+    assert_select 'a.icon.icon-add', :text => 'New issue'
+  end
+
   def test_new
     @request.session[:user_id] = 2
     get :new, :params => {:project_id => '1'}
index e1c83e22556eeda21cf580732b8c84be05c0d33b..9bdb4974966fdcfc406646d2586f435456f89d06 100644 (file)
@@ -53,4 +53,60 @@ class VersionsHelperTest < Redmine::HelperTest
     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