summaryrefslogtreecommitdiff
path: root/app/services/work_items/export_csv_service.rb
blob: 9bef75e2c40091f37d4c6c71b94b3cf4feb8f3f4 (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
28
29
30
31
32
33
34
# frozen_string_literal: true

module WorkItems
  class ExportCsvService < ExportCsv::BaseService
    NotAvailableError = StandardError.new('This feature is currently behind a feature flag and it is not available.')

    def csv_data
      raise NotAvailableError unless Feature.enabled?(:import_export_work_items_csv, resource_parent)

      super
    end

    def email(mail_to_user)
      # TODO - will be implemented as part of https://gitlab.com/gitlab-org/gitlab/-/issues/379082
    end

    private

    def associations_to_preload
      [:work_item_type, :author]
    end

    def header_to_value_hash
      {
        'Id' => 'iid',
        'Title' => 'title',
        'Type' => ->(work_item) { work_item.work_item_type.name },
        'Author' => 'author_name',
        'Author Username' => ->(work_item) { work_item.author.username },
        'Created At (UTC)' => ->(work_item) { work_item.created_at.to_s(:csv) }
      }
    end
  end
end