Feature #12704

Allow selecting subprojects on new issue form

Added by Adnan Topçu over 5 years ago. Updated 5 months ago.

Status:ClosedStart date:
Priority:NormalDue date:
Assignee:Go MAEDA% Done:

0%

Category:Issues
Target version:4.0.0
Resolution:Fixed

Description

happy new years!
As you know, redmine sub task mechanism supported cross-project since version 2.2.
But there is no project field on the new issue form. This is a need, when we creating new issue by the link "Sub task Add" on the parent issue.

select_project.patch Magnifier (2.08 KB) Bastian B., 2014-05-24 00:23

project-select.patch Magnifier (2.1 KB) Greg T, 2016-10-26 15:46

12704_allow_selecting_subprojects_on_new_issue_page.patch Magnifier (5.45 KB) Marius BALTEANU, 2017-04-11 00:29

12704-before@2x.png (28.4 KB) Go MAEDA, 2017-07-20 02:22

12704-after@2x.png (17.4 KB) Go MAEDA, 2017-07-20 02:22

12704_allow_selecting_subprojects_on_new_issue_page_17216.patch Magnifier (4.89 KB) Marius BALTEANU, 2018-02-26 22:33


Related issues

Related to Redmine - Feature #16067: Generic New Issue page New
Related to Redmine - Feature #17286: change project while creating a ticket New
Duplicated by Redmine - Feature #19838: Project selection while creation a new issue Closed
Duplicated by Redmine - Feature #26639: Enabling creating issue within the project regarding the ... Closed

Associated revisions

Revision 17217
Added by Go MAEDA 5 months ago

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

Patch by Marius BALTEANU.

History

#1 Updated by Toshi MARUYAMA over 4 years ago

#2 Updated by Bastian B. about 4 years ago

This can be implemented pretty easily as it seems.

You have to edit

apps/models/issue.rb

and change (starting at line 358)
  safe_attributes 'project_id',
    :if => lambda {|issue, user|
      if issue.new_record?
        issue.copy?
      elsif user.allowed_to?(:move_issues, issue.project)
        Issue.allowed_target_projects_on_move.count > 1
      end
    }

to
  safe_attributes 'project_id',
    :if => lambda {|issue, user|
      if issue.new_record?
        true
      elsif user.allowed_to?(:move_issues, issue.project)
        Issue.allowed_target_projects_on_move.count > 1
      end
    }

This will add the project selection drop-down box for all new issues, incl. subtasks.

I am not sure if there are any side effects, so use this hint at your own risk :-)

#3 Updated by Bastian B. about 4 years ago

Patch that enables to configure the behavior (to select the project) via the settings.

#4 Updated by Quan VN almost 4 years ago

Hi Bastian
The patch is working great. However, I hit another wall. I have project1 with only tracker1, and project2 with tracker2. Then from project1 I create a subtask in project2, I expect that the subtask will be tracker2 but it is not possible since the tracker list show only tracker1. Could you find the way for the tracker to be refreshed according to the selected project? Thank you very much
Quan

#5 Updated by Alex Stout almost 4 years ago

I too have tried this approach. It's definitely nice and would be the optimal way to go for those who organize everything with a boat-load of projects. I haven't noticed the issue that @Quan has mentioned. When the project is changed in the drop down, the javascript is executed and the correct form is loaded for that project–i.e. the correct fields and correct options.

However, my app has some plugins installed that have some fields on the issues form (particularly redmine_tags), and when the form is loaded for the new project, the plugin's field isn't correctly stylized (as a taggable select list). Essentially, the plugin's javascript is run when the page first loads, but when a new project is selected in the drop down, the plugin's javascript is not rerun as it should be. I haven't been able to track down where these hooks are made nor have I been able to add a js hack that could make the right calls. If this were to be fixed, this would be the way to go for me, but I can't have the tags field broken; it renders it useless and confusing.

