Defect #23963 » bundle-update-set-project.patch
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 | ||
---|---|---|
294 | 294 |
render_404 |
295 | 295 |
end |
296 | 296 | |
297 |
# Find the first common parent of two projects |
|
298 |
def find_common_parent(project1, project2) |
|
299 |
return nil if project1.nil? || project2.nil? |
|
300 |
return project1 if project1.id == project2.id |
|
301 |
p1_ancestors = [project1.id] |
|
302 |
while !project1.parent_id.nil? |
|
303 |
p1_ancestors << project1.parent_id |
|
304 |
project1 = Project.find(project1.parent_id) |
|
305 |
end |
|
306 |
while !project2.parent_id.nil? && !p1_ancestors.include?(project2.parent_id) |
|
307 |
project2 = Project.find(project2.parent_id) |
|
308 |
end |
|
309 |
project2.parent_id.nil? ? nil : Project.find(project2.parent_id) |
|
310 |
end |
|
311 | ||
297 | 312 |
# Finds and sets @project based on @object.project |
298 | 313 |
def find_project_from_association |
299 | 314 |
render_404 unless @object.present? |
... | ... | |
337 | 352 |
raise ActiveRecord::RecordNotFound if @issues.empty? |
338 | 353 |
raise Unauthorized unless @issues.all?(&:visible?) |
339 | 354 |
@projects = @issues.collect(&:project).compact.uniq |
340 |
@project = @projects.first if @projects.size == 1 |
|
355 |
# Get the highest common parent project in the project tree |
|
356 |
common_parent = @projects.first |
|
357 |
Project.project_tree(@projects) do |project, level| |
|
358 |
if level == 0 |
|
359 |
common_parent = find_common_parent(common_parent, project) |
|
360 |
end |
|
361 |
end |
|
362 |
@project = common_parent |
|
341 | 363 |
rescue ActiveRecord::RecordNotFound |
342 | 364 |
render_404 |
343 | 365 |
end |