summaryrefslogtreecommitdiff
path: root/app/graphql/mutations/groups/update.rb
blob: 9c5628a57cd848001ca838c172ce45de42bd593e (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
# frozen_string_literal: true

module Mutations
  module Groups
    class Update < Mutations::BaseMutation
      include Mutations::ResolvesGroup

      graphql_name 'GroupUpdate'

      authorize :admin_group

      field :group, Types::GroupType,
            null: true,
            description: 'Group after update.'

      argument :full_path, GraphQL::Types::ID,
               required: true,
               description: 'Full path of the group that will be updated.'
      argument :shared_runners_setting, Types::Namespace::SharedRunnersSettingEnum,
               required: true,
               description: copy_field_description(Types::GroupType, :shared_runners_setting)

      def resolve(full_path:, **args)
        group = authorized_find!(full_path: full_path)

        unless ::Groups::UpdateService.new(group, current_user, args).execute
          return { group: nil, errors: group.errors.full_messages }
        end

        { group: group, errors: [] }
      end

      private

      def find_object(full_path:)
        resolve_group(full_path: full_path)
      end
    end
  end
end