Apply changes from team members in own editor

This commit is contained in:
kiragrammel
2023-08-16 18:36:42 +02:00
committed by Sebastian Serth
parent 69ba7270dd
commit 89afb599e4
8 changed files with 127 additions and 4 deletions

View File

@ -2,10 +2,12 @@
module ApplicationCable
class Connection < ActionCable::Connection::Base
identified_by :current_user
identified_by :current_user, :current_contributor
def connect
# The order is important here, because a valid user is required to find a valid contributor.
self.current_user = find_verified_user
self.current_contributor = find_verified_contributor
end
def disconnect
@ -24,5 +26,14 @@ module ApplicationCable
current_user = ExternalUser.find_by(id: session[:external_user_id]) || InternalUser.find_by(id: session[:user_id])
current_user || reject_unauthorized_connection
end
def find_verified_contributor
# Finding the current_contributor is similar to the code used in application_controller.rb#current_contributor
if session[:pg_id]
current_user.programming_groups.find(session[:pg_id])
else
current_user
end
end
end
end

View File

@ -0,0 +1,25 @@
# frozen_string_literal: true
class SynchronizedEditorChannel < ApplicationCable::Channel
def subscribed
stream_from specific_channel
end
def unsubscribed
# Any cleanup needed when channel is unsubscribed
stop_all_streams
end
def specific_channel
reject unless ProgrammingGroupPolicy.new(current_user, programming_group).stream_sync_editor?
"synchronized_editor_channel_group_#{programming_group.id}"
end
def programming_group
current_contributor if current_contributor.programming_group?
end
def send_changes(message)
ActionCable.server.broadcast(specific_channel, message['delta_with_user_id'])
end
end