diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-03-23 15:09:33 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-03-23 15:09:33 +0300 |
commit | b38fc20ae0e90d5b1c538a139aa0a7da1b7b5726 (patch) | |
tree | 3ce77cdb707b75c9d74c6ff2a8386dd06bd48b44 /app/presenters | |
parent | b3647b2a67930e8aa3c1b1dd9bda29c368c862ba (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app/presenters')
-rw-r--r-- | app/presenters/projects/settings/deploy_keys_presenter.rb | 69 |
1 files changed, 54 insertions, 15 deletions
diff --git a/app/presenters/projects/settings/deploy_keys_presenter.rb b/app/presenters/projects/settings/deploy_keys_presenter.rb index 103c26289bf..aec008f1e40 100644 --- a/app/presenters/projects/settings/deploy_keys_presenter.rb +++ b/app/presenters/projects/settings/deploy_keys_presenter.rb @@ -14,12 +14,20 @@ module Projects @key ||= DeployKey.new.tap { |dk| dk.deploy_keys_projects.build } end + # It includes: + # - The deploy keys enabled in the project. def enabled_keys strong_memoize(:enabled_keys) do project.deploy_keys.with_projects end end + # NOTE: This method is redundant. Use `available_project_keys` and `available_public_keys` instead. + # It includes: + # - Enabled deploy keys in projects that can be accessed by the user. + # - Instance-level public deploy keys. + # It excludes: + # - The deploy keys enabled in the project. def available_keys strong_memoize(:available_keys) do current_user @@ -29,22 +37,46 @@ module Projects end end + # It includes: + # - Enabled deploy keys in projects that can be accessed by the user. + # It excludes: + # - The deploy keys enabled in the project def available_project_keys - strong_memoize(:available_project_keys) do - current_user - .project_deploy_keys - .id_not_in(enabled_keys.select(:id)) - .with_projects + if Feature.enabled?(:optimize_deploy_keys_presenter, project, default_enabled: :yaml) + strong_memoize(:available_project_keys) do + current_user.project_deploy_keys.with_projects - enabled_keys + end + else + strong_memoize(:legacy_available_project_keys) do + current_user + .project_deploy_keys + .id_not_in(enabled_keys.select(:id)) + .with_projects + end end end + # It includes: + # - Instance-level public deploy keys. + # It excludes: + # - The deploy keys enabled in the project. def available_public_keys - strong_memoize(:available_public_keys) do - DeployKey - .are_public - .id_not_in(enabled_keys.select(:id)) - .id_not_in(available_project_keys.select(:id)) - .with_projects + if Feature.enabled?(:optimize_deploy_keys_presenter, project, default_enabled: :yaml) + strong_memoize(:available_public_keys) do + DeployKey.are_public.with_projects - enabled_keys + end + else + strong_memoize(:legacy_available_public_keys) do + # This also excludes "Enabled deploy keys in projects that can be accessed by the user". + # However, this means we are filtering out a public key that enabled + # in the other project, which should be also available for this project. + # We should expose the public keys that has not been enabled on the project yet. + DeployKey + .are_public + .id_not_in(enabled_keys.select(:id)) + .id_not_in(available_project_keys.select(:id)) + .with_projects + end end end @@ -78,10 +110,17 @@ module Projects # rubocop: disable CodeReuse/ActiveRecord def user_readable_project_ids - project_ids = (available_keys + available_project_keys + available_public_keys) - .flat_map { |deploy_key| deploy_key.deploy_keys_projects.map(&:project_id) } - .compact - .uniq + project_ids = if Feature.enabled?(:optimize_deploy_keys_presenter, project, default_enabled: :yaml) + (available_project_keys + available_public_keys) + .flat_map { |deploy_key| deploy_key.deploy_keys_projects.map(&:project_id) } + .compact + .uniq + else + (available_keys + available_project_keys + available_public_keys) + .flat_map { |deploy_key| deploy_key.deploy_keys_projects.map(&:project_id) } + .compact + .uniq + end current_user.authorized_projects(Gitlab::Access::GUEST).id_in(project_ids).pluck(:id) end |