Commit 15762985 authored by Robert Speicher's avatar Robert Speicher

Merge branch 'ee-backport-api-parameters' into 'master'

EE: Backport EE API parameters in lib/api

See merge request gitlab-org/gitlab-ee!10326
parents 5f475d63 7a0d55d4
# frozen_string_literal: true
module EE
module API
module Helpers
module IssuesHelpers
extend ActiveSupport::Concern
class_methods do
extend ::Gitlab::Utils::Override
override :update_params_at_least_one_of
def update_params_at_least_one_of
[*super, :weight]
end
end
end
end
end
end
# frozen_string_literal: true
module EE
module API
module Helpers
module ProjectsHelpers
extend ActiveSupport::Concern
class_methods do
# We don't use "override" here as this module is included into various
# API classes, and for reasons unknown the override would be verified
# in the context of the including class, and not in the context of
# `API::Helpers::ProjectsHelpers`.
#
# Likely this is related to
# https://gitlab.com/gitlab-org/gitlab-ce/issues/50911.
def update_params_at_least_one_of
super.concat [
:approvals_before_merge,
:repository_storage,
:external_authorization_classification_label,
:import_url,
:packages_enabled,
:fallback_approvals_required
]
end
end
end
end
end
end
# frozen_string_literal: true
module EE
module API
module Issues
extend ActiveSupport::Concern
prepended do
helpers do
params :issues_params_ee do
optional :weight, types: [Integer, String], integer_none_any: true, desc: 'The weight of the issue'
end
params :issue_params_ee do
optional :weight, type: Integer, desc: 'The weight of the issue'
end
end
end
end
end
end
......@@ -9,20 +9,6 @@ module EE
helpers do
extend ::Gitlab::Utils::Override
params :optional_filter_params_ee do
optional :wiki_checksum_failed, type: Grape::API::Boolean, default: false, desc: 'Limit by projects where wiki checksum is failed'
optional :repository_checksum_failed, type: Grape::API::Boolean, default: false, desc: 'Limit by projects where repository checksum is failed'
end
params :optional_update_params_ee do
optional :mirror_user_id, type: Integer, desc: 'User responsible for all the activity surrounding a pull mirror event'
optional :only_mirror_protected_branches, type: Grape::API::Boolean, desc: 'Only mirror protected branches'
optional :mirror_overwrites_diverged_branches, type: Grape::API::Boolean, desc: 'Pull mirror overwrites diverged branches'
optional :import_url, type: String, desc: 'URL from which the project is imported'
optional :packages_enabled, type: Grape::API::Boolean, desc: 'Enable project packages feature'
optional :fallback_approvals_required, type: Integer, desc: 'Overall approvals required when no rule is present'
end
def apply_filters(projects)
projects = super(projects)
projects = projects.verification_failed_wikis if params[:wiki_checksum_failed]
......@@ -57,22 +43,6 @@ module EE
end
end
end
class_methods do
extend ::Gitlab::Utils::Override
override :update_params_at_least_one_of
def update_params_at_least_one_of
super.concat [
:approvals_before_merge,
:repository_storage,
:external_authorization_classification_label,
:import_url,
:packages_enabled,
:fallback_approvals_required
]
end
end
end
end
end
......@@ -20,17 +20,19 @@ module API
optional :share_with_group_lock, type: Boolean, desc: 'Prevent sharing a project with another group within this group'
end
params :optional_params_ee do
optional :membership_lock, type: Boolean, desc: 'Prevent adding new members to project membership within this group'
optional :ldap_cn, type: String, desc: 'LDAP Common Name'
optional :ldap_access, type: Integer, desc: 'A valid access level'
optional :shared_runners_minutes_limit, type: Integer, desc: '(admin-only) Pipeline minutes quota for this group'
all_or_none_of :ldap_cn, :ldap_access
if Gitlab.ee?
params :optional_params_ee do
optional :membership_lock, type: Boolean, desc: 'Prevent adding new members to project membership within this group'
optional :ldap_cn, type: String, desc: 'LDAP Common Name'
optional :ldap_access, type: Integer, desc: 'A valid access level'
optional :shared_runners_minutes_limit, type: Integer, desc: '(admin-only) Pipeline minutes quota for this group'
all_or_none_of :ldap_cn, :ldap_access
end
end
params :optional_params do
use :optional_params_ce
use :optional_params_ee
use :optional_params_ee if Gitlab.ee?
end
params :statistics_params do
......@@ -174,8 +176,9 @@ module API
optional :path, type: String, desc: 'The path of the group'
use :optional_params
# EE
optional :file_template_project_id, type: Integer, desc: 'The ID of a project to use for custom templates in this group'
if Gitlab.ee?
optional :file_template_project_id, type: Integer, desc: 'The ID of a project to use for custom templates in this group'
end
end
put ':id' do
group = find_group!(params[:id])
......
# frozen_string_literal: true
module API
module Helpers
module IssuesHelpers
def self.update_params_at_least_one_of
[
:assignee_id,
:assignee_ids,
:confidential,
:created_at,
:description,
:discussion_locked,
:due_date,
:labels,
:milestone_id,
:state_event,
:title
]
end
end
end
end
API::Helpers::IssuesHelpers.prepend(EE::API::Helpers::IssuesHelpers)
......@@ -31,20 +31,52 @@ module API
optional :initialize_with_readme, type: Boolean, desc: "Initialize a project with a README.md"
end
params :optional_project_params_ee do
optional :repository_storage, type: String, desc: 'Which storage shard the repository is on. Available only to admins'
optional :approvals_before_merge, type: Integer, desc: 'How many approvers should approve merge request by default'
optional :external_authorization_classification_label, type: String, desc: 'The classification label for the project'
optional :mirror, type: Boolean, desc: 'Enables pull mirroring in a project'
optional :mirror_trigger_builds, type: Boolean, desc: 'Pull mirroring triggers builds'
if Gitlab.ee?
params :optional_project_params_ee do
optional :repository_storage, type: String, desc: 'Which storage shard the repository is on. Available only to admins'
optional :approvals_before_merge, type: Integer, desc: 'How many approvers should approve merge request by default'
optional :external_authorization_classification_label, type: String, desc: 'The classification label for the project'
optional :mirror, type: Boolean, desc: 'Enables pull mirroring in a project'
optional :mirror_trigger_builds, type: Boolean, desc: 'Pull mirroring triggers builds'
end
end
params :optional_project_params do
use :optional_project_params_ce
use :optional_project_params_ee
use :optional_project_params_ee if Gitlab.ee?
end
end
end
def self.update_params_at_least_one_of
[
:jobs_enabled,
:resolve_outdated_diff_discussions,
:ci_config_path,
:container_registry_enabled,
:default_branch,
:description,
:issues_enabled,
:lfs_enabled,
:merge_requests_enabled,
:merge_method,
:name,
:only_allow_merge_if_all_discussions_are_resolved,
:only_allow_merge_if_pipeline_succeeds,
:path,
:printing_merge_request_link_enabled,
:public_builds,
:request_access_enabled,
:shared_runners_enabled,
:snippets_enabled,
:tag_list,
:visibility,
:wiki_enabled,
:avatar
]
end
end
end
end
API::Helpers::ProjectsHelpers.prepend(EE::API::Helpers::ProjectsHelpers)
......@@ -8,17 +8,6 @@ module API
helpers ::Gitlab::IssuableMetadata
# EE::API::Issues would override the following helpers
helpers do
params :issues_params_ee do
end
params :issue_params_ee do
end
end
prepend EE::API::Issues # rubocop: disable Cop/InjectEnterpriseEditionModule
helpers do
# rubocop: disable CodeReuse/ActiveRecord
def find_issues(args = {})
......@@ -35,6 +24,16 @@ module API
end
# rubocop: enable CodeReuse/ActiveRecord
if Gitlab.ee?
params :issues_params_ee do
optional :weight, types: [Integer, String], integer_none_any: true, desc: 'The weight of the issue'
end
params :issue_params_ee do
optional :weight, type: Integer, desc: 'The weight of the issue'
end
end
params :issues_params do
optional :labels, type: Array[String], coerce_with: Validations::Types::LabelsList.coerce, desc: 'Comma-separated list of label names'
optional :milestone, type: String, desc: 'Milestone title'
......@@ -59,7 +58,7 @@ module API
optional :confidential, type: Boolean, desc: 'Filter confidential or public issues'
use :pagination
use :issues_params_ee
use :issues_params_ee if Gitlab.ee?
end
params :issue_params do
......@@ -72,7 +71,7 @@ module API
optional :confidential, type: Boolean, desc: 'Boolean parameter if the issue should be confidential'
optional :discussion_locked, type: Boolean, desc: " Boolean parameter indicating if the issue's discussion is locked"
use :issue_params_ee
use :issue_params_ee if Gitlab.ee?
end
end
......@@ -221,9 +220,8 @@ module API
desc: 'Date time when the issue was updated. Available only for admins and project owners.'
optional :state_event, type: String, values: %w[reopen close], desc: 'State of the issue'
use :issue_params
at_least_one_of :title, :description, :assignee_ids, :assignee_id, :milestone_id,
:labels, :created_at, :due_date, :confidential, :state_event,
:weight, :discussion_locked
at_least_one_of(*Helpers::IssuesHelpers.update_params_at_least_one_of)
end
# rubocop: disable CodeReuse/ActiveRecord
put ':id/issues/:issue_iid' do
......
......@@ -11,12 +11,20 @@ module API
before { authenticate_non_get! }
helpers do
params :optional_filter_params_ee do
# EE::API::Projects would override this helper
end
if Gitlab.ee?
params :optional_filter_params_ee do
optional :wiki_checksum_failed, type: Grape::API::Boolean, default: false, desc: 'Limit by projects where wiki checksum is failed'
optional :repository_checksum_failed, type: Grape::API::Boolean, default: false, desc: 'Limit by projects where repository checksum is failed'
end
params :optional_update_params_ee do
# EE::API::Projects would override this helper
params :optional_update_params_ee do
optional :mirror_user_id, type: Integer, desc: 'User responsible for all the activity surrounding a pull mirror event'
optional :only_mirror_protected_branches, type: Grape::API::Boolean, desc: 'Only mirror protected branches'
optional :mirror_overwrites_diverged_branches, type: Grape::API::Boolean, desc: 'Pull mirror overwrites diverged branches'
optional :import_url, type: String, desc: 'URL from which the project is imported'
optional :packages_enabled, type: Grape::API::Boolean, desc: 'Enable project packages feature'
optional :fallback_approvals_required, type: Integer, desc: 'Overall approvals required when no rule is present'
end
end
# EE::API::Projects would override this method
......@@ -35,36 +43,6 @@ module API
end
end
prepend EE::API::Projects # rubocop: disable Cop/InjectEnterpriseEditionModule
def self.update_params_at_least_one_of
[
:jobs_enabled,
:resolve_outdated_diff_discussions,
:ci_config_path,
:container_registry_enabled,
:default_branch,
:description,
:issues_enabled,
:lfs_enabled,
:merge_requests_enabled,
:merge_method,
:name,
:only_allow_merge_if_all_discussions_are_resolved,
:only_allow_merge_if_pipeline_succeeds,
:path,
:printing_merge_request_link_enabled,
:public_builds,
:request_access_enabled,
:shared_runners_enabled,
:snippets_enabled,
:tag_list,
:visibility,
:wiki_enabled,
:avatar
]
end
helpers do
params :statistics_params do
optional :statistics, type: Boolean, default: false, desc: 'Include project statistics'
......@@ -99,7 +77,7 @@ module API
optional :with_programming_language, type: String, desc: 'Limit to repositories which use the given programming language'
optional :min_access_level, type: Integer, values: Gitlab::Access.all_values, desc: 'Limit by minimum access level of authenticated user'
use :optional_filter_params_ee
use :optional_filter_params_ee if Gitlab.ee?
end
params :create_params do
......@@ -318,9 +296,9 @@ module API
optional :path, type: String, desc: 'The path of the repository'
use :optional_project_params
use :optional_update_params_ee
use :optional_update_params_ee if Gitlab.ee?
at_least_one_of(*::API::Projects.update_params_at_least_one_of)
at_least_one_of(*Helpers::ProjectsHelpers.update_params_at_least_one_of)
end
put ':id' do
authorize_admin_project
......@@ -538,3 +516,5 @@ module API
end
end
end
API::Projects.prepend(EE::API::Projects)
......@@ -51,23 +51,29 @@ module API
optional :merge_access_level, type: Integer,
values: ProtectedBranch::MergeAccessLevel.allowed_access_levels,
desc: 'Access levels allowed to merge (defaults: `40`, maintainer access level)'
optional :unprotect_access_level, type: Integer,
values: ProtectedBranch::UnprotectAccessLevel.allowed_access_levels,
desc: 'Access levels allowed to unprotect (defaults: `40`, maintainer access level)'
optional :allowed_to_push, type: Array, desc: 'An array of users/groups allowed to push' do
optional :access_level, type: Integer, values: ProtectedBranch::PushAccessLevel.allowed_access_levels
optional :user_id, type: Integer
optional :group_id, type: Integer
end
optional :allowed_to_merge, type: Array, desc: 'An array of users/groups allowed to merge' do
optional :access_level, type: Integer, values: ProtectedBranch::MergeAccessLevel.allowed_access_levels
optional :user_id, type: Integer
optional :group_id, type: Integer
end
optional :allowed_to_unprotect, type: Array, desc: 'An array of users/groups allowed to unprotect' do
optional :access_level, type: Integer, values: ProtectedBranch::UnprotectAccessLevel.allowed_access_levels
optional :user_id, type: Integer
optional :group_id, type: Integer
if Gitlab.ee?
optional :unprotect_access_level, type: Integer,
values: ProtectedBranch::UnprotectAccessLevel.allowed_access_levels,
desc: 'Access levels allowed to unprotect (defaults: `40`, maintainer access level)'
optional :allowed_to_push, type: Array, desc: 'An array of users/groups allowed to push' do
optional :access_level, type: Integer, values: ProtectedBranch::PushAccessLevel.allowed_access_levels
optional :user_id, type: Integer
optional :group_id, type: Integer
end
optional :allowed_to_merge, type: Array, desc: 'An array of users/groups allowed to merge' do
optional :access_level, type: Integer, values: ProtectedBranch::MergeAccessLevel.allowed_access_levels
optional :user_id, type: Integer
optional :group_id, type: Integer
end
optional :allowed_to_unprotect, type: Array, desc: 'An array of users/groups allowed to unprotect' do
optional :access_level, type: Integer, values: ProtectedBranch::UnprotectAccessLevel.allowed_access_levels
optional :user_id, type: Integer
optional :group_id, type: Integer
end
end
end
# rubocop: disable CodeReuse/ActiveRecord
......
......@@ -100,8 +100,8 @@ module API
optional :prometheus_metrics_enabled, type: Boolean, desc: 'Enable Prometheus metrics'
optional :recaptcha_enabled, type: Boolean, desc: 'Helps prevent bots from creating accounts'
given recaptcha_enabled: ->(val) { val } do
requires :recaptcha_private_key, type: String, desc: 'Generate private key at http://www.google.com/recaptcha'
requires :recaptcha_site_key, type: String, desc: 'Generate site key at http://www.google.com/recaptcha'
requires :recaptcha_private_key, type: String, desc: 'Generate private key at http://www.google.com/recaptcha'
end
optional :repository_checks_enabled, type: Boolean, desc: "GitLab will periodically run 'git fsck' in all project and wiki repositories to look for silent disk corruption issues."
optional :repository_storages, type: Array[String], desc: 'Storage paths for new projects'
......@@ -135,37 +135,43 @@ module API
desc: "Restrictions on the complexity of uploaded #{type.upcase} keys. A value of #{ApplicationSetting::FORBIDDEN_KEY_VALUE} disables all #{type.upcase} keys."
end
## EE-only START
optional :elasticsearch_aws, type: Boolean, desc: 'Enable support for AWS hosted elasticsearch'
given elasticsearch_aws: ->(val) { val } do
optional :elasticsearch_aws_access_key, type: String, desc: 'AWS IAM access key'
requires :elasticsearch_aws_region, type: String, desc: 'The AWS region the elasticsearch domain is configured'
optional :elasticsearch_aws_secret_access_key, type: String, desc: 'AWS IAM secret access key'
end
optional :elasticsearch_indexing, type: Boolean, desc: 'Enable Elasticsearch indexing'
given elasticsearch_indexing: ->(val) { val } do
optional :elasticsearch_search, type: Boolean, desc: 'Enable Elasticsearch search'
requires :elasticsearch_url, type: String, desc: 'The url to use for connecting to Elasticsearch. Use a comma-separated list to support clustering (e.g., "http://localhost:9200, http://localhost:9201")'
end
optional :email_additional_text, type: String, desc: 'Additional text added to the bottom of every email for legal/auditing/compliance reasons'
optional :help_text, type: String, desc: 'GitLab server administrator information'
optional :repository_size_limit, type: Integer, desc: 'Size limit per repository (MB)'
optional :file_template_project_id, type: Integer, desc: 'ID of project where instance-level file templates are stored.'
optional :repository_storages, type: Array[String], desc: 'A list of names of enabled storage paths, taken from `gitlab.yml`. New projects will be created in one of these stores, chosen at random.'
optional :snowplow_enabled, type: Boolean, desc: 'Enable Snowplow'
given snowplow_enabled: ->(val) { val } do
requires :snowplow_collector_uri, type: String, desc: 'Snowplow Collector URI'
optional :snowplow_cookie_domain, type: String, desc: 'Snowplow cookie domain'
optional :snowplow_site_id, type: String, desc: 'Snowplow Site/Application ID'
if Gitlab.ee?
optional :elasticsearch_aws, type: Boolean, desc: 'Enable support for AWS hosted elasticsearch'
given elasticsearch_aws: ->(val) { val } do
optional :elasticsearch_aws_access_key, type: String, desc: 'AWS IAM access key'
requires :elasticsearch_aws_region, type: String, desc: 'The AWS region the elasticsearch domain is configured'
optional :elasticsearch_aws_secret_access_key, type: String, desc: 'AWS IAM secret access key'
end
optional :elasticsearch_indexing, type: Boolean, desc: 'Enable Elasticsearch indexing'
given elasticsearch_indexing: ->(val) { val } do
optional :elasticsearch_search, type: Boolean, desc: 'Enable Elasticsearch search'
requires :elasticsearch_url, type: String, desc: 'The url to use for connecting to Elasticsearch. Use a comma-separated list to support clustering (e.g., "http://localhost:9200, http://localhost:9201")'
end
optional :email_additional_text, type: String, desc: 'Additional text added to the bottom of every email for legal/auditing/compliance reasons'
optional :help_text, type: String, desc: 'GitLab server administrator information'
optional :repository_size_limit, type: Integer, desc: 'Size limit per repository (MB)'
optional :file_template_project_id, type: Integer, desc: 'ID of project where instance-level file templates are stored.'
optional :repository_storages, type: Array[String], desc: 'A list of names of enabled storage paths, taken from `gitlab.yml`. New projects will be created in one of these stores, chosen at random.'
optional :snowplow_enabled, type: Boolean, desc: 'Enable Snowplow'
given snowplow_enabled: ->(val) { val } do
requires :snowplow_collector_uri, type: String, desc: 'Snowplow Collector URI'
optional :snowplow_cookie_domain, type: String, desc: 'Snowplow cookie domain'
optional :snowplow_site_id, type: String, desc: 'Snowplow Site/Application ID'
end
optional :usage_ping_enabled, type: Boolean, desc: 'Every week GitLab will report license usage back to GitLab, Inc.'
end
optional :usage_ping_enabled, type: Boolean, desc: 'Every week GitLab will report license usage back to GitLab, Inc.'
## EE-only END
optional_attributes = ::ApplicationSettingsHelper.visible_attributes << :performance_bar_allowed_group_id
## EE-only START
optional_attributes += EE::ApplicationSettingsHelper.possible_licensed_attributes
## EE-only END
if Gitlab.ee?
optional_attributes += EE::ApplicationSettingsHelper.possible_licensed_attributes
end
optional(*optional_attributes)
at_least_one_of(*optional_attributes)
......
......@@ -52,8 +52,9 @@ module API
optional :private_profile, type: Boolean, desc: 'Flag indicating the user has a private profile'
all_or_none_of :extern_uid, :provider
# EE
optional :shared_runners_minutes_limit, type: Integer, desc: 'Pipeline minutes quota for this user'
if Gitlab.ee?
optional :shared_runners_minutes_limit, type: Integer, desc: 'Pipeline minutes quota for this user'
end
end
params :sort_params do
......@@ -84,8 +85,9 @@ module API
use :pagination
use :with_custom_attributes
# EE
optional :skip_ldap, type: Boolean, default: false, desc: 'Skip LDAP users'
if Gitlab.ee?
optional :skip_ldap, type: Boolean, default: false, desc: 'Skip LDAP users'
end
end
# rubocop: disable CodeReuse/ActiveRecord
get do
......
......@@ -56,8 +56,9 @@ module API
requires :value, type: String, desc: 'The value of the variable'
optional :protected, type: String, desc: 'Whether the variable is protected'
# EE
optional :environment_scope, type: String, desc: 'The environment_scope of the variable'
if Gitlab.ee?
optional :environment_scope, type: String, desc: 'The environment_scope of the variable'
end
end
post ':id/variables' do
variable_params = declared_params(include_missing: false)
......@@ -80,8 +81,9 @@ module API
optional :value, type: String, desc: 'The value of the variable'
optional :protected, type: String, desc: 'Whether the variable is protected'
# EE
optional :environment_scope, type: String, desc: 'The environment_scope of the variable'
if Gitlab.ee?
optional :environment_scope, type: String, desc: 'The environment_scope of the variable'
end
end
# rubocop: disable CodeReuse/ActiveRecord
put ':id/variables/:key' 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