Class: Ci::JobToken::ExportAuthorizationsService

Inherits:
Object
  • Object
show all
Includes:
Gitlab::Allowable
Defined in:
app/services/ci/job_token/export_authorizations_service.rb

Instance Method Summary collapse

Methods included from Gitlab::Allowable

#can?, #can_all?, #can_any?

Constructor Details

#initialize(current_user:, accessed_project:) ⇒ ExportAuthorizationsService

Returns a new instance of ExportAuthorizationsService.



9
10
11
12
# File 'app/services/ci/job_token/export_authorizations_service.rb', line 9

def initialize(current_user:, accessed_project:)
  @current_user = current_user
  @accessed_project = accessed_project
end

Instance Method Details

#executeObject



14
15
16
17
18
19
20
21
22
# File 'app/services/ci/job_token/export_authorizations_service.rb', line 14

def execute
  unless can?(current_user, :admin_project, accessed_project)
    return ServiceResponse.error(message: _('Access denied'), reason: :forbidden)
  end

  csv_data = CsvBuilder.new(authorizations, header_to_value_hash).render

  ServiceResponse.success(payload: { data: csv_data, filename: csv_filename })
end