Commit 368a2a7c authored by David Fernandez's avatar David Fernandez

Merge branch...

Merge branch '322841-move-dependency-proxy-enable-under-settings-packages-registries-3' into 'master'

Add mutation to change dependency proxy setting

See merge request gitlab-org/gitlab!71274
parents f5365ccd e2d7d722
# frozen_string_literal: true
module Mutations
module DependencyProxy
module GroupSettings
class Update < Mutations::BaseMutation
include Mutations::ResolvesGroup
graphql_name 'UpdateDependencyProxySettings'
authorize :admin_dependency_proxy
argument :group_path,
GraphQL::Types::ID,
required: true,
description: 'Group path for the group dependency proxy.'
argument :enabled,
GraphQL::Types::Boolean,
required: false,
description: copy_field_description(Types::DependencyProxy::ImageTtlGroupPolicyType, :enabled)
field :dependency_proxy_setting,
Types::DependencyProxy::GroupSettingType,
null: true,
description: 'Group dependency proxy settings after mutation.'
def resolve(group_path:, **args)
group = authorized_find!(group_path: group_path)
result = ::DependencyProxy::GroupSettings::UpdateService
.new(container: group, current_user: current_user, params: args)
.execute
{
dependency_proxy_setting: result.payload[:dependency_proxy_setting],
errors: result.errors
}
end
private
def find_object(group_path:)
resolve_group(full_path: group_path)
end
end
end
end
end
...@@ -42,6 +42,7 @@ module Types ...@@ -42,6 +42,7 @@ module Types
mount_mutation Mutations::CustomerRelations::Organizations::Update mount_mutation Mutations::CustomerRelations::Organizations::Update
mount_mutation Mutations::Discussions::ToggleResolve mount_mutation Mutations::Discussions::ToggleResolve
mount_mutation Mutations::DependencyProxy::ImageTtlGroupPolicy::Update mount_mutation Mutations::DependencyProxy::ImageTtlGroupPolicy::Update
mount_mutation Mutations::DependencyProxy::GroupSettings::Update
mount_mutation Mutations::Environments::CanaryIngress::Update mount_mutation Mutations::Environments::CanaryIngress::Update
mount_mutation Mutations::Issues::Create mount_mutation Mutations::Issues::Create
mount_mutation Mutations::Issues::SetAssignees mount_mutation Mutations::Issues::SetAssignees
......
# frozen_string_literal: true
module DependencyProxy
module GroupSettings
class UpdateService < BaseContainerService
ALLOWED_ATTRIBUTES = %i[enabled].freeze
def execute
return ServiceResponse.error(message: 'Access Denied', http_status: 403) unless allowed?
return ServiceResponse.error(message: 'Dependency proxy setting not found', http_status: 404) unless dependency_proxy_setting
if dependency_proxy_setting.update(dependency_proxy_setting_params)
ServiceResponse.success(payload: { dependency_proxy_setting: dependency_proxy_setting })
else
ServiceResponse.error(
message: dependency_proxy_setting.errors.full_messages.to_sentence || 'Bad request',
http_status: 400
)
end
end
private
def dependency_proxy_setting
container.dependency_proxy_setting
end
def allowed?
Ability.allowed?(current_user, :admin_dependency_proxy, container)
end
def dependency_proxy_setting_params
params.slice(*ALLOWED_ATTRIBUTES)
end
end
end
end
...@@ -4276,6 +4276,26 @@ Input type: `UpdateDependencyProxyImageTtlGroupPolicyInput` ...@@ -4276,6 +4276,26 @@ Input type: `UpdateDependencyProxyImageTtlGroupPolicyInput`
| <a id="mutationupdatedependencyproxyimagettlgrouppolicydependencyproxyimagettlpolicy"></a>`dependencyProxyImageTtlPolicy` | [`DependencyProxyImageTtlGroupPolicy`](#dependencyproxyimagettlgrouppolicy) | Group image TTL policy after mutation. | | <a id="mutationupdatedependencyproxyimagettlgrouppolicydependencyproxyimagettlpolicy"></a>`dependencyProxyImageTtlPolicy` | [`DependencyProxyImageTtlGroupPolicy`](#dependencyproxyimagettlgrouppolicy) | Group image TTL policy after mutation. |
| <a id="mutationupdatedependencyproxyimagettlgrouppolicyerrors"></a>`errors` | [`[String!]!`](#string) | Errors encountered during execution of the mutation. | | <a id="mutationupdatedependencyproxyimagettlgrouppolicyerrors"></a>`errors` | [`[String!]!`](#string) | Errors encountered during execution of the mutation. |
### `Mutation.updateDependencyProxySettings`
Input type: `UpdateDependencyProxySettingsInput`
#### Arguments
| Name | Type | Description |
| ---- | ---- | ----------- |
| <a id="mutationupdatedependencyproxysettingsclientmutationid"></a>`clientMutationId` | [`String`](#string) | A unique identifier for the client performing the mutation. |
| <a id="mutationupdatedependencyproxysettingsenabled"></a>`enabled` | [`Boolean`](#boolean) | Indicates whether the policy is enabled or disabled. |
| <a id="mutationupdatedependencyproxysettingsgrouppath"></a>`groupPath` | [`ID!`](#id) | Group path for the group dependency proxy. |
#### Fields
| Name | Type | Description |
| ---- | ---- | ----------- |
| <a id="mutationupdatedependencyproxysettingsclientmutationid"></a>`clientMutationId` | [`String`](#string) | A unique identifier for the client performing the mutation. |
| <a id="mutationupdatedependencyproxysettingsdependencyproxysetting"></a>`dependencyProxySetting` | [`DependencyProxySetting`](#dependencyproxysetting) | Group dependency proxy settings after mutation. |
| <a id="mutationupdatedependencyproxysettingserrors"></a>`errors` | [`[String!]!`](#string) | Errors encountered during execution of the mutation. |
### `Mutation.updateEpic` ### `Mutation.updateEpic`
Input type: `UpdateEpicInput` Input type: `UpdateEpicInput`
......
# frozen_string_literal: true
FactoryBot.define do
factory :dependency_proxy_group_setting, class: 'DependencyProxy::GroupSetting' do
group
enabled { true }
end
end
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Mutations::DependencyProxy::GroupSettings::Update do
using RSpec::Parameterized::TableSyntax
let_it_be_with_reload(:group) { create(:group) }
let_it_be_with_reload(:group_settings) { create(:dependency_proxy_group_setting, group: group) }
let_it_be(:user) { create(:user) }
let(:params) { { group_path: group.full_path, enabled: false } }
specify { expect(described_class).to require_graphql_authorizations(:admin_dependency_proxy) }
describe '#resolve' do
subject { described_class.new(object: group, context: { current_user: user }, field: nil).resolve(**params) }
shared_examples 'updating the dependency proxy group settings' do
it_behaves_like 'updating the dependency proxy group settings attributes',
from: { enabled: true },
to: { enabled: false }
it 'returns the dependency proxy settings no errors' do
expect(subject).to eq(
dependency_proxy_setting: group_settings,
errors: []
)
end
end
shared_examples 'denying access to dependency proxy group settings' do
it 'raises Gitlab::Graphql::Errors::ResourceNotAvailable' do
expect { subject }.to raise_error(Gitlab::Graphql::Errors::ResourceNotAvailable)
end
end
where(:user_role, :shared_examples_name) do
:maintainer | 'updating the dependency proxy group settings'
:developer | 'updating the dependency proxy group settings'
:reporter | 'denying access to dependency proxy group settings'
:guest | 'denying access to dependency proxy group settings'
:anonymous | 'denying access to dependency proxy group settings'
end
with_them do
before do
stub_config(dependency_proxy: { enabled: true })
group.send("add_#{user_role}", user) unless user_role == :anonymous
end
it_behaves_like params[:shared_examples_name]
end
end
end
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe 'Updating the dependency proxy group settings' do
include GraphqlHelpers
using RSpec::Parameterized::TableSyntax
let_it_be(:user) { create(:user) }
let(:params) do
{
group_path: group.full_path,
enabled: false
}
end
let(:mutation) do
graphql_mutation(:update_dependency_proxy_settings, params) do
<<~QL
dependencyProxySetting {
enabled
}
errors
QL
end
end
let(:mutation_response) { graphql_mutation_response(:update_dependency_proxy_settings) }
let(:group_settings) { mutation_response['dependencyProxySetting'] }
before do
stub_config(dependency_proxy: { enabled: true })
end
describe 'post graphql mutation' do
subject { post_graphql_mutation(mutation, current_user: user) }
let_it_be_with_reload(:group) { create(:group) }
let_it_be_with_reload(:group_settings) { create(:dependency_proxy_group_setting, group: group) }
context 'without permission' do
it 'returns no response' do
subject
expect(response).to have_gitlab_http_status(:success)
expect(mutation_response).to be_nil
end
end
context 'with permission' do
before do
group.add_developer(user)
end
it 'returns the updated dependency proxy settings', :aggregate_failures do
subject
expect(response).to have_gitlab_http_status(:success)
expect(mutation_response['errors']).to be_empty
expect(group_settings[:enabled]).to eq(false)
end
end
end
end
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe ::DependencyProxy::GroupSettings::UpdateService do
using RSpec::Parameterized::TableSyntax
let_it_be_with_reload(:group) { create(:group) }
let_it_be_with_reload(:group_settings) { create(:dependency_proxy_group_setting, group: group) }
let_it_be(:user) { create(:user) }
let_it_be(:params) { { enabled: false } }
describe '#execute' do
subject { described_class.new(container: group, current_user: user, params: params).execute }
shared_examples 'updating the dependency proxy group settings' do
it_behaves_like 'updating the dependency proxy group settings attributes',
from: { enabled: true },
to: { enabled: false }
it 'returns a success' do
result = subject
expect(result.payload[:dependency_proxy_setting]).to be_present
expect(result).to be_success
end
end
shared_examples 'denying access to dependency proxy group settings' do
context 'with existing dependency proxy group settings' do
it 'returns an error' do
result = subject
expect(result).to have_attributes(
message: 'Access Denied',
status: :error,
http_status: 403
)
end
end
end
where(:user_role, :shared_examples_name) do
:maintainer | 'updating the dependency proxy group settings'
:developer | 'updating the dependency proxy group settings'
:reporter | 'denying access to dependency proxy group settings'
:guest | 'denying access to dependency proxy group settings'
:anonymous | 'denying access to dependency proxy group settings'
end
with_them do
before do
stub_config(dependency_proxy: { enabled: true })
group.send("add_#{user_role}", user) unless user_role == :anonymous
end
it_behaves_like params[:shared_examples_name]
end
end
end
# frozen_string_literal: true
RSpec.shared_examples 'updating the dependency proxy group settings attributes' do |from: {}, to: {}|
it 'updates the dependency proxy settings' do
expect { subject }
.to change { group_settings.reload.enabled }.from(from[:enabled]).to(to[:enabled])
end
end
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