debian-mirror-gitlab/app/services/namespaces/package_settings/update_service.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

50 lines
1.6 KiB
Ruby
Raw Normal View History

2021-03-08 18:12:59 +05:30
# frozen_string_literal: true
module Namespaces
module PackageSettings
class UpdateService < BaseContainerService
include Gitlab::Utils::StrongMemoize
2021-06-08 01:23:25 +05:30
ALLOWED_ATTRIBUTES = %i[maven_duplicates_allowed
maven_duplicate_exception_regex
generic_duplicates_allowed
2022-11-25 23:54:43 +05:30
generic_duplicate_exception_regex
maven_package_requests_forwarding
npm_package_requests_forwarding
pypi_package_requests_forwarding
lock_maven_package_requests_forwarding
lock_npm_package_requests_forwarding
lock_pypi_package_requests_forwarding].freeze
2021-03-08 18:12:59 +05:30
def execute
return ServiceResponse.error(message: 'Access Denied', http_status: 403) unless allowed?
if package_settings.update(package_settings_params)
ServiceResponse.success(payload: { package_settings: package_settings })
else
ServiceResponse.error(
message: package_settings.errors.full_messages.to_sentence || 'Bad request',
http_status: 400
)
end
end
private
def package_settings
strong_memoize(:package_settings) do
@container.package_settings
end
end
def allowed?
2022-07-16 23:28:13 +05:30
Ability.allowed?(current_user, :admin_package, @container)
2021-03-08 18:12:59 +05:30
end
def package_settings_params
@params.slice(*ALLOWED_ATTRIBUTES)
end
end
end
end