diff options
Diffstat (limited to 'app/services/deploy_keys/collect_keys_service.rb')
-rw-r--r-- | app/services/deploy_keys/collect_keys_service.rb | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/app/services/deploy_keys/collect_keys_service.rb b/app/services/deploy_keys/collect_keys_service.rb new file mode 100644 index 00000000000..2ef49bf0f30 --- /dev/null +++ b/app/services/deploy_keys/collect_keys_service.rb @@ -0,0 +1,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 |