summaryrefslogtreecommitdiff
path: root/lib/bulk_imports/groups/pipelines/milestones_pipeline.rb
blob: 8497162e0e73c7bf7db003e54d8919c6a03031ac (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
35
36
37
38
39
40
41
42
# frozen_string_literal: true

module BulkImports
  module Groups
    module Pipelines
      class MilestonesPipeline
        include Pipeline

        extractor BulkImports::Common::Extractors::GraphqlExtractor,
          query: BulkImports::Groups::Graphql::GetMilestonesQuery

        transformer Common::Transformers::ProhibitedAttributesTransformer

        def load(context, data)
          return unless data

          raise ::BulkImports::Pipeline::NotAllowedError unless authorized?

          context.group.milestones.create!(data)
        end

        def after_run(extracted_data)
          context.entity.update_tracker_for(
            relation: :milestones,
            has_next_page: extracted_data.has_next_page?,
            next_page: extracted_data.next_page
          )

          if extracted_data.has_next_page?
            run
          end
        end

        private

        def authorized?
          context.current_user.can?(:admin_milestone, context.group)
        end
      end
    end
  end
end