summaryrefslogtreecommitdiff
path: root/app/channels
diff options
context:
space:
mode:
Diffstat (limited to 'app/channels')
-rw-r--r--app/channels/application_cable/channel.rb6
-rw-r--r--app/channels/application_cable/connection.rb22
-rw-r--r--app/channels/issues_channel.rb13
3 files changed, 41 insertions, 0 deletions
diff --git a/app/channels/application_cable/channel.rb b/app/channels/application_cable/channel.rb
new file mode 100644
index 00000000000..9aec2305390
--- /dev/null
+++ b/app/channels/application_cable/channel.rb
@@ -0,0 +1,6 @@
+# frozen_string_literal: true
+
+module ApplicationCable
+ class Channel < ActionCable::Channel::Base
+ end
+end
diff --git a/app/channels/application_cable/connection.rb b/app/channels/application_cable/connection.rb
new file mode 100644
index 00000000000..87c833f3593
--- /dev/null
+++ b/app/channels/application_cable/connection.rb
@@ -0,0 +1,22 @@
+# frozen_string_literal: true
+
+module ApplicationCable
+ class Connection < ActionCable::Connection::Base
+ identified_by :current_user
+
+ def connect
+ self.current_user = find_user_from_session_store
+ end
+
+ private
+
+ def find_user_from_session_store
+ session = ActiveSession.sessions_from_ids([session_id]).first
+ Warden::SessionSerializer.new('rack.session' => session).fetch(:user)
+ end
+
+ def session_id
+ Rack::Session::SessionId.new(cookies[Gitlab::Application.config.session_options[:key]])
+ end
+ end
+end
diff --git a/app/channels/issues_channel.rb b/app/channels/issues_channel.rb
new file mode 100644
index 00000000000..5f3909b7716
--- /dev/null
+++ b/app/channels/issues_channel.rb
@@ -0,0 +1,13 @@
+# 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