#6 Updated by Toshi MARUYAMA almost 4 years ago

  • Description updated (diff)

#7 Updated by Toshi MARUYAMA about 3 years ago

  • Duplicated by Feature #19838: Project selection while creation a new issue added

#8 Updated by Sebastian Paluch about 3 years ago

+1
This is exactly what we need, it is huge effort to navigate between projects, especially when creating subtasks.

#9 Updated by Mustafa Bahadır Pakalın about 3 years ago

Sebastian Paluch wrote:

+1
This is exactly what we need, it is huge effort to navigate between projects, especially when creating subtasks.

That patch file not working on latest version of redmine.

#10 Updated by Mustafa Bahadır Pakalın about 3 years ago

Bastian B. wrote:

Patch that enables to configure the behavior (to select the project) via the settings.

Do u have the updated patch file ?

#11 Updated by Sebastian Paluch almost 3 years ago

The patch does not work due to a change done in r13999. The r13999 has actually implemented necessary change from the patch making project_id safe for new form but at the same time it has restricted project drop down for new issues by !@issue.new_record? in views\issues\_form.html.erb:

<% if @issue.safe_attribute?('project_id') && (!@issue.new_record? || @project.nil? || @issue.copy?) %>

To allow for project drop down when creating new issue or subtask it is enough to remove the "!" (or entire !@issue.new_record? from equation):
<% if @issue.safe_attribute?('project_id') && (@issue.new_record? || @project.nil? || @issue.copy?) %>

then the drop down shows up, form gets updated correctly when project is changed, trackers gets updated, parent issue id gets verified against cross project restrictions.

Does anyone see something that could prevent from applying this?

...and related to #1003.

#12 Updated by Harish Iyer over 2 years ago

Just wanted to check if above is Ok i.e. removing _record from the form. Should I do this in my install?

#13 Updated by Greg T about 2 years ago

Could you provide a plugin for this or integrate it into the core, please?

#14 Updated by Manuel Morales over 1 year ago

That patch file not working on latest version of redmine. Do you have the updated patch file ?

#15 Updated by Greg T over 1 year ago

Manuel Morales wrote:

Do you have the updated patch file ?

Do you mean this? (It works with redmine-3.3.1.)

diff -up redmine-3.2.1/app/views/issues/_form.html.erb.orig redmine-3.2.1/app/views/issues/_form.html.erb
--- redmine-3.2.1/app/views/issues/_form.html.erb.orig  2016-03-13 18:18:44.000000000 +0100
+++ redmine-3.2.1/app/views/issues/_form.html.erb       2016-06-08 16:36:32.921088980 +0200
@@ -8,7 +8,8 @@
 </p>
 <% end %>

-<% if @issue.safe_attribute?('project_id') && (!@issue.new_record? || @project.nil? || @issue.copy?) %>
+<% if @issue.safe_attribute?('project_id') #&& (!@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},
                 :onchange => "updateIssueFrom('#{escape_javascript update_issue_form_path(@project, @issue)}', this)" %></p>
 <% end %>

#16 Updated by Manuel Morales over 1 year ago

Thank you Gret T,

But I made the change, and even is not working.

Could you send me, your apps/models/issue.rb changes? My version is Redmine 3.2.3.stable

I appreciate your help.

#17 Updated by Manuel Morales over 1 year ago

Greg T wrote:

Manuel Morales wrote:

Do you have the updated patch file ?

Do you mean this? (It works with redmine-3.3.1.)

[...]

#18 Updated by Manuel Morales over 1 year ago

Thank you Gret T,

But I made the change, and even is not working.

Could you send me, your apps/models/issue.rb changes? My version is Redmine 3.2.3.stable

I appreciate your help.

#19 Updated by Greg T over 1 year ago

Manuel Morales wrote:

Could you send me, your apps/models/issue.rb changes?

I didn't change that. I attach project-select.patch modifying issues_controller.rb.

