Commit dd3c0c6d authored by Pedro Pombeiro's avatar Pedro Pombeiro

Convert mutation to GroupUpdate mutation

parent 0fb493ee
......@@ -2,12 +2,16 @@
module Mutations
module Groups
class UpdateSharedRunnersSetting < Mutations::BaseMutation
class Update < Mutations::BaseMutation
include Mutations::ResolvesGroup
graphql_name 'GroupSharedRunnersSettingUpdate'
graphql_name 'GroupUpdate'
authorize :update_group_shared_runners_setting
authorize :admin_group
field :group, Types::GroupType,
null: true,
description: 'The group after update.'
argument :full_path, GraphQL::Types::ID,
required: true,
......@@ -19,13 +23,11 @@ module Mutations
def resolve(full_path:, **args)
group = authorized_find!(full_path: full_path)
result = ::Groups::UpdateSharedRunnersService
.new(group, current_user, args)
.execute
unless ::Groups::UpdateService.new(group, current_user, args).execute
return { group: nil, errors: group.errors.full_messages }
end
{
errors: result[:status] == :success ? [] : Array.wrap(result[:message])
}
{ group: group, errors: [] }
end
private
......
......@@ -105,7 +105,7 @@ module Types
mount_mutation Mutations::Ci::Runner::Delete, feature_flag: :runner_graphql_query
mount_mutation Mutations::Ci::RunnersRegistrationToken::Reset, feature_flag: :runner_graphql_query
mount_mutation Mutations::Namespace::PackageSettings::Update
mount_mutation Mutations::Groups::UpdateSharedRunnersSetting
mount_mutation Mutations::Groups::Update
mount_mutation Mutations::UserCallouts::Create
mount_mutation Mutations::Packages::Destroy
mount_mutation Mutations::Packages::DestroyFile
......
......@@ -226,10 +226,6 @@ class GroupPolicy < BasePolicy
rule { developer & dependency_proxy_available }
.enable :admin_dependency_proxy
rule { can?(:admin_group) }.policy do
enable :update_group_shared_runners_setting
end
rule { can?(:admin_group) & resource_access_token_feature_available }.policy do
enable :read_resource_access_tokens
enable :destroy_resource_access_tokens
......
......@@ -2360,24 +2360,25 @@ Input type: `GitlabSubscriptionActivateInput`
| <a id="mutationgitlabsubscriptionactivateerrors"></a>`errors` | [`[String!]!`](#string) | Errors encountered during execution of the mutation. |
| <a id="mutationgitlabsubscriptionactivatelicense"></a>`license` | [`CurrentLicense`](#currentlicense) | The current license. |
### `Mutation.groupSharedRunnersSettingUpdate`
### `Mutation.groupUpdate`
Input type: `GroupSharedRunnersSettingUpdateInput`
Input type: `GroupUpdateInput`
#### Arguments
| Name | Type | Description |
| ---- | ---- | ----------- |
| <a id="mutationgroupsharedrunnerssettingupdateclientmutationid"></a>`clientMutationId` | [`String`](#string) | A unique identifier for the client performing the mutation. |
| <a id="mutationgroupsharedrunnerssettingupdatefullpath"></a>`fullPath` | [`ID!`](#id) | Full path of the group that will be updated. |
| <a id="mutationgroupsharedrunnerssettingupdatesharedrunnerssetting"></a>`sharedRunnersSetting` | [`SharedRunnersSetting!`](#sharedrunnerssetting) | Shared runners availability for the namespace and its descendants. |
| <a id="mutationgroupupdateclientmutationid"></a>`clientMutationId` | [`String`](#string) | A unique identifier for the client performing the mutation. |
| <a id="mutationgroupupdatefullpath"></a>`fullPath` | [`ID!`](#id) | Full path of the group that will be updated. |
| <a id="mutationgroupupdatesharedrunnerssetting"></a>`sharedRunnersSetting` | [`SharedRunnersSetting!`](#sharedrunnerssetting) | Shared runners availability for the namespace and its descendants. |
#### Fields
| Name | Type | Description |
| ---- | ---- | ----------- |
| <a id="mutationgroupsharedrunnerssettingupdateclientmutationid"></a>`clientMutationId` | [`String`](#string) | A unique identifier for the client performing the mutation. |
| <a id="mutationgroupsharedrunnerssettingupdateerrors"></a>`errors` | [`[String!]!`](#string) | Errors encountered during execution of the mutation. |
| <a id="mutationgroupupdateclientmutationid"></a>`clientMutationId` | [`String`](#string) | A unique identifier for the client performing the mutation. |
| <a id="mutationgroupupdateerrors"></a>`errors` | [`[String!]!`](#string) | Errors encountered during execution of the mutation. |
| <a id="mutationgroupupdategroup"></a>`group` | [`Group`](#group) | The group after update. |
### `Mutation.httpIntegrationCreate`
......
......@@ -2,7 +2,7 @@
require 'spec_helper'
RSpec.describe Mutations::Groups::UpdateSharedRunnersSetting do
RSpec.describe Mutations::Groups::Update do
using RSpec::Parameterized::TableSyntax
let_it_be_with_reload(:group) { create(:group) }
......@@ -10,7 +10,7 @@ RSpec.describe Mutations::Groups::UpdateSharedRunnersSetting do
let(:params) { { full_path: group.full_path } }
specify { expect(described_class).to require_graphql_authorizations(:update_group_shared_runners_setting) }
specify { expect(described_class).to require_graphql_authorizations(:admin_group) }
describe '#resolve' do
subject { described_class.new(object: group, context: { current_user: user }, field: nil).resolve(**params) }
......@@ -22,7 +22,7 @@ RSpec.describe Mutations::Groups::UpdateSharedRunnersSetting do
end
it 'returns no errors' do
expect(subject).to eq(errors: [])
expect(subject).to eq(errors: [], group: group)
end
context 'with invalid params' do
......@@ -35,7 +35,8 @@ RSpec.describe Mutations::Groups::UpdateSharedRunnersSetting do
it 'returns an error' do
expect(subject).to eq(
errors: ["state must be one of: #{::Namespace::SHARED_RUNNERS_SETTINGS.join(', ')}"]
group: nil,
errors: ["Update shared runners state must be one of: #{::Namespace::SHARED_RUNNERS_SETTINGS.join(', ')}"]
)
end
end
......@@ -47,7 +48,7 @@ RSpec.describe Mutations::Groups::UpdateSharedRunnersSetting do
end
end
context 'with existing group shared runners setting' do
context 'changing shared runners setting' do
let_it_be(:params) do
{ full_path: group.full_path,
shared_runners_setting: 'disabled_and_unoverridable' }
......
......@@ -2,7 +2,7 @@
require 'spec_helper'
RSpec.describe 'GroupSharedRunnersSettingUpdate' do
RSpec.describe 'GroupUpdate' do
include GraphqlHelpers
let_it_be(:user) { create(:user) }
......@@ -15,7 +15,7 @@ RSpec.describe 'GroupSharedRunnersSettingUpdate' do
}
end
let(:mutation) { graphql_mutation(:group_shared_runners_setting_update, variables) }
let(:mutation) { graphql_mutation(:group_update, variables) }
context 'when unauthorized' do
shared_examples 'unauthorized' do
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment