summaryrefslogtreecommitdiff
path: root/app/controllers/concerns
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2019-11-15 18:06:24 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2019-11-15 18:06:24 +0000
commiteca3cd3a9e7d9ea680086cad8150050ec8cdef3f (patch)
treec3d262e0d8e721fc138c2d617f501fb09876f1b6 /app/controllers/concerns
parent6e81d7f6283fae1b22f66b9d9b133243921cbd9e (diff)
downloadgitlab-ce-eca3cd3a9e7d9ea680086cad8150050ec8cdef3f.tar.gz
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app/controllers/concerns')
-rw-r--r--app/controllers/concerns/sourcegraph_gon.rb30
1 files changed, 30 insertions, 0 deletions
diff --git a/app/controllers/concerns/sourcegraph_gon.rb b/app/controllers/concerns/sourcegraph_gon.rb
new file mode 100644
index 00000000000..01925cf9d4d
--- /dev/null
+++ b/app/controllers/concerns/sourcegraph_gon.rb
@@ -0,0 +1,30 @@
+# frozen_string_literal: true
+
+module SourcegraphGon
+ extend ActiveSupport::Concern
+
+ included do
+ before_action :push_sourcegraph_gon, if: :html_request?
+ end
+
+ private
+
+ def push_sourcegraph_gon
+ return unless sourcegraph_enabled?
+
+ gon.push({
+ sourcegraph: { url: Gitlab::CurrentSettings.sourcegraph_url }
+ })
+ end
+
+ def sourcegraph_enabled?
+ Gitlab::CurrentSettings.sourcegraph_enabled && sourcegraph_enabled_for_project? && current_user&.sourcegraph_enabled
+ end
+
+ def sourcegraph_enabled_for_project?
+ return false unless project && Gitlab::Sourcegraph.feature_enabled?(project)
+ return project.public? if Gitlab::CurrentSettings.sourcegraph_public_only
+
+ true
+ end
+end