Welcome to mirror list, hosted at ThFree Co, Russian Federation.

collect_keys_service.rb « deploy_keys « services « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 2ef49bf0f30a591517b55d4105f845472eff45f8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# frozen_string_literal: true

module DeployKeys
  class CollectKeysService
    def initialize(project, current_user)
      @project = project
      @current_user = current_user
    end

    def execute
      return [] unless current_user && project && user_can_read_project

      project.deploy_keys_projects
        .with_deploy_keys
        .with_write_access
        .map(&:deploy_key)
    end

    private

    def user_can_read_project
      Ability.allowed?(current_user, :read_project, project)
    end

    attr_reader :project, :current_user
  end
end