#20 Updated by Manuel Morales over 1 year ago

Greg T wrote:

Manuel Morales wrote:

Could you send me, your apps/models/issue.rb changes?

I didn't change that. I attach project-select.patch modifying issues_controller.rb.

Thank Greg T for you answer,

I change the file and restart the Apache service, but when new issue are created, it don't show selection field for projects only when copying or edit issues.

Do you have any idea or suggestions?

#21 Updated by Greg T over 1 year ago

Manuel Morales wrote:

Do you have any idea or suggestions?

I'm afraid I don't. It works for me.

#22 Updated by Alessandro Zucchi over 1 year ago

+1

#23 Updated by Marius BALTEANU over 1 year ago

Attached is a patch that adds the project field on the new issue form when the current project has subprojects.

When you're on a project with subprojects, if you want to add an issue on a subproject from the parent project page, you need to do various actions. For example:
- select the subproject from the quick selector and then new issue
- go to overview tab, select the subproject and then new issue

Allowing to add an issue on a subproject directly from the parent project it'll be a great improvement from my point of view (we've many projects with subprojects as I described in #9909#note-9).

#24 Updated by Michael Weiss about 1 year ago

Hi, Marius. Your patch is exactly what I am looking for. Which Redmine Version do you use. I am using 3.2.1.stable. By using your patch I've got 2 FAILS:

patching file app/models/issue.rb
Hunk #1 succeeded at 1397 (offset -108 lines).
Hunk #2 succeeded at 1413 (offset -108 lines).
patching file app/models/project.rb
patching file app/views/issues/_form.html.erb
Hunk #1 FAILED at 9.
1 out of 1 hunk FAILED -- saving rejects to file app/views/issues/_form.html.erb.rej
patching file test/functional/issues_controller_test.rb
Hunk #1 succeeded at 1604 (offset -208 lines).
Hunk #2 succeeded at 1628 with fuzz 1 (offset -208 lines).
Hunk #3 succeeded at 1663 (offset -207 lines).
patching file test/unit/issue_test.rb
Hunk #1 FAILED at 354.
1 out of 1 hunk FAILED -- saving rejects to file test/unit/issue_test.rb.rej

#25 Updated by Michael Weiss about 1 year ago

+1

#26 Updated by Marius BALTEANU about 1 year ago

Michael Weiss wrote:

Hi, Marius. Your patch is exactly what I am looking for. Which Redmine Version do you use. I am using 3.2.1.stable. By using your patch I've got 2 FAILS:

Hi Michael,

The patch was made against current Redmine trunk and it wasn't tested on 3.2.1 or latest 3.3.3. Hopefully, the patch will be taken into consideration for a future Redmine version.

#27 Updated by Mischa The Evil about 1 year ago

  • Target version set to Unplanned

I like the change proposed by Marius BALTEANU in note-23. Setting target version to 'Unplanned'.

#28 Updated by Marius BALTEANU 12 months ago

Mischa The Evil wrote:

I like the change proposed by Marius BALTEANU in note-23. Setting target version to 'Unplanned'.

Thanks for the feedback, Mischa. Looking forward to see this proposed for a future version.

#29 Updated by Go MAEDA 12 months ago

Here are screenshots of Marius BALTEANU's patch (12704_allow_selecting_subprojects_on_new_issue_page.patch).

before:

after:

#30 Updated by Marius BALTEANU 11 months ago

  • Duplicated by Feature #26639: Enabling creating issue within the project regarding the subproject added

#31 Updated by Simon Cruise 9 months ago

Is there any chance of this making it into the main? With microservices and multiple interacting systems it is only natural that one parent task is going to require changes in multiple other projects.

It is a clunky process to create the issue and then edit to change project each time as notifications are triggered etc...

#32 Updated by Marius BALTEANU 6 months ago

  • File 12704_allow_selecting_subprojects_on_new_issue_page_r17173.patch added

Updated the patch to cleanly apply on the current trunk.

