diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-07-20 12:26:25 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-07-20 12:26:25 +0000 |
commit | a09983ae35713f5a2bbb100981116d31ce99826e (patch) | |
tree | 2ee2af7bd104d57086db360a7e6d8c9d5d43667a /lib/api/helpers.rb | |
parent | 18c5ab32b738c0b6ecb4d0df3994000482f34bd8 (diff) | |
download | gitlab-ce-a09983ae35713f5a2bbb100981116d31ce99826e.tar.gz |
Add latest changes from gitlab-org/gitlab@13-2-stable-ee
Diffstat (limited to 'lib/api/helpers.rb')
-rw-r--r-- | lib/api/helpers.rb | 33 |
1 files changed, 25 insertions, 8 deletions
diff --git a/lib/api/helpers.rb b/lib/api/helpers.rb index bbdb45da3b1..01b89959c14 100644 --- a/lib/api/helpers.rb +++ b/lib/api/helpers.rb @@ -41,6 +41,16 @@ module API end end + def job_token_authentication? + initial_current_user && @current_authenticated_job.present? # rubocop:disable Gitlab/ModuleWithInstanceVariables + end + + # Returns the job associated with the token provided for + # authentication, if any + def current_authenticated_job + @current_authenticated_job + end + # rubocop:disable Gitlab/ModuleWithInstanceVariables # We can't rewrite this with StrongMemoize because `sudo!` would # actually write to `@current_user`, and `sudo?` would immediately @@ -79,12 +89,6 @@ module API @project ||= find_project!(params[:id]) end - def wiki_page - page = ProjectWiki.new(user_project, current_user).find_page(params[:slug]) - - page || not_found!('Wiki Page') - end - def available_labels_for(label_parent, include_ancestor_groups: true) search_params = { include_ancestor_groups: include_ancestor_groups } @@ -374,6 +378,12 @@ module API render_api_error!(message.join(' '), 404) end + def check_sha_param!(params, merge_request) + if params[:sha] && merge_request.diff_head_sha != params[:sha] + render_api_error!("SHA does not match HEAD of source branch: #{merge_request.diff_head_sha}", 409) + end + end + def unauthorized! render_api_error!('401 Unauthorized', 401) end @@ -416,10 +426,14 @@ module API def render_validation_error!(model) if model.errors.any? - render_api_error!(model.errors.messages || '400 Bad Request', 400) + render_api_error!(model_error_messages(model) || '400 Bad Request', 400) end end + def model_error_messages(model) + model.errors.messages + end + def render_spam_error! render_api_error!({ error: 'Spam detected' }, 400) end @@ -490,7 +504,7 @@ module API header['X-Sendfile'] = path body else - file path + sendfile path end end @@ -534,6 +548,8 @@ module API def project_finder_params_ce finder_params = project_finder_params_visibility_ce + finder_params[:with_issues_enabled] = true if params[:with_issues_enabled].present? + finder_params[:with_merge_requests_enabled] = true if params[:with_merge_requests_enabled].present? finder_params[:without_deleted] = true finder_params[:search] = params[:search] if params[:search] finder_params[:search_namespaces] = true if params[:search_namespaces].present? @@ -543,6 +559,7 @@ module API finder_params[:id_before] = params[:id_before] if params[:id_before] finder_params[:last_activity_after] = params[:last_activity_after] if params[:last_activity_after] finder_params[:last_activity_before] = params[:last_activity_before] if params[:last_activity_before] + finder_params[:repository_storage] = params[:repository_storage] if params[:repository_storage] finder_params end |