diff options
author | Go MAEDA <maeda@farend.jp> | 2020-12-25 02:25:41 +0000 |
---|---|---|
committer | Go MAEDA <maeda@farend.jp> | 2020-12-25 02:25:41 +0000 |
commit | 30e80d82ce189b4232e143b054f78870afd076da (patch) | |
tree | 5fe7e869f72af34cf6af07e1e0e1d5cadbdbdd99 /app/controllers | |
parent | d11f8edc2d87ae1c0db8cbdfb0dd101d9cb5c645 (diff) | |
download | redmine-30e80d82ce189b4232e143b054f78870afd076da.tar.gz redmine-30e80d82ce189b4232e143b054f78870afd076da.zip |
Bulk addition of related issues (#33418).
Patch by Dmitry Makurin and Marius BALTEANU.
git-svn-id: http://svn.redmine.org/redmine/trunk@20689 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'app/controllers')
-rw-r--r-- | app/controllers/issue_relations_controller.rb | 33 |
1 files changed, 24 insertions, 9 deletions
diff --git a/app/controllers/issue_relations_controller.rb b/app/controllers/issue_relations_controller.rb index 1cceba576..14ee4c948 100644 --- a/app/controllers/issue_relations_controller.rb +++ b/app/controllers/issue_relations_controller.rb @@ -44,22 +44,29 @@ class IssueRelationsController < ApplicationController end def create - @relation = IssueRelation.new - @relation.issue_from = @issue - @relation.safe_attributes = params[:relation] - @relation.init_journals(User.current) + saved = false + params_relation = params[:relation] + unsaved_relations = [] + + relation_issues_to_id.each do |issue_to_id| + params_relation[:issue_to_id] = issue_to_id + + @relation = IssueRelation.new + @relation.issue_from = @issue + @relation.safe_attributes = params_relation + @relation.init_journals(User.current) - begin - saved = @relation.save - rescue ActiveRecord::RecordNotUnique - saved = false - @relation.errors.add :base, :taken + unless saved = @relation.save + saved = false + unsaved_relations << @relation + end end respond_to do |format| format.html {redirect_to issue_path(@issue)} format.js do @relations = @issue.reload.relations.select {|r| r.other_issue(@issue) && r.other_issue(@issue).visible?} + @unsaved_relations = unsaved_relations end format.api do if saved @@ -98,4 +105,12 @@ class IssueRelationsController < ApplicationController rescue ActiveRecord::RecordNotFound render_404 end + + def relation_issues_to_id + params[:relation].require(:issue_to_id).split(',').reject(&:blank?) + rescue ActionController::ParameterMissing => e + # We return a empty array just to loop once and return a validation error + # ToDo: Find a better method to return an error if the param is missing. + [''] + end end |