diff options
Diffstat (limited to 'lib/api')
-rw-r--r-- | lib/api/entities.rb | 4 | ||||
-rw-r--r-- | lib/api/groups.rb | 15 | ||||
-rw-r--r-- | lib/api/helpers.rb | 6 | ||||
-rw-r--r-- | lib/api/helpers/internal_helpers.rb | 16 | ||||
-rw-r--r-- | lib/api/helpers/issues_helpers.rb | 23 | ||||
-rw-r--r-- | lib/api/helpers/projects_helpers.rb | 39 | ||||
-rw-r--r-- | lib/api/internal.rb | 2 | ||||
-rw-r--r-- | lib/api/issues.rb | 27 | ||||
-rw-r--r-- | lib/api/milestone_responses.rb | 2 | ||||
-rw-r--r-- | lib/api/projects.rb | 51 | ||||
-rw-r--r-- | lib/api/protected_branches.rb | 24 | ||||
-rw-r--r-- | lib/api/settings.rb | 36 | ||||
-rw-r--r-- | lib/api/users.rb | 8 | ||||
-rw-r--r-- | lib/api/variables.rb | 8 |
14 files changed, 202 insertions, 59 deletions
diff --git a/lib/api/entities.rb b/lib/api/entities.rb index 611523a2444..0871ea8d21e 100644 --- a/lib/api/entities.rb +++ b/lib/api/entities.rb @@ -275,7 +275,7 @@ module API expose :printing_merge_request_link_enabled expose :merge_method expose :statistics, using: 'API::Entities::ProjectStatistics', if: -> (project, options) { - options[:statistics] && Ability.allowed?(options[:current_user], :download_code, project) + options[:statistics] && Ability.allowed?(options[:current_user], :read_statistics, project) } # rubocop: disable CodeReuse/ActiveRecord @@ -1558,8 +1558,6 @@ module API class Suggestion < Grape::Entity expose :id - expose :from_original_line - expose :to_original_line expose :from_line expose :to_line expose :appliable?, as: :appliable diff --git a/lib/api/groups.rb b/lib/api/groups.rb index cb0d6d96f29..9fcf476f537 100644 --- a/lib/api/groups.rb +++ b/lib/api/groups.rb @@ -20,8 +20,19 @@ module API optional :share_with_group_lock, type: Boolean, desc: 'Prevent sharing a project with another group within this group' end + 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 if Gitlab.ee? end params :statistics_params do @@ -164,6 +175,10 @@ module API optional :name, type: String, desc: 'The name of the group' optional :path, type: String, desc: 'The path of the group' use :optional_params + + 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]) diff --git a/lib/api/helpers.rb b/lib/api/helpers.rb index b8bd180bdc1..8a21d44b4bf 100644 --- a/lib/api/helpers.rb +++ b/lib/api/helpers.rb @@ -302,6 +302,12 @@ module API end # rubocop: enable CodeReuse/ActiveRecord + # rubocop: disable CodeReuse/ActiveRecord + def filter_by_title(items, title) + items.where(title: title) + end + # rubocop: enable CodeReuse/ActiveRecord + def filter_by_search(items, text) items.search(text) end diff --git a/lib/api/helpers/internal_helpers.rb b/lib/api/helpers/internal_helpers.rb index fe78049af87..3fd824877ae 100644 --- a/lib/api/helpers/internal_helpers.rb +++ b/lib/api/helpers/internal_helpers.rb @@ -5,9 +5,11 @@ module API module InternalHelpers attr_reader :redirected_path - def wiki? - set_project unless defined?(@wiki) # rubocop:disable Gitlab/ModuleWithInstanceVariables - @wiki # rubocop:disable Gitlab/ModuleWithInstanceVariables + delegate :wiki?, to: :repo_type + + def repo_type + set_project unless defined?(@repo_type) # rubocop:disable Gitlab/ModuleWithInstanceVariables + @repo_type # rubocop:disable Gitlab/ModuleWithInstanceVariables end def project @@ -67,10 +69,10 @@ module API # rubocop:disable Gitlab/ModuleWithInstanceVariables def set_project if params[:gl_repository] - @project, @wiki = Gitlab::GlRepository.parse(params[:gl_repository]) + @project, @repo_type = Gitlab::GlRepository.parse(params[:gl_repository]) @redirected_path = nil else - @project, @wiki, @redirected_path = Gitlab::RepoPath.parse(params[:project]) + @project, @repo_type, @redirected_path = Gitlab::RepoPath.parse(params[:project]) end end # rubocop:enable Gitlab/ModuleWithInstanceVariables @@ -78,7 +80,7 @@ module API # Project id to pass between components that don't share/don't have # access to the same filesystem mounts def gl_repository - Gitlab::GlRepository.gl_repository(project, wiki?) + repo_type.identifier_for_subject(project) end def gl_project_path @@ -92,7 +94,7 @@ module API # Return the repository depending on whether we want the wiki or the # regular repository def repository - if wiki? + if repo_type.wiki? project.wiki.repository else project.repository diff --git a/lib/api/helpers/issues_helpers.rb b/lib/api/helpers/issues_helpers.rb new file mode 100644 index 00000000000..f6762910b0c --- /dev/null +++ b/lib/api/helpers/issues_helpers.rb @@ -0,0 +1,23 @@ +# 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 diff --git a/lib/api/helpers/projects_helpers.rb b/lib/api/helpers/projects_helpers.rb index e6a72b949f9..7b858dc2e72 100644 --- a/lib/api/helpers/projects_helpers.rb +++ b/lib/api/helpers/projects_helpers.rb @@ -31,11 +31,50 @@ module API optional :initialize_with_readme, type: Boolean, desc: "Initialize a project with a README.md" end + 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 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 diff --git a/lib/api/internal.rb b/lib/api/internal.rb index 7f4a00f1389..cb9aa849eeb 100644 --- a/lib/api/internal.rb +++ b/lib/api/internal.rb @@ -59,7 +59,7 @@ module API actor end - access_checker_klass = wiki? ? Gitlab::GitAccessWiki : Gitlab::GitAccess + access_checker_klass = repo_type.access_checker_class access_checker = access_checker_klass.new(actor, project, protocol, authentication_abilities: ssh_authentication_abilities, namespace_path: namespace_path, project_path: project_path, diff --git a/lib/api/issues.rb b/lib/api/issues.rb index b2ec4ed898e..fae20e45bf9 100644 --- a/lib/api/issues.rb +++ b/lib/api/issues.rb @@ -8,15 +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 - helpers do # rubocop: disable CodeReuse/ActiveRecord def find_issues(args = {}) @@ -33,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' @@ -57,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 @@ -70,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 @@ -219,8 +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, :discussion_locked, - :labels, :created_at, :due_date, :confidential, :state_event + + at_least_one_of(*Helpers::IssuesHelpers.update_params_at_least_one_of) end # rubocop: disable CodeReuse/ActiveRecord put ':id/issues/:issue_iid' do diff --git a/lib/api/milestone_responses.rb b/lib/api/milestone_responses.rb index a0ca39b69d4..62e159ab003 100644 --- a/lib/api/milestone_responses.rb +++ b/lib/api/milestone_responses.rb @@ -16,6 +16,7 @@ module API optional :state, type: String, values: %w[active closed all], default: 'all', desc: 'Return "active", "closed", or "all" milestones' optional :iids, type: Array[Integer], desc: 'The IIDs of the milestones' + optional :title, type: String, desc: 'The title of the milestones' optional :search, type: String, desc: 'The search criteria for the title or description of the milestone' use :pagination end @@ -33,6 +34,7 @@ module API milestones = parent.milestones.order_id_desc milestones = Milestone.filter_by_state(milestones, params[:state]) milestones = filter_by_iid(milestones, params[:iids]) if params[:iids].present? + milestones = filter_by_title(milestones, params[:title]) if params[:title] milestones = filter_by_search(milestones, params[:search]) if params[:search] present paginate(milestones), with: Entities::Milestone diff --git a/lib/api/projects.rb b/lib/api/projects.rb index 91501ba4d36..0f4a47677d9 100644 --- a/lib/api/projects.rb +++ b/lib/api/projects.rb @@ -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,34 +43,6 @@ module API 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 - helpers do params :statistics_params do optional :statistics, type: Boolean, default: false, desc: 'Include project statistics' @@ -97,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 @@ -316,8 +296,9 @@ module API optional :path, type: String, desc: 'The path of the repository' use :optional_project_params + 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 diff --git a/lib/api/protected_branches.rb b/lib/api/protected_branches.rb index 5af43448727..f8cce1ed784 100644 --- a/lib/api/protected_branches.rb +++ b/lib/api/protected_branches.rb @@ -51,6 +51,30 @@ 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)' + + 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 post ':id/protected_branches' do diff --git a/lib/api/settings.rb b/lib/api/settings.rb index 3cb2f69c4ef..d742c6c97c1 100644 --- a/lib/api/settings.rb +++ b/lib/api/settings.rb @@ -135,8 +135,44 @@ 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 + 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_attributes = ::ApplicationSettingsHelper.visible_attributes << :performance_bar_allowed_group_id + if Gitlab.ee? + optional_attributes += EE::ApplicationSettingsHelper.possible_licensed_attributes + end + optional(*optional_attributes) at_least_one_of(*optional_attributes) end diff --git a/lib/api/users.rb b/lib/api/users.rb index a3d4acc63d5..776329622e2 100644 --- a/lib/api/users.rb +++ b/lib/api/users.rb @@ -51,6 +51,10 @@ module API optional :avatar, type: File, desc: 'Avatar image for user' optional :private_profile, type: Boolean, desc: 'Flag indicating the user has a private profile' all_or_none_of :extern_uid, :provider + + if Gitlab.ee? + optional :shared_runners_minutes_limit, type: Integer, desc: 'Pipeline minutes quota for this user' + end end params :sort_params do @@ -80,6 +84,10 @@ module API use :sort_params use :pagination use :with_custom_attributes + + if Gitlab.ee? + optional :skip_ldap, type: Boolean, default: false, desc: 'Skip LDAP users' + end end # rubocop: disable CodeReuse/ActiveRecord get do diff --git a/lib/api/variables.rb b/lib/api/variables.rb index d0d81ebc870..3489ba827e4 100644 --- a/lib/api/variables.rb +++ b/lib/api/variables.rb @@ -55,6 +55,10 @@ module API requires :key, type: String, desc: 'The key of the variable' requires :value, type: String, desc: 'The value of the variable' optional :protected, type: String, desc: 'Whether the variable is protected' + + 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) @@ -76,6 +80,10 @@ module API optional :key, type: String, desc: 'The key of the variable' optional :value, type: String, desc: 'The value of the variable' optional :protected, type: String, desc: 'Whether the variable is protected' + + 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 |