File: delete.rb

package info (click to toggle)
gitlab 17.6.5-19
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 629,368 kB
  • sloc: ruby: 1,915,304; javascript: 557,307; sql: 60,639; xml: 6,509; sh: 4,567; makefile: 1,239; python: 406
file content (68 lines) | stat: -rw-r--r-- 1,976 bytes parent folder | download
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# frozen_string_literal: true

module Mutations
  module Integrations
    module Exclusions
      class Delete < BaseMutation
        graphql_name 'IntegrationExclusionDelete'
        include ResolvesIds

        field :exclusions, [::Types::Integrations::ExclusionType],
          null: true,
          description: 'Project no longer excluded due to the mutation.'

        argument :integration_name,
          ::Types::Integrations::IntegrationTypeEnum,
          required: true,
          description: 'Type of integration.'

        argument :project_ids,
          [::Types::GlobalIDType[::Project]],
          required: false,
          description: 'IDs of excluded projects.'

        argument :group_ids,
          [::Types::GlobalIDType[::Group]],
          required: false,
          description: 'IDs of excluded groups.'

        authorize :admin_all_resources

        def resolve(integration_name:, project_ids: [], group_ids: [])
          authorize!(:global)

          result = ::Integrations::Exclusions::DestroyService.new(
            current_user: current_user,
            projects: projects(project_ids),
            groups: groups(group_ids),
            integration_name: integration_name
          ).execute

          exclusions = result.payload

          # Integrations::Exclusions::DestroyService calls destroy_all in some circumstances which returns a frozen
          # array.  We call dup here to allow entries to be redacted by field extensions.
          exclusions = exclusions.dup if exclusions.frozen?
          {
            exclusions: exclusions,
            errors: result.errors
          }
        end

        private

        def projects(project_ids)
          return [] unless project_ids.present?

          Project.id_in(resolve_ids(project_ids))
        end

        def groups(group_ids)
          return [] unless group_ids.present?

          Group.id_in(resolve_ids(group_ids))
        end
      end
    end
  end
end