summaryrefslogtreecommitdiff
path: root/app/channels
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2021-05-19 15:44:42 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2021-05-19 15:44:42 +0000
commit4555e1b21c365ed8303ffb7a3325d773c9b8bf31 (patch)
tree5423a1c7516cffe36384133ade12572cf709398d /app/channels
parente570267f2f6b326480d284e0164a6464ba4081bc (diff)
downloadgitlab-ce-4555e1b21c365ed8303ffb7a3325d773c9b8bf31.tar.gz
Add latest changes from gitlab-org/gitlab@13-12-stable-eev13.12.0-rc42
Diffstat (limited to 'app/channels')
-rw-r--r--app/channels/graphql_channel.rb56
-rw-r--r--app/channels/issues_channel.rb13
2 files changed, 56 insertions, 13 deletions
diff --git a/app/channels/graphql_channel.rb b/app/channels/graphql_channel.rb
new file mode 100644
index 00000000000..d364cc2b64b
--- /dev/null
+++ b/app/channels/graphql_channel.rb
@@ -0,0 +1,56 @@
+# frozen_string_literal: true
+
+# This is based on https://github.com/rmosolgo/graphql-ruby/blob/v1.11.8/lib/graphql/subscriptions/action_cable_subscriptions.rb#L19-L82
+# modified to work with our own ActionCableLink client
+
+class GraphqlChannel < ApplicationCable::Channel # rubocop:disable Gitlab/NamespacedClass
+ def subscribed
+ @subscription_ids = []
+
+ query = params['query']
+ variables = Gitlab::Graphql::Variables.new(params['variables']).to_h
+ operation_name = params['operationName']
+
+ result = GitlabSchema.execute(
+ query,
+ context: context,
+ variables: variables,
+ operation_name: operation_name
+ )
+
+ payload = {
+ result: result.to_h,
+ more: result.subscription?
+ }
+
+ # Track the subscription here so we can remove it
+ # on unsubscribe.
+ if result.context[:subscription_id]
+ @subscription_ids << result.context[:subscription_id]
+ end
+
+ transmit(payload)
+ end
+
+ def unsubscribed
+ @subscription_ids.each do |sid|
+ GitlabSchema.subscriptions.delete_subscription(sid)
+ end
+ end
+
+ rescue_from Gitlab::Graphql::Variables::Invalid do |exception|
+ transmit({ errors: [{ message: exception.message }] })
+ end
+
+ private
+
+ # When modifying the context, also update GraphqlController#context if needed
+ # so that we have similar context when executing queries, mutations, and subscriptions
+ #
+ # Objects added to the context may also need to be reloaded in
+ # `Subscriptions::BaseSubscription` so that they are not stale
+ def context
+ # is_sessionless_user is always false because we only support cookie auth in ActionCable
+ { channel: self, current_user: current_user, is_sessionless_user: false }
+ end
+end
diff --git a/app/channels/issues_channel.rb b/app/channels/issues_channel.rb
deleted file mode 100644
index 5f3909b7716..00000000000
--- a/app/channels/issues_channel.rb
+++ /dev/null
@@ -1,13 +0,0 @@
-# frozen_string_literal: true
-
-class IssuesChannel < ApplicationCable::Channel
- def subscribed
- project = Project.find_by_full_path(params[:project_path])
- return reject unless project
-
- issue = project.issues.find_by_iid(params[:iid])
- return reject unless issue && Ability.allowed?(current_user, :read_issue, issue)
-
- stream_for issue
- end
-end