diff options
author | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2016-12-10 12:02:37 +0000 |
---|---|---|
committer | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2016-12-10 12:02:37 +0000 |
commit | 3a2b6c7c9653ddbd32ea0c2434b0c9b638832b3e (patch) | |
tree | d26c2e0017af9ba1ce3a8767c9dc2f2584a0f776 /app | |
parent | 575f4032a221c8fc7919c2997c13e1424da8006e (diff) | |
download | redmine-3a2b6c7c9653ddbd32ea0c2434b0c9b638832b3e.tar.gz redmine-3a2b6c7c9653ddbd32ea0c2434b0c9b638832b3e.zip |
Enforce issue assignee validation (#23921).
git-svn-id: http://svn.redmine.org/redmine/trunk@16055 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'app')
-rw-r--r-- | app/models/issue.rb | 24 | ||||
-rw-r--r-- | app/models/project.rb | 2 |
2 files changed, 16 insertions, 10 deletions
diff --git a/app/models/issue.rb b/app/models/issue.rb index f1bbe1c78..e49890e1a 100644 --- a/app/models/issue.rb +++ b/app/models/issue.rb @@ -377,6 +377,11 @@ class Issue < ActiveRecord::Base if category self.category = project.issue_categories.find_by_name(category.name) end + # Clear the assignee if not available in the new project for new issues (eg. copy) + # For existing issue, the previous assignee is still valid, so we keep it + if new_record? && assigned_to && !assignable_users.include?(assigned_to) + self.assigned_to_id = nil + end # Keep the fixed_version if it's still valid in the new_project if fixed_version && fixed_version.project != project && !project.shared_versions.include?(fixed_version) self.fixed_version = nil @@ -538,14 +543,7 @@ class Issue < ActiveRecord::Base self.status = statuses_allowed.first || default_status end if (u = attrs.delete('assigned_to_id')) && safe_attribute?('assigned_to_id') - if u.blank? - self.assigned_to_id = nil - else - u = u.to_i - if assignable_users.any?{|assignable_user| assignable_user.id == u} - self.assigned_to_id = u - end - end + self.assigned_to_id = u end @@ -708,6 +706,12 @@ class Issue < ActiveRecord::Base end end + if assigned_to_id_changed? && assigned_to_id.present? + unless assignable_users.include?(assigned_to) + errors.add :assigned_to_id, :invalid + end + end + # Checks parent issue assignment if @invalid_parent_issue_id.present? errors.add :parent_issue_id, :invalid @@ -868,7 +872,9 @@ class Issue < ActiveRecord::Base def assignable_users users = project.assignable_users(tracker).to_a users << author if author && author.active? - users << assigned_to if assigned_to + if assigned_to_id_was.present? && assignee = Principal.find_by_id(assigned_to_id_was) + users << assignee + end users.uniq.sort end diff --git a/app/models/project.rb b/app/models/project.rb index eecc3851e..2f258f3f9 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -780,7 +780,7 @@ class Project < ActiveRecord::Base def copy(project, options={}) project = project.is_a?(Project) ? project : Project.find(project) - to_be_copied = %w(wiki versions issue_categories issues members queries boards) + to_be_copied = %w(members wiki versions issue_categories issues queries boards) to_be_copied = to_be_copied & Array.wrap(options[:only]) unless options[:only].nil? Project.transaction do |