summaryrefslogtreecommitdiffstats
path: root/app/models/issue.rb
diff options
context:
space:
mode:
authorGo MAEDA <maeda@farend.jp>2021-01-01 00:59:07 +0000
committerGo MAEDA <maeda@farend.jp>2021-01-01 00:59:07 +0000
commit3f3514d8b1a6c7db39c7b0e180598437a210fac0 (patch)
tree39b2f8498584ffa36ff07baff92a38e6bf5bdc35 /app/models/issue.rb
parent2ee2b349879a0816fc49700fade0be1750a6fa87 (diff)
downloadredmine-3f3514d8b1a6c7db39c7b0e180598437a210fac0.tar.gz
redmine-3f3514d8b1a6c7db39c7b0e180598437a210fac0.zip
Show only valid projects on issue form when the issue is a subtask (#33419).
Patch by Marius BALTEANU. git-svn-id: http://svn.redmine.org/redmine/trunk@20701 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'app/models/issue.rb')
-rw-r--r--app/models/issue.rb52
1 files changed, 39 insertions, 13 deletions
diff --git a/app/models/issue.rb b/app/models/issue.rb
index 8ba261bb1..2c6437311 100644
--- a/app/models/issue.rb
+++ b/app/models/issue.rb
@@ -1596,29 +1596,38 @@ class Issue < ActiveRecord::Base
end
end
+ # Returns a scope of projects that user can assign the subtask
+ def allowed_target_projects_for_subtask(user=User.current)
+ if parent_issue_id.present?
+ scope = filter_projects_scope(Setting.cross_project_subtasks)
+ end
+
+ self.class.allowed_target_projects(user, project, scope)
+ end
+
# Returns a scope of projects that user can assign the issue to
- def allowed_target_projects(user=User.current, context=nil)
- if new_record? && context.is_a?(Project) && !copy?
- current_project = context.self_and_descendants
- elsif new_record?
- current_project = nil
- else
- current_project = project
+ def allowed_target_projects(user=User.current, scope=nil)
+ current_project = new_record? ? nil : project
+ if scope
+ scope = filter_projects_scope(scope)
end
- self.class.allowed_target_projects(user, current_project)
+ self.class.allowed_target_projects(user, current_project, scope)
end
# Returns a scope of projects that user can assign issues to
# If current_project is given, it will be included in the scope
- def self.allowed_target_projects(user=User.current, current_project=nil)
+ def self.allowed_target_projects(user=User.current, current_project=nil, scope=nil)
condition = Project.allowed_to_condition(user, :add_issues)
- if current_project.is_a?(Project)
+ if current_project
condition = ["(#{condition}) OR #{Project.table_name}.id = ?", current_project.id]
- elsif current_project
- condition = ["(#{condition}) AND #{Project.table_name}.id IN (?)", current_project.map(&:id)]
end
- Project.where(condition).having_trackers
+
+ if scope.nil?
+ scope = Project
+ end
+
+ scope.where(condition).having_trackers
end
# Returns a scope of trackers that user can assign the issue to
@@ -1988,4 +1997,21 @@ class Issue < ActiveRecord::Base
self.done_ratio ||= 0
end
end
+
+ def filter_projects_scope(scope=nil)
+ case scope
+ when 'system'
+ Project
+ when 'tree'
+ project.root.self_and_descendants
+ when 'hierarchy'
+ project.hierarchy
+ when 'descendants'
+ project.self_and_descendants
+ when ''
+ Project.where(:id => project.id)
+ else
+ Project
+ end
+ end
end