Commit 4368a170 authored by Oswaldo Ferreira's avatar Oswaldo Ferreira

Separate CE from EE params on V4 API

parent 453cc447
...@@ -5,21 +5,26 @@ module API ...@@ -5,21 +5,26 @@ module API
before { authenticate! } before { authenticate! }
helpers do helpers do
params :optional_params do params :optional_params_ce do
optional :description, type: String, desc: 'The description of the group' optional :description, type: String, desc: 'The description of the group'
optional :visibility, type: String, values: Gitlab::VisibilityLevel.string_values, desc: 'The visibility of the group' optional :visibility, type: String, values: Gitlab::VisibilityLevel.string_values, desc: 'The visibility of the group'
optional :lfs_enabled, type: Boolean, desc: 'Enable/disable LFS for the projects in this group' optional :lfs_enabled, type: Boolean, desc: 'Enable/disable LFS for the projects in this group'
optional :request_access_enabled, type: Boolean, desc: 'Allow users to request member access' optional :request_access_enabled, type: Boolean, desc: 'Allow users to request member access'
optional :membership_lock, type: Boolean, desc: 'Prevent adding new members to project membership within this group'
optional :share_with_group_lock, type: Boolean, desc: 'Prevent sharing a project with another group within this group' optional :share_with_group_lock, type: Boolean, desc: 'Prevent sharing a project with another group within this group'
end end
params :optional_params_ee do 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_cn, type: String, desc: 'LDAP Common Name'
optional :ldap_access, type: Integer, desc: 'A valid access level' optional :ldap_access, type: Integer, desc: 'A valid access level'
all_or_none_of :ldap_cn, :ldap_access all_or_none_of :ldap_cn, :ldap_access
end end
params :optional_params do
use :optional_params_ce
use :optional_params_ee
end
params :statistics_params do params :statistics_params do
optional :statistics, type: Boolean, default: false, desc: 'Include project statistics' optional :statistics, type: Boolean, default: false, desc: 'Include project statistics'
end end
...@@ -75,7 +80,6 @@ module API ...@@ -75,7 +80,6 @@ module API
requires :path, type: String, desc: 'The path of the group' requires :path, type: String, desc: 'The path of the group'
optional :parent_id, type: Integer, desc: 'The parent group id for creating nested group' optional :parent_id, type: Integer, desc: 'The parent group id for creating nested group'
use :optional_params use :optional_params
use :optional_params_ee
end end
post do post do
authorize! :create_group authorize! :create_group
......
...@@ -30,16 +30,23 @@ module API ...@@ -30,16 +30,23 @@ module API
use :pagination use :pagination
end end
params :issue_params do params :issue_params_ce do
optional :description, type: String, desc: 'The description of an issue' optional :description, type: String, desc: 'The description of an issue'
optional :assignee_id, type: Integer, desc: 'The ID of a user to assign issue' optional :assignee_id, type: Integer, desc: 'The ID of a user to assign issue'
optional :milestone_id, type: Integer, desc: 'The ID of a milestone to assign issue' optional :milestone_id, type: Integer, desc: 'The ID of a milestone to assign issue'
optional :labels, type: String, desc: 'Comma-separated list of label names' optional :labels, type: String, desc: 'Comma-separated list of label names'
optional :due_date, type: String, desc: 'Date string in the format YEAR-MONTH-DAY' optional :due_date, type: String, desc: 'Date string in the format YEAR-MONTH-DAY'
optional :confidential, type: Boolean, desc: 'Boolean parameter if the issue should be confidential' optional :confidential, type: Boolean, desc: 'Boolean parameter if the issue should be confidential'
# Gitlab-EE specific end
params :issue_params_ee do
optional :weight, type: Integer, values: 0..9, desc: 'The weight of the issue' optional :weight, type: Integer, values: 0..9, desc: 'The weight of the issue'
end end
params :issue_params do
use :issue_params_ce
use :issue_params_ee
end
end end
resource :issues do resource :issues do
......
...@@ -33,15 +33,23 @@ module API ...@@ -33,15 +33,23 @@ module API
end end
end end
params :optional_params do params :optional_params_ce do
optional :description, type: String, desc: 'The description of the merge request' optional :description, type: String, desc: 'The description of the merge request'
optional :assignee_id, type: Integer, desc: 'The ID of a user to assign the merge request' optional :assignee_id, type: Integer, desc: 'The ID of a user to assign the merge request'
optional :milestone_id, type: Integer, desc: 'The ID of a milestone to assign the merge request' optional :milestone_id, type: Integer, desc: 'The ID of a milestone to assign the merge request'
optional :labels, type: String, desc: 'Comma-separated list of label names' optional :labels, type: String, desc: 'Comma-separated list of label names'
optional :approvals_before_merge, type: Integer, desc: 'Number of approvals required before this can be merged'
optional :remove_source_branch, type: Boolean, desc: 'Remove source branch when merging' optional :remove_source_branch, type: Boolean, desc: 'Remove source branch when merging'
end
params :optional_params_ee do
optional :approvals_before_merge, type: Integer, desc: 'Number of approvals required before this can be merged'
optional :squash, type: Boolean, desc: 'Squash commits when merging' optional :squash, type: Boolean, desc: 'Squash commits when merging'
end end
params :optional_params do
use :optional_params_ce
use :optional_params_ee
end
end end
desc 'List merge requests' do desc 'List merge requests' do
...@@ -147,14 +155,29 @@ module API ...@@ -147,14 +155,29 @@ module API
success Entities::MergeRequest success Entities::MergeRequest
end end
params do params do
# CE
at_least_one_of_ce = [
:assignee_id,
:description,
:labels,
:milestone_id,
:remove_source_branch,
:state_event,
:target_branch,
:title
]
optional :title, type: String, allow_blank: false, desc: 'The title of the merge request' optional :title, type: String, allow_blank: false, desc: 'The title of the merge request'
optional :target_branch, type: String, allow_blank: false, desc: 'The target branch' optional :target_branch, type: String, allow_blank: false, desc: 'The target branch'
optional :state_event, type: String, values: %w[close reopen], optional :state_event, type: String, values: %w[close reopen],
desc: 'Status of the merge request' desc: 'Status of the merge request'
# EE
at_least_one_of_ee = [
:squash
]
use :optional_params use :optional_params
at_least_one_of :title, :target_branch, :description, :assignee_id, at_least_one_of(*(at_least_one_of_ce + at_least_one_of_ee))
:milestone_id, :labels, :state_event,
:remove_source_branch, :squash
end end
put ':id/merge_requests/:merge_request_iid' do put ':id/merge_requests/:merge_request_iid' do
merge_request = find_merge_request_with_access(params.delete(:merge_request_iid), :update_merge_request) merge_request = find_merge_request_with_access(params.delete(:merge_request_iid), :update_merge_request)
...@@ -175,12 +198,15 @@ module API ...@@ -175,12 +198,15 @@ module API
success Entities::MergeRequest success Entities::MergeRequest
end end
params do params do
# CE
optional :merge_commit_message, type: String, desc: 'Custom merge commit message' optional :merge_commit_message, type: String, desc: 'Custom merge commit message'
optional :should_remove_source_branch, type: Boolean, optional :should_remove_source_branch, type: Boolean,
desc: 'When true, the source branch will be deleted if possible' desc: 'When true, the source branch will be deleted if possible'
optional :merge_when_pipeline_succeeds, type: Boolean, optional :merge_when_pipeline_succeeds, type: Boolean,
desc: 'When true, this merge request will be merged when the pipeline succeeds' desc: 'When true, this merge request will be merged when the pipeline succeeds'
optional :sha, type: String, desc: 'When present, must have the HEAD SHA of the source branch' optional :sha, type: String, desc: 'When present, must have the HEAD SHA of the source branch'
# EE
optional :squash, type: Boolean, desc: 'When true, the commits will be squashed into a single commit on merge' optional :squash, type: Boolean, desc: 'When true, the commits will be squashed into a single commit on merge'
end end
put ':id/merge_requests/:merge_request_iid/merge' do put ':id/merge_requests/:merge_request_iid/merge' do
......
...@@ -6,7 +6,7 @@ module API ...@@ -6,7 +6,7 @@ module API
before { authenticate_non_get! } before { authenticate_non_get! }
helpers do helpers do
params :optional_params do params :optional_params_ce do
optional :description, type: String, desc: 'The description of the project' optional :description, type: String, desc: 'The description of the project'
optional :issues_enabled, type: Boolean, desc: 'Flag indication if the issue tracker is enabled' optional :issues_enabled, type: Boolean, desc: 'Flag indication if the issue tracker is enabled'
optional :merge_requests_enabled, type: Boolean, desc: 'Flag indication if merge requests are enabled' optional :merge_requests_enabled, type: Boolean, desc: 'Flag indication if merge requests are enabled'
...@@ -21,11 +21,17 @@ module API ...@@ -21,11 +21,17 @@ module API
optional :request_access_enabled, type: Boolean, desc: 'Allow users to request member access' optional :request_access_enabled, type: Boolean, desc: 'Allow users to request member access'
optional :only_allow_merge_if_pipeline_succeeds, type: Boolean, desc: 'Only allow to merge if builds succeed' optional :only_allow_merge_if_pipeline_succeeds, type: Boolean, desc: 'Only allow to merge if builds succeed'
optional :only_allow_merge_if_all_discussions_are_resolved, type: Boolean, desc: 'Only allow to merge if all discussions are resolved' optional :only_allow_merge_if_all_discussions_are_resolved, type: Boolean, desc: 'Only allow to merge if all discussions are resolved'
end
# EE-specific params :optional_params_ee do
optional :repository_storage, type: String, desc: 'Which storage shard the repository is on. Available only to admins' 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 :approvals_before_merge, type: Integer, desc: 'How many approvers should approve merge request by default'
end end
params :optional_params do
use :optional_params_ce
use :optional_params_ee
end
end end
resource :projects do resource :projects do
...@@ -202,19 +208,39 @@ module API ...@@ -202,19 +208,39 @@ module API
success Entities::Project success Entities::Project
end end
params do params do
# CE
at_least_one_of_ce =
[
:builds_enabled,
:container_registry_enabled,
:default_branch,
:description,
:issues_enabled,
:lfs_enabled,
:merge_requests_enabled,
:name,
:only_allow_merge_if_all_discussions_are_resolved,
:only_allow_merge_if_pipeline_succeeds,
:path,
:public_builds,
:request_access_enabled,
:shared_runners_enabled,
:snippets_enabled,
:visibility,
:wiki_enabled,
]
optional :name, type: String, desc: 'The name of the project' optional :name, type: String, desc: 'The name of the project'
optional :default_branch, type: String, desc: 'The default branch of the project' optional :default_branch, type: String, desc: 'The default branch of the project'
optional :path, type: String, desc: 'The path of the repository' optional :path, type: String, desc: 'The path of the repository'
# EE
at_least_one_of_ee = [
:approvals_before_merge,
:repository_storage
]
use :optional_params use :optional_params
at_least_one_of :name, :description, :issues_enabled, :merge_requests_enabled, at_least_one_of(*(at_least_one_of_ce + at_least_one_of_ee))
:wiki_enabled, :builds_enabled, :snippets_enabled,
:shared_runners_enabled, :container_registry_enabled,
:lfs_enabled, :visibility, :public_builds,
:request_access_enabled, :only_allow_merge_if_pipeline_succeeds,
:only_allow_merge_if_all_discussions_are_resolved, :path,
:default_branch,
## EE-specific
:repository_storage, :approvals_before_merge
end end
put ':id' do put ':id' do
authorize_admin_project authorize_admin_project
......
...@@ -20,6 +20,55 @@ module API ...@@ -20,6 +20,55 @@ module API
success Entities::ApplicationSetting success Entities::ApplicationSetting
end end
params do params do
# CE
at_least_one_of_ce = [
:admin_notification_email,
:after_sign_out_path,
:after_sign_up_text,
:akismet_enabled,
:container_registry_token_expire_delay,
:default_artifacts_expire_in,
:default_branch_protection,
:default_group_visibility,
:default_project_visibility,
:default_projects_limit,
:default_snippet_visibility,
:disabled_oauth_sign_in_sources,
:domain_blacklist_enabled,
:domain_whitelist,
:email_author_in_body,
:enabled_git_access_protocol,
:gravatar_enabled,
:help_page_text,
:home_page_url,
:housekeeping_enabled,
:html_emails_enabled,
:import_sources,
:koding_enabled,
:max_artifacts_size,
:max_attachment_size,
:max_pages_size,
:metrics_enabled,
:plantuml_enabled,
:polling_interval_multiplier,
:recaptcha_enabled,
:repository_checks_enabled,
:repository_storage,
:require_two_factor_authentication,
:restricted_visibility_levels,
:send_user_confirmation_email,
:sentry_enabled,
:session_expire_delay,
:shared_runners_enabled,
:sidekiq_throttling_enabled,
:sign_in_text,
:signin_enabled,
:signup_enabled,
:terminal_max_session_time,
:user_default_external,
:user_oauth_applications,
:version_check_enabled
]
optional :default_branch_protection, type: Integer, values: [0, 1, 2], desc: 'Determine if developers can push to master' optional :default_branch_protection, type: Integer, values: [0, 1, 2], desc: 'Determine if developers can push to master'
optional :default_project_visibility, type: String, values: Gitlab::VisibilityLevel.string_values, desc: 'The default project visibility' optional :default_project_visibility, type: String, values: Gitlab::VisibilityLevel.string_values, desc: 'The default project visibility'
optional :default_snippet_visibility, type: String, values: Gitlab::VisibilityLevel.string_values, desc: 'The default snippet visibility' optional :default_snippet_visibility, type: String, values: Gitlab::VisibilityLevel.string_values, desc: 'The default snippet visibility'
...@@ -111,22 +160,6 @@ module API ...@@ -111,22 +160,6 @@ module API
end end
optional :terminal_max_session_time, type: Integer, desc: 'Maximum time for web terminal websocket connection (in seconds). Set to 0 for unlimited time.' optional :terminal_max_session_time, type: Integer, desc: 'Maximum time for web terminal websocket connection (in seconds). Set to 0 for unlimited time.'
optional :polling_interval_multiplier, type: BigDecimal, desc: 'Interval multiplier used by endpoints that perform polling. Set to 0 to disable polling.' optional :polling_interval_multiplier, type: BigDecimal, desc: 'Interval multiplier used by endpoints that perform polling. Set to 0 to disable polling.'
# GitLab-EE specific settings
optional :help_text, type: String, desc: 'GitLab server administrator information'
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 :elasticsearch_aws, type: Boolean, desc: 'Enable support for AWS hosted elasticsearch'
given elasticsearch_aws: ->(val) { val } do
requires :elasticsearch_aws_region, type: String, desc: 'The AWS region the elasticsearch domain is configured'
optional :elasticsearch_aws_access_key, type: String, desc: 'AWS IAM access key'
optional :elasticsearch_aws_secret_access_key, type: String, desc: 'AWS IAM secret access key'
end
optional :usage_ping_enabled, type: Boolean, desc: 'Every week GitLab will report license usage back to GitLab, Inc.'
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 :repository_size_limit, type: Integer, desc: 'Size limit per repository (MB)'
at_least_one_of :default_branch_protection, :default_project_visibility, :default_snippet_visibility, at_least_one_of :default_branch_protection, :default_project_visibility, :default_snippet_visibility,
:default_group_visibility, :restricted_visibility_levels, :import_sources, :default_group_visibility, :restricted_visibility_levels, :import_sources,
:enabled_git_access_protocol, :gravatar_enabled, :default_projects_limit, :enabled_git_access_protocol, :gravatar_enabled, :default_projects_limit,
...@@ -142,10 +175,33 @@ module API ...@@ -142,10 +175,33 @@ module API
:akismet_enabled, :admin_notification_email, :sentry_enabled, :akismet_enabled, :admin_notification_email, :sentry_enabled,
:repository_checks_enabled, :koding_enabled, :plantuml_enabled, :repository_checks_enabled, :koding_enabled, :plantuml_enabled,
:version_check_enabled, :email_author_in_body, :html_emails_enabled, :version_check_enabled, :email_author_in_body, :html_emails_enabled,
:housekeeping_enabled, :terminal_max_session_time, :polling_interval_multiplier, :housekeeping_enabled, :terminal_max_session_time, :polling_interval_multiplier
# GitLab-EE specific settings
:help_text, :elasticsearch_indexing, :usage_ping_enabled, # EE
:repository_storages, :repository_size_limit at_least_one_of_ee = [
:elasticsearch_indexing,
:help_text,
:repository_size_limit,
:repository_storages,
:usage_ping_enabled
]
optional :help_text, type: String, desc: 'GitLab server administrator information'
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 :elasticsearch_aws, type: Boolean, desc: 'Enable support for AWS hosted elasticsearch'
given elasticsearch_aws: ->(val) { val } do
requires :elasticsearch_aws_region, type: String, desc: 'The AWS region the elasticsearch domain is configured'
optional :elasticsearch_aws_access_key, type: String, desc: 'AWS IAM access key'
optional :elasticsearch_aws_secret_access_key, type: String, desc: 'AWS IAM secret access key'
end
optional :usage_ping_enabled, type: Boolean, desc: 'Every week GitLab will report license usage back to GitLab, Inc.'
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 :repository_size_limit, type: Integer, desc: 'Size limit per repository (MB)'
at_least_one_of(*(at_least_one_of_ce + at_least_one_of_ee))
end end
put "application/settings" do put "application/settings" do
attrs = declared_params(include_missing: false) attrs = declared_params(include_missing: false)
......
...@@ -37,12 +37,16 @@ module API ...@@ -37,12 +37,16 @@ module API
success Entities::UserBasic success Entities::UserBasic
end end
params do params do
# CE
optional :username, type: String, desc: 'Get a single user with a specific username' optional :username, type: String, desc: 'Get a single user with a specific username'
optional :search, type: String, desc: 'Search for a username' optional :search, type: String, desc: 'Search for a username'
optional :active, type: Boolean, default: false, desc: 'Filters only active users' optional :active, type: Boolean, default: false, desc: 'Filters only active users'
optional :external, type: Boolean, default: false, desc: 'Filters only external users' optional :external, type: Boolean, default: false, desc: 'Filters only external users'
optional :blocked, type: Boolean, default: false, desc: 'Filters only blocked users' optional :blocked, type: Boolean, default: false, desc: 'Filters only blocked users'
# EE
optional :skip_ldap, type: Boolean, default: false, desc: 'Skip LDAP users' optional :skip_ldap, type: Boolean, default: false, desc: 'Skip LDAP users'
use :pagination use :pagination
end end
get do get do
......
...@@ -1126,6 +1126,13 @@ describe API::Projects, :api do ...@@ -1126,6 +1126,13 @@ describe API::Projects, :api do
before { project_member3 } before { project_member3 }
before { project_member2 } before { project_member2 }
it 'returns 400 when nothing sent' do
project_param = {}
put api("/projects/#{project.id}", user), project_param
expect(response).to have_http_status(400)
expect(json_response['error']).to match('at least one parameter must be provided')
end
context 'when unauthenticated' do context 'when unauthenticated' do
it 'returns authentication error' do it 'returns authentication error' do
project_param = { name: 'bar' } project_param = { name: 'bar' }
......
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