From 0ea3fcec397b69815975647f5e2aa5fe944a8486 Mon Sep 17 00:00:00 2001 From: GitLab Bot Date: Mon, 20 Jun 2022 11:10:13 +0000 Subject: Add latest changes from gitlab-org/gitlab@15-1-stable-ee --- app/serializers/deploy_keys/deploy_key_entity.rb | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 app/serializers/deploy_keys/deploy_key_entity.rb (limited to 'app/serializers/deploy_keys/deploy_key_entity.rb') diff --git a/app/serializers/deploy_keys/deploy_key_entity.rb b/app/serializers/deploy_keys/deploy_key_entity.rb new file mode 100644 index 00000000000..79f386d1529 --- /dev/null +++ b/app/serializers/deploy_keys/deploy_key_entity.rb @@ -0,0 +1,22 @@ +# frozen_string_literal: true + +module DeployKeys + class DeployKeyEntity < BasicDeployKeyEntity + expose :deploy_keys_projects, using: DeployKeysProjectEntity do |deploy_key| + deploy_key.deploy_keys_projects.select do |deploy_key_project| + !deploy_key_project.project&.pending_delete? && + (allowed_to_read_project?(deploy_key_project.project) || options[:user].can_admin_all_resources?) + end + end + + private + + def allowed_to_read_project?(project) + if options[:readable_project_ids] + options[:readable_project_ids].include?(project.id) + else + Ability.allowed?(options[:user], :read_project, project) + end + end + end +end -- cgit v1.2.1