From a7821dd910fd385a66cfe6c840c37c7b11263410 Mon Sep 17 00:00:00 2001 From: Fabio Pitino Date: Fri, 28 Jun 2019 17:27:07 +0100 Subject: Drop feature to take ownership of a trigger token Removing API and frontend interactions that allowed users to take ownership of a trigger token. Removed mentions from the documentation. --- lib/api/triggers.rb | 21 --------------------- 1 file changed, 21 deletions(-) (limited to 'lib/api') diff --git a/lib/api/triggers.rb b/lib/api/triggers.rb index 0e829c5699b..eeecc390256 100644 --- a/lib/api/triggers.rb +++ b/lib/api/triggers.rb @@ -112,27 +112,6 @@ module API end end - desc 'Take ownership of trigger' do - success Entities::Trigger - end - params do - requires :trigger_id, type: Integer, desc: 'The trigger ID' - end - post ':id/triggers/:trigger_id/take_ownership' do - authenticate! - authorize! :admin_build, user_project - - trigger = user_project.triggers.find(params.delete(:trigger_id)) - break not_found!('Trigger') unless trigger - - if trigger.update(owner: current_user) - status :ok - present trigger, with: Entities::Trigger, current_user: current_user - else - render_validation_error!(trigger) - end - end - desc 'Delete a trigger' do success Entities::Trigger end -- cgit v1.2.1 From 4e814c257b74ac78a50f54ec57b1e1c7f78d43b7 Mon Sep 17 00:00:00 2001 From: Gaetan Semet Date: Mon, 15 Jul 2019 14:47:47 +0200 Subject: Multiple pipeline support for Build status This allows user to specify the pipeline ID when several pipelines has been triggered on the same branch and commit. Signed-off-by: Gaetan Semet --- lib/api/commit_statuses.rb | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'lib/api') diff --git a/lib/api/commit_statuses.rb b/lib/api/commit_statuses.rb index 08b4f8db8b0..61cf929bcdc 100644 --- a/lib/api/commit_statuses.rb +++ b/lib/api/commit_statuses.rb @@ -52,6 +52,7 @@ module API optional :name, type: String, desc: 'A string label to differentiate this status from the status of other systems. Default: "default"' optional :context, type: String, desc: 'A string label to differentiate this status from the status of other systems. Default: "default"' optional :coverage, type: Float, desc: 'The total code coverage' + optional :pipeline_id, type: Integer, desc: 'An existing pipeline id, when multiple pipelines on the same commit sha have been triggered' end # rubocop: disable CodeReuse/ActiveRecord post ':id/statuses/:sha' do @@ -72,8 +73,12 @@ module API not_found! 'References for commit' unless ref name = params[:name] || params[:context] || 'default' + pipeline = if params[:pipeline_id] + @project.ci_pipelines.find_by(id: params[:pipeline_id]) + else + @project.pipeline_for(ref, commit.sha) + end - pipeline = @project.pipeline_for(ref, commit.sha) unless pipeline pipeline = @project.ci_pipelines.create!( source: :external, -- cgit v1.2.1 From bcd2458076512ad80c6e470d9434618f27dfec3c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Francisco=20Javier=20L=C3=B3pez?= Date: Wed, 17 Jul 2019 23:45:35 +0000 Subject: Refactor RedisCounter and WebIdeCommitsCounter This MR refactor RedisCounter and WebIdeCommitsCounter to be reused by other components. --- lib/api/commits.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/api') diff --git a/lib/api/commits.rb b/lib/api/commits.rb index c414ad75d9d..fe910d46f6c 100644 --- a/lib/api/commits.rb +++ b/lib/api/commits.rb @@ -126,7 +126,7 @@ module API if result[:status] == :success commit_detail = user_project.repository.commit(result[:result]) - Gitlab::UsageDataCounters::WebIdeCommitsCounter.increment if find_user_from_warden + Gitlab::UsageDataCounters::WebIdeCounter.increment_commits_count if find_user_from_warden present commit_detail, with: Entities::CommitDetail, stats: params[:stats] else -- cgit v1.2.1 From f8cecafb07792bcaf9d7ffa85766c3b33c1dd252 Mon Sep 17 00:00:00 2001 From: Markus Koller Date: Thu, 13 Jun 2019 12:44:41 +0200 Subject: Add start_sha to commits API When passing start_branch on committing from the WebIDE, it's possible that the branch has changed since editing started, which results in the change being applied on top of the latest commit in the branch and overwriting the new changes. By passing the start_sha instead we can make sure that the change is applied on top of the commit which the user started editing from. --- lib/api/commits.rb | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) (limited to 'lib/api') diff --git a/lib/api/commits.rb b/lib/api/commits.rb index c414ad75d9d..0aeb9584641 100644 --- a/lib/api/commits.rb +++ b/lib/api/commits.rb @@ -76,7 +76,7 @@ module API detail 'This feature was introduced in GitLab 8.13' end params do - requires :branch, type: String, desc: 'Name of the branch to commit into. To create a new branch, also provide `start_branch`.', allow_blank: false + requires :branch, type: String, desc: 'Name of the branch to commit into. To create a new branch, also provide either `start_branch` or `start_sha`, and optionally `start_project`.', allow_blank: false requires :commit_message, type: String, desc: 'Commit message' requires :actions, type: Array, desc: 'Actions to perform in commit' do requires :action, type: String, desc: 'The action to perform, `create`, `delete`, `move`, `update`, `chmod`', values: %w[create update move delete chmod].freeze @@ -98,12 +98,16 @@ module API requires :execute_filemode, type: Boolean, desc: 'When `true/false` enables/disables the execute flag on the file.' end end - optional :start_branch, type: String, desc: 'Name of the branch to start the new commit from' - optional :start_project, types: [Integer, String], desc: 'The ID or path of the project to start the commit from' + + optional :start_branch, type: String, desc: 'Name of the branch to start the new branch from' + optional :start_sha, type: String, desc: 'SHA of the commit to start the new branch from' + mutually_exclusive :start_branch, :start_sha + + optional :start_project, types: [Integer, String], desc: 'The ID or path of the project to start the new branch from' optional :author_email, type: String, desc: 'Author email for commit' optional :author_name, type: String, desc: 'Author name for commit' optional :stats, type: Boolean, default: true, desc: 'Include commit stats' - optional :force, type: Boolean, default: false, desc: 'When `true` overwrites the target branch with a new commit based on the `start_branch`' + optional :force, type: Boolean, default: false, desc: 'When `true` overwrites the target branch with a new commit based on the `start_branch` or `start_sha`' end post ':id/repository/commits' do if params[:start_project] @@ -118,7 +122,7 @@ module API attrs = declared_params attrs[:branch_name] = attrs.delete(:branch) - attrs[:start_branch] ||= attrs[:branch_name] + attrs[:start_branch] ||= attrs[:branch_name] unless attrs[:start_sha] attrs[:start_project] = start_project if start_project result = ::Files::MultiService.new(user_project, current_user, attrs).execute -- cgit v1.2.1 From 0f585d0de89cfee5054e002fe6421c38b3f8e8ce Mon Sep 17 00:00:00 2001 From: Mathieu Parent Date: Thu, 18 Jul 2019 10:13:15 +0200 Subject: API: Allow changing only ci_default_git_depth --- lib/api/helpers/projects_helpers.rb | 1 + 1 file changed, 1 insertion(+) (limited to 'lib/api') diff --git a/lib/api/helpers/projects_helpers.rb b/lib/api/helpers/projects_helpers.rb index 833e3b9ebaf..51b7cf05c8f 100644 --- a/lib/api/helpers/projects_helpers.rb +++ b/lib/api/helpers/projects_helpers.rb @@ -71,6 +71,7 @@ module API :build_timeout, :builds_access_level, :ci_config_path, + :ci_default_git_depth, :container_registry_enabled, :default_branch, :description, -- cgit v1.2.1 From 41b8dca877ba790cd56677dc6405e16b631f9854 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matija=20=C4=8Cupi=C4=87?= Date: Wed, 17 Jul 2019 01:36:49 +0200 Subject: Add specs for specifying pipeline behavior Adds specs for testing the new behavior of specifying a pipeline when POSTing a status. --- lib/api/commit_statuses.rb | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) (limited to 'lib/api') diff --git a/lib/api/commit_statuses.rb b/lib/api/commit_statuses.rb index 61cf929bcdc..d58a5e214ed 100644 --- a/lib/api/commit_statuses.rb +++ b/lib/api/commit_statuses.rb @@ -52,7 +52,7 @@ module API optional :name, type: String, desc: 'A string label to differentiate this status from the status of other systems. Default: "default"' optional :context, type: String, desc: 'A string label to differentiate this status from the status of other systems. Default: "default"' optional :coverage, type: Float, desc: 'The total code coverage' - optional :pipeline_id, type: Integer, desc: 'An existing pipeline id, when multiple pipelines on the same commit sha have been triggered' + optional :pipeline_id, type: Integer, desc: 'An existing pipeline ID, when multiple pipelines on the same commit SHA have been triggered' end # rubocop: disable CodeReuse/ActiveRecord post ':id/statuses/:sha' do @@ -73,11 +73,8 @@ module API not_found! 'References for commit' unless ref name = params[:name] || params[:context] || 'default' - pipeline = if params[:pipeline_id] - @project.ci_pipelines.find_by(id: params[:pipeline_id]) - else - @project.pipeline_for(ref, commit.sha) - end + + pipeline = @project.pipeline_for(ref, commit.sha, params[:pipeline_id]) unless pipeline pipeline = @project.ci_pipelines.create!( -- cgit v1.2.1 From 4aa76dddecc048cef24963323afe59f1c120cb72 Mon Sep 17 00:00:00 2001 From: Nick Thomas Date: Thu, 13 Jun 2019 14:12:28 +0100 Subject: Remove dead MySQL code None of this code can be reached any more, so it can all be removed --- lib/api/entities.rb | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) (limited to 'lib/api') diff --git a/lib/api/entities.rb b/lib/api/entities.rb index 494da770279..10b4f8934d7 100644 --- a/lib/api/entities.rb +++ b/lib/api/entities.rb @@ -1052,15 +1052,8 @@ module API # rubocop: disable CodeReuse/ActiveRecord def self.preload_relation(projects_relation, options = {}) relation = super(projects_relation, options) - - # MySQL doesn't support LIMIT inside an IN subquery - if Gitlab::Database.mysql? - project_ids = relation.pluck('projects.id') - namespace_ids = relation.pluck(:namespace_id) - else - project_ids = relation.select('projects.id') - namespace_ids = relation.select(:namespace_id) - end + project_ids = relation.select('projects.id') + namespace_ids = relation.select(:namespace_id) options[:project_members] = options[:current_user] .project_members -- cgit v1.2.1 From 1ce5bcacdbf56682e05fa63875203bf4d10584bc Mon Sep 17 00:00:00 2001 From: Heinrich Lee Yu Date: Wed, 24 Jul 2019 17:20:54 +0800 Subject: Remove code related to object hierarchy in MySQL These are not required because MySQL is not supported anymore --- lib/api/entities.rb | 5 +---- lib/api/groups.rb | 5 +---- 2 files changed, 2 insertions(+), 8 deletions(-) (limited to 'lib/api') diff --git a/lib/api/entities.rb b/lib/api/entities.rb index 10b4f8934d7..2e78331df6c 100644 --- a/lib/api/entities.rb +++ b/lib/api/entities.rb @@ -366,10 +366,7 @@ module API end expose :request_access_enabled expose :full_name, :full_path - - if ::Group.supports_nested_objects? - expose :parent_id - end + expose :parent_id expose :custom_attributes, using: 'API::Entities::CustomAttribute', if: :with_custom_attributes diff --git a/lib/api/groups.rb b/lib/api/groups.rb index ec1020c7c78..f545f33c06b 100644 --- a/lib/api/groups.rb +++ b/lib/api/groups.rb @@ -114,10 +114,7 @@ module API params do requires :name, type: String, desc: 'The name of the group' requires :path, type: String, desc: 'The path of the group' - - if ::Group.supports_nested_objects? - optional :parent_id, type: Integer, desc: 'The parent group id for creating nested group' - end + optional :parent_id, type: Integer, desc: 'The parent group id for creating nested group' use :optional_params end -- cgit v1.2.1 From 38ab1ae2f200e2071ea7329e106beb1b9232f44c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matija=20=C4=8Cupi=C4=87?= Date: Tue, 23 Jul 2019 21:29:12 +0200 Subject: Rename latest_successful to be more explicit * Reword Project#latest_successful_build_for to Project#latest_successful_build_for_ref * Reword Ci::Pipeline#latest_successful_for to Ci::Pipeline#latest_successful_build_for_ref --- lib/api/job_artifacts.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'lib/api') diff --git a/lib/api/job_artifacts.rb b/lib/api/job_artifacts.rb index e7fed55170e..b35aa952f81 100644 --- a/lib/api/job_artifacts.rb +++ b/lib/api/job_artifacts.rb @@ -27,7 +27,7 @@ module API requirements: { ref_name: /.+/ } do authorize_download_artifacts! - latest_build = user_project.latest_successful_build_for!(params[:job], params[:ref_name]) + latest_build = user_project.latest_successful_build_for_ref!(params[:job], params[:ref_name]) present_carrierwave_file!(latest_build.artifacts_file) end @@ -45,7 +45,7 @@ module API requirements: { ref_name: /.+/ } do authorize_download_artifacts! - build = user_project.latest_successful_build_for!(params[:job], params[:ref_name]) + build = user_project.latest_successful_build_for_ref!(params[:job], params[:ref_name]) path = Gitlab::Ci::Build::Artifacts::Path .new(params[:artifact_path]) -- cgit v1.2.1 From 6cfd13726fbce725633d95140dd0e4bf1779c5db Mon Sep 17 00:00:00 2001 From: manojmj Date: Wed, 24 Jul 2019 19:45:50 +0530 Subject: CE: Add project download & project export audit event This change adds audit events for download of repository and export of project. --- lib/api/helpers.rb | 4 ++++ lib/api/helpers/runner.rb | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) (limited to 'lib/api') diff --git a/lib/api/helpers.rb b/lib/api/helpers.rb index 8ae42c6dadd..1aa6dc44bf7 100644 --- a/lib/api/helpers.rb +++ b/lib/api/helpers.rb @@ -544,5 +544,9 @@ module API params[:archived] end + + def ip_address + env["action_dispatch.remote_ip"].to_s || request.ip + end end end diff --git a/lib/api/helpers/runner.rb b/lib/api/helpers/runner.rb index 100463fcb95..5b87eccf860 100644 --- a/lib/api/helpers/runner.rb +++ b/lib/api/helpers/runner.rb @@ -25,7 +25,7 @@ module API end def get_runner_ip - { ip_address: env["action_dispatch.remote_ip"].to_s || request.ip } + { ip_address: ip_address } end def current_runner -- cgit v1.2.1 From 8136fac26c8f470720ff90d152b93abf50f5084d Mon Sep 17 00:00:00 2001 From: Peter Leitzen Date: Fri, 26 Jul 2019 10:44:13 +0000 Subject: Prefer `flat_map` over `map` + `flatten` Convert several occurrences of `map` + `flatten` to `flat_map` where applicable. --- lib/api/validations/types/labels_list.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/api') diff --git a/lib/api/validations/types/labels_list.rb b/lib/api/validations/types/labels_list.rb index 47cd83c29cf..60277b99106 100644 --- a/lib/api/validations/types/labels_list.rb +++ b/lib/api/validations/types/labels_list.rb @@ -10,7 +10,7 @@ module API when String value.split(',').map(&:strip) when Array - value.map { |v| v.to_s.split(',').map(&:strip) }.flatten + value.flat_map { |v| v.to_s.split(',').map(&:strip) } when LabelsList value else -- cgit v1.2.1 From 5a8eaef42e771e9de6f6cbce715877352807f53c Mon Sep 17 00:00:00 2001 From: Oleg Zubchenko Date: Thu, 4 Jul 2019 14:59:10 +0300 Subject: Add git blame api --- lib/api/entities.rb | 13 +++++++++++++ lib/api/files.rb | 25 +++++++++++++++++++++++++ 2 files changed, 38 insertions(+) (limited to 'lib/api') diff --git a/lib/api/entities.rb b/lib/api/entities.rb index 0a9515f1dd2..2b1176871fe 100644 --- a/lib/api/entities.rb +++ b/lib/api/entities.rb @@ -2,6 +2,19 @@ module API module Entities + class BlameRangeCommit < Grape::Entity + expose :id + expose :parent_ids + expose :message + expose :authored_date, :author_name, :author_email + expose :committed_date, :committer_name, :committer_email + end + + class BlameRange < Grape::Entity + expose :commit, using: BlameRangeCommit + expose :lines + end + class WikiPageBasic < Grape::Entity expose :format expose :slug diff --git a/lib/api/files.rb b/lib/api/files.rb index ca59d330e1c..0b438fb5bbc 100644 --- a/lib/api/files.rb +++ b/lib/api/files.rb @@ -83,6 +83,31 @@ module API resource :projects, requirements: FILE_ENDPOINT_REQUIREMENTS do allow_access_with_scope :read_repository, if: -> (request) { request.get? || request.head? } + desc 'Get blame file metadata from repository' + params do + requires :file_path, type: String, desc: 'The url encoded path to the file. Ex. lib%2Fclass%2Erb' + requires :ref, type: String, desc: 'The name of branch, tag or commit', allow_blank: false + end + head ":id/repository/files/:file_path/blame", requirements: FILE_ENDPOINT_REQUIREMENTS do + assign_file_vars! + + set_http_headers(blob_data) + end + + desc 'Get blame file from the repository' + params do + requires :file_path, type: String, desc: 'The url encoded path to the file. Ex. lib%2Fclass%2Erb' + requires :ref, type: String, desc: 'The name of branch, tag or commit', allow_blank: false + end + get ":id/repository/files/:file_path/blame", requirements: FILE_ENDPOINT_REQUIREMENTS do + assign_file_vars! + + set_http_headers(blob_data) + + blame_ranges = Gitlab::Blame.new(@blob, @commit).groups(highlight: false) + present blame_ranges, with: Entities::BlameRange + end + desc 'Get raw file metadata from repository' params do requires :file_path, type: String, desc: 'The url encoded path to the file. Ex. lib%2Fclass%2Erb' -- cgit v1.2.1 From e20538088bba75fa3193004b8695d4ffab7aca21 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20Louz=C3=A1n?= Date: Tue, 30 Jul 2019 17:03:17 +0000 Subject: Add support page link in help menu Creates a new item in help dropdown to show configured support page link --- lib/api/settings.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/api') diff --git a/lib/api/settings.rb b/lib/api/settings.rb index 4275d911708..aa9e879160d 100644 --- a/lib/api/settings.rb +++ b/lib/api/settings.rb @@ -59,7 +59,7 @@ module API optional :grafana_url, type: String, desc: 'Grafana URL' optional :gravatar_enabled, type: Boolean, desc: 'Flag indicating if the Gravatar service is enabled' optional :help_page_hide_commercial_content, type: Boolean, desc: 'Hide marketing-related entries from help' - optional :help_page_support_url, type: String, desc: 'Alternate support URL for help page' + optional :help_page_support_url, type: String, desc: 'Alternate support URL for help page and help dropdown' optional :help_page_text, type: String, desc: 'Custom text displayed on the help page' optional :home_page_url, type: String, desc: 'We will redirect non-logged in users to this page' optional :housekeeping_enabled, type: Boolean, desc: 'Enable automatic repository housekeeping (git repack, git gc)' -- cgit v1.2.1 From 0e99daae4afdb90d74c4b0bfe5cb3e482bbb422e Mon Sep 17 00:00:00 2001 From: Patrick Derichs Date: Tue, 30 Jul 2019 20:25:49 +0200 Subject: Use NotesFinder in IssuableActions module Remove project from NotesFinder constructor Add project parameter to specs Also look for methods in private scope Fix specs to match new NotesFinder constructor --- lib/api/helpers/notes_helpers.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/api') diff --git a/lib/api/helpers/notes_helpers.rb b/lib/api/helpers/notes_helpers.rb index b03ac7deb71..7124ac0c5c3 100644 --- a/lib/api/helpers/notes_helpers.rb +++ b/lib/api/helpers/notes_helpers.rb @@ -76,7 +76,7 @@ module API def find_noteable(parent_type, parent_id, noteable_type, noteable_id) params = params_by_noteable_type_and_id(noteable_type, noteable_id) - noteable = NotesFinder.new(user_project, current_user, params).target + noteable = NotesFinder.new(current_user, params.merge(project: user_project)).target noteable = nil unless can?(current_user, noteable_read_ability_name(noteable), noteable) noteable || not_found!(noteable_type) end -- cgit v1.2.1 From 5e3a208f58a7a887370888055da180f64b3692a3 Mon Sep 17 00:00:00 2001 From: George Koltsov Date: Thu, 1 Aug 2019 14:22:54 +0100 Subject: Add backwards compatibility for legacy setting `allow_local_requests_for_hooks_and_services` was renamed to `allow_local_requests_for_web_hooks_and_services`. --- lib/api/entities.rb | 2 ++ lib/api/settings.rb | 6 ++++++ 2 files changed, 8 insertions(+) (limited to 'lib/api') diff --git a/lib/api/entities.rb b/lib/api/entities.rb index 2d6dd18d4ea..2f5ce3d4003 100644 --- a/lib/api/entities.rb +++ b/lib/api/entities.rb @@ -1162,6 +1162,7 @@ module API attributes = ::ApplicationSettingsHelper.visible_attributes attributes.delete(:performance_bar_allowed_group_path) attributes.delete(:performance_bar_enabled) + attributes.delete(:allow_local_requests_from_hooks_and_services) attributes end @@ -1180,6 +1181,7 @@ module API # support legacy names, can be removed in v5 expose :password_authentication_enabled_for_web, as: :password_authentication_enabled expose :password_authentication_enabled_for_web, as: :signin_enabled + expose :allow_local_requests_from_web_hooks_and_services, as: :allow_local_requests_from_hooks_and_services end # deprecated old Release representation diff --git a/lib/api/settings.rb b/lib/api/settings.rb index aa9e879160d..196ef1fcdfa 100644 --- a/lib/api/settings.rb +++ b/lib/api/settings.rb @@ -124,6 +124,7 @@ module API optional :usage_ping_enabled, type: Boolean, desc: 'Every week GitLab will report license usage back to GitLab, Inc.' optional :instance_statistics_visibility_private, type: Boolean, desc: 'When set to `true` Instance statistics will only be available to admins' optional :local_markdown_version, type: Integer, desc: "Local markdown version, increase this value when any cached markdown should be invalidated" + optional :allow_local_requests_from_hooks_and_services, type: Boolean, desc: 'Deprecated: Use :allow_local_requests_from_web_hooks_and_services instead. Allow requests to the local network from hooks and services.' # support legacy names, can be removed in v5 ApplicationSetting::SUPPORTED_KEY_TYPES.each do |type| optional :"#{type}_key_restriction", @@ -158,6 +159,11 @@ module API attrs[:password_authentication_enabled_for_web] = attrs.delete(:password_authentication_enabled) end + # support legacy names, can be removed in v5 + if attrs.has_key?(:allow_local_requests_from_hooks_and_services) + attrs[:allow_local_requests_from_web_hooks_and_services] = attrs.delete(:allow_local_requests_from_hooks_and_services) + end + attrs = filter_attributes_using_license(attrs) if ApplicationSettings::UpdateService.new(current_settings, current_user, attrs).execute -- cgit v1.2.1 From c69a47049c62f3b6b8b4f426ee498690bc45d3e6 Mon Sep 17 00:00:00 2001 From: Patrick Derichs Date: Fri, 2 Aug 2019 10:55:03 +0200 Subject: Use NotesFinder#target to find Epics --- lib/api/helpers/notes_helpers.rb | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'lib/api') diff --git a/lib/api/helpers/notes_helpers.rb b/lib/api/helpers/notes_helpers.rb index 7124ac0c5c3..6bf9057fad7 100644 --- a/lib/api/helpers/notes_helpers.rb +++ b/lib/api/helpers/notes_helpers.rb @@ -74,14 +74,14 @@ module API end def find_noteable(parent_type, parent_id, noteable_type, noteable_id) - params = params_by_noteable_type_and_id(noteable_type, noteable_id) + params = finder_params_by_noteable_type_and_id(noteable_type, noteable_id, parent_id) - noteable = NotesFinder.new(current_user, params.merge(project: user_project)).target + noteable = NotesFinder.new(current_user, params).target noteable = nil unless can?(current_user, noteable_read_ability_name(noteable), noteable) noteable || not_found!(noteable_type) end - def params_by_noteable_type_and_id(type, id) + def finder_params_by_noteable_type_and_id(type, id, parent_id) target_type = type.name.underscore { target_type: target_type }.tap do |h| if %w(issue merge_request).include?(target_type) @@ -89,9 +89,15 @@ module API else h[:target_id] = id end + + add_parent_to_finder_params(h, type, parent_id) end end + def add_parent_to_finder_params(finder_params, noteable_type, parent_id) + finder_params[:project] = user_project + end + def noteable_parent(noteable) public_send("user_#{noteable.class.parent_class.to_s.underscore}") # rubocop:disable GitlabSecurity/PublicSend end -- cgit v1.2.1 From 3dbf3997bbf51eca8a313c4e152c77c1b038fd5d Mon Sep 17 00:00:00 2001 From: Steve Abrams Date: Mon, 5 Aug 2019 20:00:50 +0000 Subject: Add group level container repository endpoints API endpoints for requesting container repositories and container repositories with their tag information are enabled for users that want to specify the group containing the repository rather than the specific project. --- lib/api/api.rb | 3 +- lib/api/container_registry.rb | 149 ----------------------------- lib/api/entities/container_registry.rb | 10 +- lib/api/group_container_repositories.rb | 39 ++++++++ lib/api/project_container_repositories.rb | 152 ++++++++++++++++++++++++++++++ 5 files changed, 199 insertions(+), 154 deletions(-) delete mode 100644 lib/api/container_registry.rb create mode 100644 lib/api/group_container_repositories.rb create mode 100644 lib/api/project_container_repositories.rb (limited to 'lib/api') diff --git a/lib/api/api.rb b/lib/api/api.rb index 223ae13bd2d..e500a93b31e 100644 --- a/lib/api/api.rb +++ b/lib/api/api.rb @@ -104,7 +104,6 @@ module API mount ::API::BroadcastMessages mount ::API::Commits mount ::API::CommitStatuses - mount ::API::ContainerRegistry mount ::API::DeployKeys mount ::API::Deployments mount ::API::Environments @@ -116,6 +115,7 @@ module API mount ::API::GroupLabels mount ::API::GroupMilestones mount ::API::Groups + mount ::API::GroupContainerRepositories mount ::API::GroupVariables mount ::API::ImportGithub mount ::API::Internal @@ -138,6 +138,7 @@ module API mount ::API::Pipelines mount ::API::PipelineSchedules mount ::API::ProjectClusters + mount ::API::ProjectContainerRepositories mount ::API::ProjectEvents mount ::API::ProjectExport mount ::API::ProjectImport diff --git a/lib/api/container_registry.rb b/lib/api/container_registry.rb deleted file mode 100644 index 7dad20a822a..00000000000 --- a/lib/api/container_registry.rb +++ /dev/null @@ -1,149 +0,0 @@ -# frozen_string_literal: true - -module API - class ContainerRegistry < Grape::API - include PaginationParams - - REGISTRY_ENDPOINT_REQUIREMENTS = API::NAMESPACE_OR_PROJECT_REQUIREMENTS.merge( - tag_name: API::NO_SLASH_URL_PART_REGEX) - - before { error!('404 Not Found', 404) unless Feature.enabled?(:container_registry_api, user_project, default_enabled: true) } - before { authorize_read_container_images! } - - params do - requires :id, type: String, desc: 'The ID of a project' - end - resource :projects, requirements: API::NAMESPACE_OR_PROJECT_REQUIREMENTS do - desc 'Get a project container repositories' do - detail 'This feature was introduced in GitLab 11.8.' - success Entities::ContainerRegistry::Repository - end - params do - use :pagination - end - get ':id/registry/repositories' do - repositories = user_project.container_repositories.ordered - - present paginate(repositories), with: Entities::ContainerRegistry::Repository - end - - desc 'Delete repository' do - detail 'This feature was introduced in GitLab 11.8.' - end - params do - requires :repository_id, type: Integer, desc: 'The ID of the repository' - end - delete ':id/registry/repositories/:repository_id', requirements: REGISTRY_ENDPOINT_REQUIREMENTS do - authorize_admin_container_image! - - DeleteContainerRepositoryWorker.perform_async(current_user.id, repository.id) - - status :accepted - end - - desc 'Get a list of repositories tags' do - detail 'This feature was introduced in GitLab 11.8.' - success Entities::ContainerRegistry::Tag - end - params do - requires :repository_id, type: Integer, desc: 'The ID of the repository' - use :pagination - end - get ':id/registry/repositories/:repository_id/tags', requirements: REGISTRY_ENDPOINT_REQUIREMENTS do - authorize_read_container_image! - - tags = Kaminari.paginate_array(repository.tags) - present paginate(tags), with: Entities::ContainerRegistry::Tag - end - - desc 'Delete repository tags (in bulk)' do - detail 'This feature was introduced in GitLab 11.8.' - end - params do - requires :repository_id, type: Integer, desc: 'The ID of the repository' - requires :name_regex, type: String, desc: 'The tag name regexp to delete, specify .* to delete all' - optional :keep_n, type: Integer, desc: 'Keep n of latest tags with matching name' - optional :older_than, type: String, desc: 'Delete older than: 1h, 1d, 1month' - end - delete ':id/registry/repositories/:repository_id/tags', requirements: REGISTRY_ENDPOINT_REQUIREMENTS do - authorize_admin_container_image! - - message = 'This request has already been made. You can run this at most once an hour for a given container repository' - render_api_error!(message, 400) unless obtain_new_cleanup_container_lease - - CleanupContainerRepositoryWorker.perform_async(current_user.id, repository.id, - declared_params.except(:repository_id)) # rubocop: disable CodeReuse/ActiveRecord - - status :accepted - end - - desc 'Get a details about repository tag' do - detail 'This feature was introduced in GitLab 11.8.' - success Entities::ContainerRegistry::TagDetails - end - params do - requires :repository_id, type: Integer, desc: 'The ID of the repository' - requires :tag_name, type: String, desc: 'The name of the tag' - end - get ':id/registry/repositories/:repository_id/tags/:tag_name', requirements: REGISTRY_ENDPOINT_REQUIREMENTS do - authorize_read_container_image! - validate_tag! - - present tag, with: Entities::ContainerRegistry::TagDetails - end - - desc 'Delete repository tag' do - detail 'This feature was introduced in GitLab 11.8.' - end - params do - requires :repository_id, type: Integer, desc: 'The ID of the repository' - requires :tag_name, type: String, desc: 'The name of the tag' - end - delete ':id/registry/repositories/:repository_id/tags/:tag_name', requirements: REGISTRY_ENDPOINT_REQUIREMENTS do - authorize_destroy_container_image! - validate_tag! - - tag.delete - - status :ok - end - end - - helpers do - def authorize_read_container_images! - authorize! :read_container_image, user_project - end - - def authorize_read_container_image! - authorize! :read_container_image, repository - end - - def authorize_destroy_container_image! - authorize! :destroy_container_image, repository - end - - def authorize_admin_container_image! - authorize! :admin_container_image, repository - end - - def obtain_new_cleanup_container_lease - Gitlab::ExclusiveLease - .new("container_repository:cleanup_tags:#{repository.id}", - timeout: 1.hour) - .try_obtain - end - - def repository - @repository ||= user_project.container_repositories.find(params[:repository_id]) - end - - def tag - @tag ||= repository.tag(params[:tag_name]) - end - - def validate_tag! - not_found!('Tag') unless tag.valid? - end - end - end -end diff --git a/lib/api/entities/container_registry.rb b/lib/api/entities/container_registry.rb index 00833ca7480..6250f35c7cb 100644 --- a/lib/api/entities/container_registry.rb +++ b/lib/api/entities/container_registry.rb @@ -3,18 +3,20 @@ module API module Entities module ContainerRegistry - class Repository < Grape::Entity - expose :id + class Tag < Grape::Entity expose :name expose :path expose :location - expose :created_at end - class Tag < Grape::Entity + class Repository < Grape::Entity + expose :id expose :name expose :path + expose :project_id expose :location + expose :created_at + expose :tags, using: Tag, if: -> (_, options) { options[:tags] } end class TagDetails < Tag diff --git a/lib/api/group_container_repositories.rb b/lib/api/group_container_repositories.rb new file mode 100644 index 00000000000..fd24662cc9a --- /dev/null +++ b/lib/api/group_container_repositories.rb @@ -0,0 +1,39 @@ +# frozen_string_literal: true + +module API + class GroupContainerRepositories < Grape::API + include PaginationParams + + before { authorize_read_group_container_images! } + + REPOSITORY_ENDPOINT_REQUIREMENTS = API::NAMESPACE_OR_PROJECT_REQUIREMENTS.merge( + tag_name: API::NO_SLASH_URL_PART_REGEX) + + params do + requires :id, type: String, desc: "Group's ID or path" + end + resource :groups, requirements: API::NAMESPACE_OR_PROJECT_REQUIREMENTS do + desc 'Get a list of all repositories within a group' do + detail 'This feature was introduced in GitLab 12.2.' + success Entities::ContainerRegistry::Repository + end + params do + use :pagination + optional :tags, type: Boolean, default: false, desc: 'Determines if tags should be included' + end + get ':id/registry/repositories' do + repositories = ContainerRepositoriesFinder.new( + id: user_group.id, container_type: :group + ).execute + + present paginate(repositories), with: Entities::ContainerRegistry::Repository, tags: params[:tags] + end + end + + helpers do + def authorize_read_group_container_images! + authorize! :read_container_image, user_group + end + end + end +end diff --git a/lib/api/project_container_repositories.rb b/lib/api/project_container_repositories.rb new file mode 100644 index 00000000000..6d53abcc500 --- /dev/null +++ b/lib/api/project_container_repositories.rb @@ -0,0 +1,152 @@ +# frozen_string_literal: true + +module API + class ProjectContainerRepositories < Grape::API + include PaginationParams + + REPOSITORY_ENDPOINT_REQUIREMENTS = API::NAMESPACE_OR_PROJECT_REQUIREMENTS.merge( + tag_name: API::NO_SLASH_URL_PART_REGEX) + + before { error!('404 Not Found', 404) unless Feature.enabled?(:container_registry_api, user_project, default_enabled: true) } + before { authorize_read_container_images! } + + params do + requires :id, type: String, desc: 'The ID of a project' + end + resource :projects, requirements: API::NAMESPACE_OR_PROJECT_REQUIREMENTS do + desc 'Get a project container repositories' do + detail 'This feature was introduced in GitLab 11.8.' + success Entities::ContainerRegistry::Repository + end + params do + use :pagination + optional :tags, type: Boolean, default: false, desc: 'Determines if tags should be included' + end + get ':id/registry/repositories' do + repositories = ContainerRepositoriesFinder.new( + id: user_project.id, container_type: :project + ).execute + + present paginate(repositories), with: Entities::ContainerRegistry::Repository, tags: params[:tags] + end + + desc 'Delete repository' do + detail 'This feature was introduced in GitLab 11.8.' + end + params do + requires :repository_id, type: Integer, desc: 'The ID of the repository' + end + delete ':id/registry/repositories/:repository_id', requirements: REPOSITORY_ENDPOINT_REQUIREMENTS do + authorize_admin_container_image! + + DeleteContainerRepositoryWorker.perform_async(current_user.id, repository.id) + + status :accepted + end + + desc 'Get a list of repositories tags' do + detail 'This feature was introduced in GitLab 11.8.' + success Entities::ContainerRegistry::Tag + end + params do + requires :repository_id, type: Integer, desc: 'The ID of the repository' + use :pagination + end + get ':id/registry/repositories/:repository_id/tags', requirements: REPOSITORY_ENDPOINT_REQUIREMENTS do + authorize_read_container_image! + + tags = Kaminari.paginate_array(repository.tags) + present paginate(tags), with: Entities::ContainerRegistry::Tag + end + + desc 'Delete repository tags (in bulk)' do + detail 'This feature was introduced in GitLab 11.8.' + end + params do + requires :repository_id, type: Integer, desc: 'The ID of the repository' + requires :name_regex, type: String, desc: 'The tag name regexp to delete, specify .* to delete all' + optional :keep_n, type: Integer, desc: 'Keep n of latest tags with matching name' + optional :older_than, type: String, desc: 'Delete older than: 1h, 1d, 1month' + end + delete ':id/registry/repositories/:repository_id/tags', requirements: REPOSITORY_ENDPOINT_REQUIREMENTS do + authorize_admin_container_image! + + message = 'This request has already been made. You can run this at most once an hour for a given container repository' + render_api_error!(message, 400) unless obtain_new_cleanup_container_lease + + CleanupContainerRepositoryWorker.perform_async(current_user.id, repository.id, + declared_params.except(:repository_id)) # rubocop: disable CodeReuse/ActiveRecord + + status :accepted + end + + desc 'Get a details about repository tag' do + detail 'This feature was introduced in GitLab 11.8.' + success Entities::ContainerRegistry::TagDetails + end + params do + requires :repository_id, type: Integer, desc: 'The ID of the repository' + requires :tag_name, type: String, desc: 'The name of the tag' + end + get ':id/registry/repositories/:repository_id/tags/:tag_name', requirements: REPOSITORY_ENDPOINT_REQUIREMENTS do + authorize_read_container_image! + validate_tag! + + present tag, with: Entities::ContainerRegistry::TagDetails + end + + desc 'Delete repository tag' do + detail 'This feature was introduced in GitLab 11.8.' + end + params do + requires :repository_id, type: Integer, desc: 'The ID of the repository' + requires :tag_name, type: String, desc: 'The name of the tag' + end + delete ':id/registry/repositories/:repository_id/tags/:tag_name', requirements: REPOSITORY_ENDPOINT_REQUIREMENTS do + authorize_destroy_container_image! + validate_tag! + + tag.delete + + status :ok + end + end + + helpers do + def authorize_read_container_images! + authorize! :read_container_image, user_project + end + + def authorize_read_container_image! + authorize! :read_container_image, repository + end + + def authorize_destroy_container_image! + authorize! :destroy_container_image, repository + end + + def authorize_admin_container_image! + authorize! :admin_container_image, repository + end + + def obtain_new_cleanup_container_lease + Gitlab::ExclusiveLease + .new("container_repository:cleanup_tags:#{repository.id}", + timeout: 1.hour) + .try_obtain + end + + def repository + @repository ||= user_project.container_repositories.find(params[:repository_id]) + end + + def tag + @tag ||= repository.tag(params[:tag_name]) + end + + def validate_tag! + not_found!('Tag') unless tag.valid? + end + end + end +end -- cgit v1.2.1 From 5b20df0a9276bc1250dc8b307adb161b24d9c255 Mon Sep 17 00:00:00 2001 From: Camil Staps Date: Fri, 25 Jan 2019 18:34:45 +0100 Subject: Add projects/:id/starrers API endpoint for users who starred a repository --- lib/api/projects.rb | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'lib/api') diff --git a/lib/api/projects.rb b/lib/api/projects.rb index 0923d31f5ff..ed9f5a9039e 100644 --- a/lib/api/projects.rb +++ b/lib/api/projects.rb @@ -358,6 +358,18 @@ module API end end + desc 'List users who starred this project' do + success Entities::UserBasic + end + params do + use :collection_params + end + get ':id/starrers' do + users = DeclarativePolicy.subject_scope { user_project.starrers } + + present users, with: Entities::UserBasic + end + desc 'Get languages in project repository' get ':id/languages' do ::Projects::RepositoryLanguagesService -- cgit v1.2.1 From d03a4c9a07c1a1eebbb209514957abd3278bd602 Mon Sep 17 00:00:00 2001 From: Camil Staps Date: Sun, 27 Jan 2019 12:45:43 +0100 Subject: Add users/:user_id/starred_projects API endpoint for projects starred by a user --- lib/api/projects.rb | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'lib/api') diff --git a/lib/api/projects.rb b/lib/api/projects.rb index ed9f5a9039e..e24c5765de5 100644 --- a/lib/api/projects.rb +++ b/lib/api/projects.rb @@ -115,6 +115,22 @@ module API present_projects load_projects end + + desc 'Get a user\'s starred projects' do + success Entities::BasicProjectDetails + end + params do + requires :user_id, type: String, desc: 'The ID or username of the user' + use :collection_params + use :statistics_params + end + get ":user_id/starred_projects" do + user = find_user(params[:user_id]) + not_found!('User') unless user + + starred_projects = StarredProjectsFinder.new(user).execute(current_user) + present_projects starred_projects + end end resource :projects do -- cgit v1.2.1 From e7c34c37c83d877a887173d833ba4103772d1566 Mon Sep 17 00:00:00 2001 From: Camil Staps Date: Mon, 28 Jan 2019 20:01:18 +0100 Subject: Add documentation and changelog for !24690 --- lib/api/projects.rb | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'lib/api') diff --git a/lib/api/projects.rb b/lib/api/projects.rb index e24c5765de5..dc9959b619f 100644 --- a/lib/api/projects.rb +++ b/lib/api/projects.rb @@ -116,7 +116,7 @@ module API present_projects load_projects end - desc 'Get a user\'s starred projects' do + desc 'Get projects starred by a user' do success Entities::BasicProjectDetails end params do @@ -374,16 +374,18 @@ module API end end - desc 'List users who starred this project' do + desc 'Get the users who starred a project' do success Entities::UserBasic end params do - use :collection_params + optional :search, type: String, desc: 'Return list of users matching the search criteria' + use :pagination end get ':id/starrers' do users = DeclarativePolicy.subject_scope { user_project.starrers } + users = users.search(params[:search]) if params[:search].present? - present users, with: Entities::UserBasic + present paginate(users), with: Entities::UserBasic end desc 'Get languages in project repository' -- cgit v1.2.1 From 1ec8c0e837ff4ba42adbc7cc1e9a15a04f2afd7e Mon Sep 17 00:00:00 2001 From: Camil Staps Date: Mon, 28 Jan 2019 20:57:56 +0100 Subject: Fix API endpoint for starred projects of a user; add info about starred projects on profile to documentation --- lib/api/projects.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/api') diff --git a/lib/api/projects.rb b/lib/api/projects.rb index dc9959b619f..f8f0ff48be0 100644 --- a/lib/api/projects.rb +++ b/lib/api/projects.rb @@ -128,7 +128,7 @@ module API user = find_user(params[:user_id]) not_found!('User') unless user - starred_projects = StarredProjectsFinder.new(user).execute(current_user) + starred_projects = StarredProjectsFinder.new(user, current_user: current_user).execute present_projects starred_projects end end -- cgit v1.2.1 From e8bdcdf0f89d88463f6fb8a67e85f315e6a9097d Mon Sep 17 00:00:00 2001 From: Camil Staps Date: Sat, 2 Feb 2019 20:48:27 +0100 Subject: Expose time since starring on project/:id/starrers API endpoint; exclude private profiles here as well --- lib/api/entities.rb | 5 +++++ lib/api/projects.rb | 7 +++---- 2 files changed, 8 insertions(+), 4 deletions(-) (limited to 'lib/api') diff --git a/lib/api/entities.rb b/lib/api/entities.rb index 2f5ce3d4003..643b53f5e63 100644 --- a/lib/api/entities.rb +++ b/lib/api/entities.rb @@ -77,6 +77,11 @@ module API expose :last_activity_on, as: :last_activity_at # Back-compat end + class UserStarsProject < Grape::Entity + expose :starred_since + expose :user, using: Entities::UserBasic + end + class Identity < Grape::Entity expose :provider, :extern_uid end diff --git a/lib/api/projects.rb b/lib/api/projects.rb index f8f0ff48be0..6d221200372 100644 --- a/lib/api/projects.rb +++ b/lib/api/projects.rb @@ -128,7 +128,7 @@ module API user = find_user(params[:user_id]) not_found!('User') unless user - starred_projects = StarredProjectsFinder.new(user, current_user: current_user).execute + starred_projects = StarredProjectsFinder.new(user, params: project_finder_params, current_user: current_user).execute present_projects starred_projects end end @@ -382,10 +382,9 @@ module API use :pagination end get ':id/starrers' do - users = DeclarativePolicy.subject_scope { user_project.starrers } - users = users.search(params[:search]) if params[:search].present? + starrers = UsersStarProjectsFinder.new(params, user_project, current_user: current_user).execute - present paginate(users), with: Entities::UserBasic + present paginate(starrers), with: Entities::UserStarsProject end desc 'Get languages in project repository' -- cgit v1.2.1 From 99bb207ef14d12fe59e23fd70e219ed5e166470b Mon Sep 17 00:00:00 2001 From: Camil Staps Date: Sat, 2 Feb 2019 20:53:21 +0100 Subject: Fix tests --- lib/api/projects.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/api') diff --git a/lib/api/projects.rb b/lib/api/projects.rb index 6d221200372..996205d4b7b 100644 --- a/lib/api/projects.rb +++ b/lib/api/projects.rb @@ -382,7 +382,7 @@ module API use :pagination end get ':id/starrers' do - starrers = UsersStarProjectsFinder.new(params, user_project, current_user: current_user).execute + starrers = UsersStarProjectsFinder.new(user_project, params, current_user: current_user).execute present paginate(starrers), with: Entities::UserStarsProject end -- cgit v1.2.1 From e3696bf20e4d646f46f847237da828eaee00253a Mon Sep 17 00:00:00 2001 From: Tiger Date: Thu, 1 Aug 2019 16:20:35 +1000 Subject: Final removal of KubernetesService Creating new records has been disabled, and all existing records been migrated to clusters as of https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/28534 --- lib/api/helpers/services_helpers.rb | 27 --------------------------- 1 file changed, 27 deletions(-) (limited to 'lib/api') diff --git a/lib/api/helpers/services_helpers.rb b/lib/api/helpers/services_helpers.rb index c4ecf55969c..422db5c7a50 100644 --- a/lib/api/helpers/services_helpers.rb +++ b/lib/api/helpers/services_helpers.rb @@ -489,32 +489,6 @@ module API desc: 'The ID of a transition that moves issues to a closed state. You can find this number under the Jira workflow administration (**Administration > Issues > Workflows**) by selecting **View** under **Operations** of the desired workflow of your project. The ID of each state can be found inside the parenthesis of each transition name under the **Transitions (id)** column ([see screenshot][trans]). By default, this ID is set to `2`' } ], - 'kubernetes' => [ - { - required: true, - name: :namespace, - type: String, - desc: 'The Kubernetes namespace to use' - }, - { - required: true, - name: :api_url, - type: String, - desc: 'The URL to the Kubernetes cluster API, e.g., https://kubernetes.example.com' - }, - { - required: true, - name: :token, - type: String, - desc: 'The service token to authenticate against the Kubernetes cluster with' - }, - { - required: false, - name: :ca_pem, - type: String, - desc: 'A custom certificate authority bundle to verify the Kubernetes cluster with (PEM format)' - } - ], 'mattermost-slash-commands' => [ { required: true, @@ -739,7 +713,6 @@ module API ::HipchatService, ::IrkerService, ::JiraService, - ::KubernetesService, ::MattermostSlashCommandsService, ::SlackSlashCommandsService, ::PackagistService, -- cgit v1.2.1 From 4c53b3945c874933d6da517ade161d66f8f87b21 Mon Sep 17 00:00:00 2001 From: Yorick Peterse Date: Wed, 7 Aug 2019 16:01:51 +0200 Subject: Backport EE changes to the project import API EE added a single line to this file that can easily be backported to CE, but it appears this was overlooked. The method called is a noop in CE, so no additional changes are necessary. --- lib/api/project_import.rb | 1 + 1 file changed, 1 insertion(+) (limited to 'lib/api') diff --git a/lib/api/project_import.rb b/lib/api/project_import.rb index 71891e43dcc..bb1b037c08f 100644 --- a/lib/api/project_import.rb +++ b/lib/api/project_import.rb @@ -59,6 +59,7 @@ module API } override_params = import_params.delete(:override_params) + filter_attributes_using_license!(override_params) if override_params project = ::Projects::GitlabProjectsImportService.new( current_user, project_params, override_params -- cgit v1.2.1 From e6dc5168b86d613e3334fa55618e394308bf55bf Mon Sep 17 00:00:00 2001 From: Sean McGivern Date: Tue, 6 Aug 2019 17:27:46 +0100 Subject: Remove label issue and MR counts from default API responses These counts significantly increase the load time for these requests. Users can now opt in to receiving the counts by setting `with_counts=true` in requests. This is a breaking change, but hopefully a fairly minor one. --- lib/api/entities.rb | 18 ++++++++++-------- lib/api/group_labels.rb | 2 ++ lib/api/helpers/label_helpers.rb | 6 +++++- lib/api/labels.rb | 2 ++ 4 files changed, 19 insertions(+), 9 deletions(-) (limited to 'lib/api') diff --git a/lib/api/entities.rb b/lib/api/entities.rb index 2f5ce3d4003..70201502b57 100644 --- a/lib/api/entities.rb +++ b/lib/api/entities.rb @@ -1085,16 +1085,18 @@ module API end class Label < LabelBasic - expose :open_issues_count do |label, options| - label.open_issues_count(options[:current_user]) - end + with_options if: lambda { |_, options| options[:with_counts] } do + expose :open_issues_count do |label, options| + label.open_issues_count(options[:current_user]) + end - expose :closed_issues_count do |label, options| - label.closed_issues_count(options[:current_user]) - end + expose :closed_issues_count do |label, options| + label.closed_issues_count(options[:current_user]) + end - expose :open_merge_requests_count do |label, options| - label.open_merge_requests_count(options[:current_user]) + expose :open_merge_requests_count do |label, options| + label.open_merge_requests_count(options[:current_user]) + end end expose :subscribed do |label, options| diff --git a/lib/api/group_labels.rb b/lib/api/group_labels.rb index 0dbc5f45a68..79a44941c81 100644 --- a/lib/api/group_labels.rb +++ b/lib/api/group_labels.rb @@ -16,6 +16,8 @@ module API success Entities::GroupLabel end params do + optional :with_counts, type: Boolean, default: false, + desc: 'Include issue and merge request counts' use :pagination end get ':id/labels' do diff --git a/lib/api/helpers/label_helpers.rb b/lib/api/helpers/label_helpers.rb index c11e7d614ab..896b0aba52b 100644 --- a/lib/api/helpers/label_helpers.rb +++ b/lib/api/helpers/label_helpers.rb @@ -19,7 +19,11 @@ module API end def get_labels(parent, entity) - present paginate(available_labels_for(parent)), with: entity, current_user: current_user, parent: parent + present paginate(available_labels_for(parent)), + with: entity, + current_user: current_user, + parent: parent, + with_counts: params[:with_counts] end def create_label(parent, entity) diff --git a/lib/api/labels.rb b/lib/api/labels.rb index d729d3ee625..c183198d3c6 100644 --- a/lib/api/labels.rb +++ b/lib/api/labels.rb @@ -15,6 +15,8 @@ module API success Entities::ProjectLabel end params do + optional :with_counts, type: Boolean, default: false, + desc: 'Include issue and merge request counts' use :pagination end get ':id/labels' do -- cgit v1.2.1 From 5f82ff1469510b4e51d531775a44e4bea92254fe Mon Sep 17 00:00:00 2001 From: Hordur Freyr Yngvason Date: Thu, 8 Aug 2019 18:51:52 +0000 Subject: Bring scoped environment variables to core As decided in https://gitlab.com/gitlab-org/gitlab-ce/issues/53593 --- lib/api/entities.rb | 1 + lib/api/helpers/variables_helpers.rb | 13 ------------- lib/api/variables.rb | 8 ++------ 3 files changed, 3 insertions(+), 19 deletions(-) delete mode 100644 lib/api/helpers/variables_helpers.rb (limited to 'lib/api') diff --git a/lib/api/entities.rb b/lib/api/entities.rb index 643b53f5e63..1496b5c5f9e 100644 --- a/lib/api/entities.rb +++ b/lib/api/entities.rb @@ -1346,6 +1346,7 @@ module API expose :variable_type, :key, :value expose :protected?, as: :protected, if: -> (entity, _) { entity.respond_to?(:protected?) } expose :masked?, as: :masked, if: -> (entity, _) { entity.respond_to?(:masked?) } + expose :environment_scope, if: -> (entity, _) { entity.respond_to?(:environment_scope) } end class Pipeline < PipelineBasic diff --git a/lib/api/helpers/variables_helpers.rb b/lib/api/helpers/variables_helpers.rb deleted file mode 100644 index 78a92d0f5a6..00000000000 --- a/lib/api/helpers/variables_helpers.rb +++ /dev/null @@ -1,13 +0,0 @@ -# frozen_string_literal: true - -module API - module Helpers - module VariablesHelpers - extend ActiveSupport::Concern - extend Grape::API::Helpers - - params :optional_params_ee do - end - end - end -end diff --git a/lib/api/variables.rb b/lib/api/variables.rb index af1d7936556..f022b9e665a 100644 --- a/lib/api/variables.rb +++ b/lib/api/variables.rb @@ -7,8 +7,6 @@ module API before { authenticate! } before { authorize! :admin_build, user_project } - helpers Helpers::VariablesHelpers - helpers do def filter_variable_parameters(params) # This method exists so that EE can more easily filter out certain @@ -59,8 +57,7 @@ module API optional :protected, type: Boolean, desc: 'Whether the variable is protected' optional :masked, type: Boolean, desc: 'Whether the variable is masked' optional :variable_type, type: String, values: Ci::Variable.variable_types.keys, desc: 'The type of variable, must be one of env_var or file. Defaults to env_var' - - use :optional_params_ee + optional :environment_scope, type: String, desc: 'The environment_scope of the variable' end post ':id/variables' do variable_params = declared_params(include_missing: false) @@ -84,8 +81,7 @@ module API optional :protected, type: Boolean, desc: 'Whether the variable is protected' optional :masked, type: Boolean, desc: 'Whether the variable is masked' optional :variable_type, type: String, values: Ci::Variable.variable_types.keys, desc: 'The type of variable, must be one of env_var or file' - - use :optional_params_ee + optional :environment_scope, type: String, desc: 'The environment_scope of the variable' end # rubocop: disable CodeReuse/ActiveRecord put ':id/variables/:key' do -- cgit v1.2.1 From 20ac5e6d4b1e1b6807e13b11daaedd2fb47bd3fc Mon Sep 17 00:00:00 2001 From: Armin Hohenegger Date: Sat, 10 Aug 2019 19:11:20 +0200 Subject: fix handling of empty ref_name parameter string in commits api when params[:ref_name] is set to "" by passing an empty query parameter to the api it is evaluated as false by the || operator. The use of active support core extensions presence method fixes the original implemantation. https://guides.rubyonrails.org/active_support_core_extensions.html#presence --- lib/api/commits.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/api') diff --git a/lib/api/commits.rb b/lib/api/commits.rb index e4f4e79cd46..a2f3e87ebd2 100644 --- a/lib/api/commits.rb +++ b/lib/api/commits.rb @@ -43,7 +43,7 @@ module API path = params[:path] before = params[:until] after = params[:since] - ref = params[:ref_name] || user_project.try(:default_branch) || 'master' unless params[:all] + ref = params[:ref_name].presence || user_project.try(:default_branch) || 'master' unless params[:all] offset = (params[:page] - 1) * params[:per_page] all = params[:all] with_stats = params[:with_stats] -- cgit v1.2.1 From 5d9d5e603119c3ae334b0855a63d10d12b2390bd Mon Sep 17 00:00:00 2001 From: Jeremy Jackson Date: Wed, 14 Aug 2019 19:21:58 +0000 Subject: Migrates Snowplow backend from EE to CE This introduces several changes, but these are all just ported from the EE project. --- lib/api/settings.rb | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'lib/api') diff --git a/lib/api/settings.rb b/lib/api/settings.rb index 196ef1fcdfa..c36ee5af63f 100644 --- a/lib/api/settings.rb +++ b/lib/api/settings.rb @@ -125,6 +125,12 @@ module API optional :instance_statistics_visibility_private, type: Boolean, desc: 'When set to `true` Instance statistics will only be available to admins' optional :local_markdown_version, type: Integer, desc: "Local markdown version, increase this value when any cached markdown should be invalidated" optional :allow_local_requests_from_hooks_and_services, type: Boolean, desc: 'Deprecated: Use :allow_local_requests_from_web_hooks_and_services instead. Allow requests to the local network from hooks and services.' # support legacy names, can be removed in v5 + optional :snowplow_enabled, type: Grape::API::Boolean, desc: 'Enable Snowplow tracking' + given snowplow_enabled: ->(val) { val } do + requires :snowplow_collector_hostname, type: String, desc: 'The Snowplow collector hostname' + optional :snowplow_cookie_domain, type: String, desc: 'The Snowplow cookie domain' + optional :snowplow_site_id, type: String, desc: 'The Snowplow site name / application ic' + end ApplicationSetting::SUPPORTED_KEY_TYPES.each do |type| optional :"#{type}_key_restriction", -- cgit v1.2.1 From 88746f5311a2624d99c3639daf2760c6715d5670 Mon Sep 17 00:00:00 2001 From: Luke Duncalfe Date: Wed, 14 Aug 2019 13:34:42 +1200 Subject: CE-specific changes to allow design Todos CE-specific changes for: https://gitlab.com/gitlab-org/gitlab-ee/merge_requests/15129 Co-Authored-By: Alex Kalderimis Co-Authored-By: Luke Duncalfe --- lib/api/todos.rb | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'lib/api') diff --git a/lib/api/todos.rb b/lib/api/todos.rb index 7260ecfb5ee..404675bfaec 100644 --- a/lib/api/todos.rb +++ b/lib/api/todos.rb @@ -13,6 +13,13 @@ module API 'issues' => ->(iid) { find_project_issue(iid) } }.freeze + helpers do + # EE::API::Todos would override this method + def find_todos + TodosFinder.new(current_user, params).execute + end + end + params do requires :id, type: String, desc: 'The ID of a project' end @@ -41,10 +48,6 @@ module API resource :todos do helpers do - def find_todos - TodosFinder.new(current_user, params).execute - end - def issuable_and_awardable?(type) obj_type = Object.const_get(type) @@ -107,3 +110,5 @@ module API end end end + +API::Todos.prepend_if_ee('EE::API::Todos') -- cgit v1.2.1 From d31405271179d9a95c2944e61249d2d906e4e7ac Mon Sep 17 00:00:00 2001 From: Luke Duncalfe Date: Thu, 15 Aug 2019 21:06:01 +1200 Subject: Remove prepend_if_ee from CE codebase This was added in https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/31789 --- lib/api/todos.rb | 2 -- 1 file changed, 2 deletions(-) (limited to 'lib/api') diff --git a/lib/api/todos.rb b/lib/api/todos.rb index 404675bfaec..526b5216e15 100644 --- a/lib/api/todos.rb +++ b/lib/api/todos.rb @@ -110,5 +110,3 @@ module API end end end - -API::Todos.prepend_if_ee('EE::API::Todos') -- cgit v1.2.1 From 922f21e23d60b965d83bd50b780cb9b33e8010c1 Mon Sep 17 00:00:00 2001 From: Alex Kalderimis Date: Thu, 15 Aug 2019 14:16:29 +0100 Subject: Adds EE prepend, which for some reason was missing --- lib/api/todos.rb | 2 ++ 1 file changed, 2 insertions(+) (limited to 'lib/api') diff --git a/lib/api/todos.rb b/lib/api/todos.rb index 7260ecfb5ee..51772db3118 100644 --- a/lib/api/todos.rb +++ b/lib/api/todos.rb @@ -107,3 +107,5 @@ module API end end end + +API::Todos.prepend_if_ee('EE::API::Todos') -- cgit v1.2.1 From 8044440d7ad8c476d05e3e204ee26b9663738cea Mon Sep 17 00:00:00 2001 From: Stan Hu Date: Wed, 14 Aug 2019 21:50:52 -0700 Subject: Eliminate many Gitaly calls in discussions API Previously, the API to retrieve discussions from merge requests often generated hundreds of Gitaly calls to determine whether a system note should be shown to the user. It did this by: 1. Rendering the Markdown 2. Extracting cross-references from the Markdown 3. For cross-references that were commits, a Gitaly FindCommit RPC would be issued to validate that the commit exists. The last step is unnecessary because we don't need to display a commit if the user doesn't have access to the project in the first place. `RendersNotes#prepare_notes_for_rendering` is already used in `MergeRequestsController`, which is why we don't see N+1 Gitaly calls there. We use it here to optimize the note redaction process. Closes https://gitlab.com/gitlab-org/gitlab-ce/issues/65957 --- lib/api/discussions.rb | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) (limited to 'lib/api') diff --git a/lib/api/discussions.rb b/lib/api/discussions.rb index cc62ce22a1b..6c1acc3963f 100644 --- a/lib/api/discussions.rb +++ b/lib/api/discussions.rb @@ -4,6 +4,7 @@ module API class Discussions < Grape::API include PaginationParams helpers ::API::Helpers::NotesHelpers + helpers ::RendersNotes before { authenticate! } @@ -23,21 +24,15 @@ module API requires :noteable_id, types: [Integer, String], desc: 'The ID of the noteable' use :pagination end - # rubocop: disable CodeReuse/ActiveRecord + get ":id/#{noteables_path}/:noteable_id/discussions" do noteable = find_noteable(parent_type, params[:id], noteable_type, params[:noteable_id]) - notes = noteable.notes - .inc_relations_for_view - .includes(:noteable) - .fresh - - notes = notes.reject { |n| n.cross_reference_not_visible_for?(current_user) } + notes = readable_discussion_notes(noteable) discussions = Kaminari.paginate_array(Discussion.build_collection(notes, noteable)) present paginate(discussions), with: Entities::Discussion end - # rubocop: enable CodeReuse/ActiveRecord desc "Get a single #{noteable_type.to_s.downcase} discussion" do success Entities::Discussion @@ -226,13 +221,24 @@ module API helpers do # rubocop: disable CodeReuse/ActiveRecord - def readable_discussion_notes(noteable, discussion_id) + def readable_discussion_notes(noteable, discussion_id = nil) notes = noteable.notes - .where(discussion_id: discussion_id) + notes = notes.where(discussion_id: discussion_id) if discussion_id + notes = notes .inc_relations_for_view .includes(:noteable) .fresh + # Without RendersActions#prepare_notes_for_rendering, + # Note#cross_reference_not_visible_for? will attempt to render + # Markdown references mentioned in the note to see whether they + # should be redacted. For notes that reference a commit, this + # would also incur a Gitaly call to verify the commit exists. + # + # With prepare_notes_for_rendering, we can avoid Gitaly calls + # because notes are redacted if they point to projects that + # cannot be accessed by the user. + notes = prepare_notes_for_rendering(notes) notes.reject { |n| n.cross_reference_not_visible_for?(current_user) } end # rubocop: enable CodeReuse/ActiveRecord -- cgit v1.2.1 From ba7c501fef5976ea7a1cc4212e84742246fed781 Mon Sep 17 00:00:00 2001 From: Stan Hu Date: Sat, 17 Aug 2019 15:39:39 -0700 Subject: Fix Gitaly N+1 calls with listing issues/MRs via API In GitLab 9.0, https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/9661 removed the `subscribed` flag from the API when the user requested a list of issues or merge requests since calculating this value triggers extensive Markdown processing. In GitLab 12.0 via a4fbf39e, we accidentally reintroduced this performance regression by changing `IssueBasic` to `Issue` in `entities.rb`. This showed up as a Gitaly N+1 issue since the Markdown processing would attempt to extract a commit if it detected a regex that matched a commit. We restore the prior behavior by once again removing the `subscribed` flag for the bulk list of issues and merge requests and add a test to ensure they aren't reintroduced. Closes https://gitlab.com/gitlab-org/gitlab-ce/issues/66202 --- lib/api/entities.rb | 5 ++++- lib/api/issues.rb | 6 ++++-- 2 files changed, 8 insertions(+), 3 deletions(-) (limited to 'lib/api') diff --git a/lib/api/entities.rb b/lib/api/entities.rb index 09253ab6b0e..5e66b4e76a5 100644 --- a/lib/api/entities.rb +++ b/lib/api/entities.rb @@ -645,7 +645,10 @@ module API end end - expose :subscribed do |issue, options| + # Calculating the value of subscribed field triggers Markdown + # processing. We can't do that for multiple issues / merge + # requests in a single API request. + expose :subscribed, if: -> (_, options) { options.fetch(:include_subscribed, true) } do |issue, options| issue.subscribed?(options[:current_user], options[:project] || issue.project) end end diff --git a/lib/api/issues.rb b/lib/api/issues.rb index d687acf3423..7819c2de515 100644 --- a/lib/api/issues.rb +++ b/lib/api/issues.rb @@ -96,7 +96,8 @@ module API with: Entities::Issue, with_labels_details: declared_params[:with_labels_details], current_user: current_user, - issuable_metadata: issuable_meta_data(issues, 'Issue', current_user) + issuable_metadata: issuable_meta_data(issues, 'Issue', current_user), + include_subscribed: false } present issues, options @@ -122,7 +123,8 @@ module API with: Entities::Issue, with_labels_details: declared_params[:with_labels_details], current_user: current_user, - issuable_metadata: issuable_meta_data(issues, 'Issue', current_user) + issuable_metadata: issuable_meta_data(issues, 'Issue', current_user), + include_subscribed: false } present issues, options -- cgit v1.2.1 From e632ae80845f849f93e4d85ef9f836a4792844c9 Mon Sep 17 00:00:00 2001 From: Stan Hu Date: Tue, 20 Aug 2019 18:12:28 +0000 Subject: Standardize remote_ip and path keys for auth.log and api_json.log Current `auth.log` uses `fullpath` and `ip`, while `api_json.log` uses `remote_ip` and `path` for the same fields. Let's standardize these namings to make it easier for people working with the data. Closes https://gitlab.com/gitlab-org/gitlab-ce/issues/66167 --- lib/api/api.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/api') diff --git a/lib/api/api.rb b/lib/api/api.rb index e500a93b31e..219ed45eff6 100644 --- a/lib/api/api.rb +++ b/lib/api/api.rb @@ -18,7 +18,7 @@ module API formatter: Gitlab::GrapeLogging::Formatters::LogrageWithTimestamp.new, include: [ GrapeLogging::Loggers::FilterParameters.new(LOG_FILTERS), - GrapeLogging::Loggers::ClientEnv.new, + Gitlab::GrapeLogging::Loggers::ClientEnvLogger.new, Gitlab::GrapeLogging::Loggers::RouteLogger.new, Gitlab::GrapeLogging::Loggers::UserLogger.new, Gitlab::GrapeLogging::Loggers::QueueDurationLogger.new, -- cgit v1.2.1 From 37b17fa61a1fb5efe5942ab2cb27b15685bf905e Mon Sep 17 00:00:00 2001 From: Luke Duncalfe Date: Tue, 18 Jun 2019 13:44:43 +1200 Subject: Add service classes for mutating AwardEmoji Adding, destroying and toggling emoji previously lacked services and instead were performed through methods called on Awardable models. This led to inconsistencies where relevant todos would be marked as done only when emoji were awarded through our controllers, but not through the API. Todos could also be marked as done when an emoji was being removed. Behaviour changes - Awarding emoji through the API will now mark a relevant Todo as done - Toggling an emoji off (destroying it) through our controllers will no longer mark a relevant Todo as done Closes https://gitlab.com/gitlab-org/gitlab-ce/issues/63372 --- lib/api/award_emoji.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'lib/api') diff --git a/lib/api/award_emoji.rb b/lib/api/award_emoji.rb index a1851ba3627..89b7e5c5e4b 100644 --- a/lib/api/award_emoji.rb +++ b/lib/api/award_emoji.rb @@ -69,12 +69,12 @@ module API post endpoint do not_found!('Award Emoji') unless can_read_awardable? && can_award_awardable? - award = awardable.create_award_emoji(params[:name], current_user) + service = AwardEmojis::AddService.new(awardable, params[:name], current_user).execute - if award.persisted? - present award, with: Entities::AwardEmoji + if service[:status] == :success + present service[:award], with: Entities::AwardEmoji else - not_found!("Award Emoji #{award.errors.messages}") + not_found!("Award Emoji #{service[:message]}") end end -- cgit v1.2.1