diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-03-16 18:18:33 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-03-16 18:18:33 +0000 |
commit | f64a639bcfa1fc2bc89ca7db268f594306edfd7c (patch) | |
tree | a2c3c2ebcc3b45e596949db485d6ed18ffaacfa1 /app/controllers/projects/compare_controller.rb | |
parent | bfbc3e0d6583ea1a91f627528bedc3d65ba4b10f (diff) | |
download | gitlab-ce-f64a639bcfa1fc2bc89ca7db268f594306edfd7c.tar.gz |
Add latest changes from gitlab-org/gitlab@13-10-stable-eev13.10.0-rc40
Diffstat (limited to 'app/controllers/projects/compare_controller.rb')
-rw-r--r-- | app/controllers/projects/compare_controller.rb | 56 |
1 files changed, 42 insertions, 14 deletions
diff --git a/app/controllers/projects/compare_controller.rb b/app/controllers/projects/compare_controller.rb index 6be0b465402..81f80d37662 100644 --- a/app/controllers/projects/compare_controller.rb +++ b/app/controllers/projects/compare_controller.rb @@ -6,6 +6,7 @@ class Projects::CompareController < Projects::ApplicationController include DiffForPath include DiffHelper include RendersCommits + include CompareHelper # Authorize before_action :require_non_empty_project @@ -19,6 +20,10 @@ class Projects::CompareController < Projects::ApplicationController # Validation before_action :validate_refs! + before_action do + push_frontend_feature_flag(:compare_repo_dropdown, source_project, default_enabled: :yaml) + end + feature_category :source_code_management def index @@ -37,16 +42,18 @@ class Projects::CompareController < Projects::ApplicationController end def create - if params[:from].blank? || params[:to].blank? + from_to_vars = { + from: params[:from].presence, + to: params[:to].presence, + from_project_id: params[:from_project_id].presence + } + + if from_to_vars[:from].blank? || from_to_vars[:to].blank? flash[:alert] = "You must select a Source and a Target revision" - from_to_vars = { - from: params[:from].presence, - to: params[:to].presence - } - redirect_to project_compare_index_path(@project, from_to_vars) + + redirect_to project_compare_index_path(source_project, from_to_vars) else - redirect_to project_compare_path(@project, - params[:from], params[:to]) + redirect_to project_compare_path(source_project, from_to_vars) end end @@ -73,13 +80,34 @@ class Projects::CompareController < Projects::ApplicationController return if valid.all? flash[:alert] = "Invalid branch name" - redirect_to project_compare_index_path(@project) + redirect_to project_compare_index_path(source_project) + end + + # target == start_ref == from + def target_project + strong_memoize(:target_project) do + next source_project unless params.key?(:from_project_id) + next source_project unless Feature.enabled?(:compare_repo_dropdown, source_project, default_enabled: :yaml) + next source_project if params[:from_project_id].to_i == source_project.id + + target_project = target_projects(source_project).find_by_id(params[:from_project_id]) + + # Just ignore the field if it points at a non-existent or hidden project + next source_project unless target_project && can?(current_user, :download_code, target_project) + + target_project + end + end + + # source == head_ref == to + def source_project + project end def compare return @compare if defined?(@compare) - @compare = CompareService.new(@project, head_ref).execute(@project, start_ref) + @compare = CompareService.new(source_project, head_ref).execute(target_project, start_ref) end def start_ref @@ -102,9 +130,9 @@ class Projects::CompareController < Projects::ApplicationController def define_environment if compare - environment_params = @repository.branch_exists?(head_ref) ? { ref: head_ref } : { commit: compare.commit } + environment_params = source_project.repository.branch_exists?(head_ref) ? { ref: head_ref } : { commit: compare.commit } environment_params[:find_latest] = true - @environment = EnvironmentsFinder.new(@project, current_user, environment_params).execute.last + @environment = EnvironmentsFinder.new(source_project, current_user, environment_params).execute.last end end @@ -114,8 +142,8 @@ class Projects::CompareController < Projects::ApplicationController # rubocop: disable CodeReuse/ActiveRecord def merge_request - @merge_request ||= MergeRequestsFinder.new(current_user, project_id: @project.id).execute.opened - .find_by(source_project: @project, source_branch: head_ref, target_branch: start_ref) + @merge_request ||= MergeRequestsFinder.new(current_user, project_id: target_project.id).execute.opened + .find_by(source_project: source_project, source_branch: head_ref, target_branch: start_ref) end # rubocop: enable CodeReuse/ActiveRecord end |