Project

General

Profile

Defect #23963 » bundle-update-set-project.patch

Olivier Houdas, 2016-09-30 15:14

View differences:

app/controllers/application_controller.rb Thu Sep 22 14:31:27 2016 +0200 → app/controllers/application_controller.rb Fri Sep 30 15:14:27 2016 +0200
render_404
end
# Find the first common parent of two projects
def find_common_parent(project1, project2)
return nil if project1.nil? || project2.nil?
return project1 if project1.id == project2.id
p1_ancestors = [project1.id]
while !project1.parent_id.nil?
p1_ancestors << project1.parent_id
project1 = Project.find(project1.parent_id)
end
while !project2.parent_id.nil? && !p1_ancestors.include?(project2.parent_id)
project2 = Project.find(project2.parent_id)
end
project2.parent_id.nil? ? nil : Project.find(project2.parent_id)
end
# Finds and sets @project based on @object.project
def find_project_from_association
render_404 unless @object.present?
......
raise ActiveRecord::RecordNotFound if @issues.empty?
raise Unauthorized unless @issues.all?(&:visible?)
@projects = @issues.collect(&:project).compact.uniq
@project = @projects.first if @projects.size == 1
# Get the highest common parent project in the project tree
common_parent = @projects.first
Project.project_tree(@projects) do |project, level|
if level == 0
common_parent = find_common_parent(common_parent, project)
end
end
@project = common_parent
rescue ActiveRecord::RecordNotFound
render_404
end
    (1-1/1)