Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/lib/api
diff options
context:
space:
mode:
Diffstat (limited to 'lib/api')
-rw-r--r--lib/api/api.rb8
-rw-r--r--lib/api/commit_statuses.rb12
-rw-r--r--lib/api/helpers/internal_helpers.rb4
-rw-r--r--lib/api/internal/base.rb12
-rw-r--r--lib/api/projects.rb2
5 files changed, 30 insertions, 8 deletions
diff --git a/lib/api/api.rb b/lib/api/api.rb
index 56eccb036b6..eae10738f32 100644
--- a/lib/api/api.rb
+++ b/lib/api/api.rb
@@ -43,6 +43,14 @@ module API
header['X-Content-Type-Options'] = 'nosniff'
end
+ before do
+ Gitlab::ApplicationContext.push(
+ user: -> { current_user },
+ project: -> { @project },
+ namespace: -> { @group }
+ )
+ end
+
# The locale is set to the current user's locale when `current_user` is loaded
after { Gitlab::I18n.use_default_locale }
diff --git a/lib/api/commit_statuses.rb b/lib/api/commit_statuses.rb
index d108c811f4b..6e26ee309f0 100644
--- a/lib/api/commit_statuses.rb
+++ b/lib/api/commit_statuses.rb
@@ -71,27 +71,27 @@ module API
ref = params[:ref]
ref ||= pipeline&.ref
- ref ||= @project.repository.branch_names_contains(commit.sha).first
+ ref ||= user_project.repository.branch_names_contains(commit.sha).first
not_found! 'References for commit' unless ref
name = params[:name] || params[:context] || 'default'
unless pipeline
- pipeline = @project.ci_pipelines.create!(
+ pipeline = user_project.ci_pipelines.create!(
source: :external,
sha: commit.sha,
ref: ref,
user: current_user,
- protected: @project.protected_for?(ref))
+ protected: user_project.protected_for?(ref))
end
status = GenericCommitStatus.running_or_pending.find_or_initialize_by(
- project: @project,
+ project: user_project,
pipeline: pipeline,
name: name,
ref: ref,
user: current_user,
- protected: @project.protected_for?(ref)
+ protected: user_project.protected_for?(ref)
)
optional_attributes =
@@ -117,7 +117,7 @@ module API
render_api_error!('invalid state', 400)
end
- MergeRequest.where(source_project: @project, source_branch: ref)
+ MergeRequest.where(source_project: user_project, source_branch: ref)
.update_all(head_pipeline_id: pipeline.id) if pipeline.latest?
present status, with: Entities::CommitStatus
diff --git a/lib/api/helpers/internal_helpers.rb b/lib/api/helpers/internal_helpers.rb
index 607e0784415..b719e5c0886 100644
--- a/lib/api/helpers/internal_helpers.rb
+++ b/lib/api/helpers/internal_helpers.rb
@@ -107,8 +107,10 @@ module API
if params[:gl_repository]
@project, @repo_type = Gitlab::GlRepository.parse(params[:gl_repository])
@redirected_path = nil
- else
+ elsif params[:project]
@project, @repo_type, @redirected_path = Gitlab::RepoPath.parse(params[:project])
+ else
+ @project, @repo_type, @redirected_path = nil, nil, nil
end
end
# rubocop:enable Gitlab/ModuleWithInstanceVariables
diff --git a/lib/api/internal/base.rb b/lib/api/internal/base.rb
index 11f2a2ea1c0..d64de2bb465 100644
--- a/lib/api/internal/base.rb
+++ b/lib/api/internal/base.rb
@@ -6,6 +6,13 @@ module API
class Base < Grape::API
before { authenticate_by_gitlab_shell_token! }
+ before do
+ Gitlab::ApplicationContext.push(
+ user: -> { actor&.user },
+ project: -> { project }
+ )
+ end
+
helpers ::API::Helpers::InternalHelpers
UNKNOWN_CHECK_RESULT_ERROR = 'Unknown check result'.freeze
@@ -205,7 +212,12 @@ module API
status 200
response = Gitlab::InternalPostReceive::Response.new
+
+ # Try to load the project and users so we have the application context
+ # available for logging before we schedule any jobs.
user = actor.user
+ project
+
push_options = Gitlab::PushOptions.new(params[:push_options])
response.reference_counter_decreased = Gitlab::ReferenceCounter.new(params[:gl_repository]).decrease
diff --git a/lib/api/projects.rb b/lib/api/projects.rb
index d1f99ea49ce..68f199cc160 100644
--- a/lib/api/projects.rb
+++ b/lib/api/projects.rb
@@ -355,7 +355,7 @@ module API
post ':id/unarchive' do
authorize!(:archive_project, user_project)
- ::Projects::UpdateService.new(@project, current_user, archived: false).execute
+ ::Projects::UpdateService.new(user_project, current_user, archived: false).execute
present user_project, with: Entities::Project, current_user: current_user
end