Mischa, Go Maeda, the feature is quite requested and really improves the UX when working with subprojects (it saves at least 3 clicks). Can we propose the patch for the next major release (4.0.0 or 4.1.0)?

#33 Updated by Go MAEDA 6 months ago

I have tried out the patch and think there isn't any problem to include this feature in the upcoming release. Users will be able to create a subproject's issue when they see the parent project's issues list. I can easily imagine the use case and usefulness of the feature.

The only thing I was worried is that adding a new UI element, the "Project" drop-down, increases the complexity of the new issue form. But I found that it was needless anxiety because the drop-down is displayed only when the project has one or more subprojects.

#34 Updated by Go MAEDA 6 months ago

  • Target version changed from Unplanned to 4.1.0

LGTM, setting target version to 4.1.0.

#35 Updated by Go MAEDA 5 months ago

  • Status changed from New to Needs feedback
  • Assignee set to Marius BALTEANU

Marius, I had to change your code slightly in order to run test/functional/issues_controller_test.rb. Could you review the change?

I got stuck with the following error while running the test.

Error:
IssuesControllerTest#test_get_new_should_not_show_project_selector_for_project_without_subprojects:
ArgumentError: unknown keywords: project_id, tracker_id
    test/functional/issues_controller_test.rb:2347:in `test_get_new_should_not_show_project_selector_for_project_without_subprojects'

To fix the error, I updated the code as follow:

--- test/functional/issues_controller_test.rb.orig    2018-02-26 04:56:07.000000000 +0000
+++ test/functional/issues_controller_test.rb    2018-02-26 04:59:07.000000000 +0000
@@ -2328,7 +2328,10 @@

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

     assert_select 'select[name="issue[project_id]"]' do
@@ -2344,7 +2347,10 @@

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

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

#36 Updated by Marius BALTEANU 5 months ago

  • File deleted (12704_allow_selecting_subprojects_on_new_issue_page_r17173.patch)

#37 Updated by Marius BALTEANU 5 months ago

Indeed, I missed the tests updates for Rails 5.1 in my previous patch.

I'm attaching now the updated patch which include that updates and one more improvement: replaced the projects.count with projects.length in order to avoid an unnecessary query to db.

@Go Maeda, on my environment, all the tests from issues_controller_test.rb pass with this patch:

notroot@42f1f3063342:/work$ ruby test/functional/issues_controller_test.rb 
Run options: --seed 49241

# Running:

...............................    ........................................................................................................................................................................................................................................................................................................................................................

Finished in 88.663171s, 4.2295 runs/s, 18.8692 assertions/s.
375 runs, 1673 assertions, 0 failures, 0 errors, 0 skips

#38 Updated by Marius BALTEANU 5 months ago

  • Status changed from Needs feedback to New
  • Assignee deleted (Marius BALTEANU)

#39 Updated by Go MAEDA 5 months ago

  • Status changed from New to Closed
  • Assignee set to Go MAEDA
  • Target version changed from 4.1.0 to 4.0.0
  • Resolution set to Fixed

Committed.
Thank you for writing the patch.

#40 Updated by Go MAEDA 5 months ago

  • Subject changed from Project Select on new issue to Allow selecting subprojects on new issue form

#41 Updated by Sebastian Paluch 5 months ago

This is long waited feature, thanks for implementing it.

The only issue it seems to have is that the select list will not preserve project hierarchy by not showing intermittent projects that do not have trackers enabled (or user has no access to). As a result we get flattered list of projects. This is an issue when we have deep hierarchy with "container" projects in between and sub-project names are not unique, on its own not allowing to clearly identify the project.

It would be good if all projects are shown but select items for those where issue cannot be added are disabled and grayed out.

Similar issue exists in project jump box (#8904).

#42 Updated by Go MAEDA about 1 month ago

  • Related to Feature #17286: change project while creating a ticket added

Also available in: Atom PDF