Skip to content

Commit 9f30996

Browse files
committed
Support for multiple chili instances added
1 parent 6804ab0 commit 9f30996

File tree

1 file changed

+26
-5
lines changed

1 file changed

+26
-5
lines changed

app/controllers/pads_controller.rb

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,21 +15,41 @@ def pad_domain
1515
ENV['PAD_DOMAIN']
1616
end
1717

18+
def pad_client_id
19+
ENV['PAD_CLIENT_ID']
20+
end
21+
1822
def index
1923
@pad_host = self.pad_host
2024
session[:ep_sessions] = {} if session[:ep_sessions].nil?
2125
ether = EtherpadLite.connect(@pad_host, self.pad_key)
22-
group = ether.group(@project.identifier)
26+
group = ether.group(self.project_uid(@project))
2327
@pads = group.pads
2428
end
2529

30+
def project_uid(project)
31+
if self.pad_client_id.nil? || self.pad_client_id.empty?
32+
return project.identifier
33+
else
34+
return "#{self.pad_client_id}-#{project.identifier}"
35+
end
36+
end
37+
38+
def user_uid(user)
39+
if self.pad_client_id.nil? || self.pad_client_id.empty?
40+
return "chili_user_#{user.id}"
41+
else
42+
return "#{self.pad_client_id}_chili_user_#{user.id}"
43+
end
44+
end
45+
2646
def new
2747
if request.post?
2848
@pad_host = self.pad_host
2949
pad_title = params[:pad][:title]
3050
session[:ep_sessions] = {} if session[:ep_sessions].nil?
3151
ether = EtherpadLite.connect(@pad_host, self.pad_key)
32-
@group = ether.group(@project.identifier)
52+
@group = ether.group(self.project_uid(@project))
3353
if @group.pads.select { |p| p.name == pad_title }.size == 0
3454
@pad = @group.pad(pad_title)
3555
redirect_to :action => :show, :pad_id => pad_title
@@ -44,7 +64,7 @@ def destroy
4464
@pad_host = self.pad_host
4565
session[:ep_sessions] = {} if session[:ep_sessions].nil?
4666
ether = EtherpadLite.connect(@pad_host, self.pad_key)
47-
group = ether.group(@project.identifier)
67+
group = ether.group(self.project_uid(@project))
4868
pad = group.pad(params[:pad_id])
4969
pad.delete
5070
redirect_to :action => :index, :project_id => @project
@@ -55,12 +75,12 @@ def show
5575
session[:ep_sessions] = {} if session[:ep_sessions].nil?
5676
ether = EtherpadLite.connect(@pad_host, self.pad_key)
5777
# Get the EtherpadLite Group and Pad by id
58-
@group = ether.group(@project.identifier)
78+
@group = ether.group(self.project_uid(@project))
5979
@pad = @group.pad(params[:pad_id])
6080
@pad_id = "#{@group.id}$#{@pad.name}"
6181
@user_name = User.current.name
6282
# Map the user to an EtherpadLite Author
63-
author = ether.author("chili_user_#{User.current.id}", :name => User.current.name)
83+
author = ether.author(self.user_uid(User.current), :name => User.current.name)
6484
# Get or create an hour-long session for this Author in this Group
6585
sess = session[:ep_sessions][@group.id] ? ether.get_session(session[:ep_sessions][@group.id]) : @group.create_session(author, 60)
6686
if sess.expired?
@@ -73,6 +93,7 @@ def show
7393
end
7494

7595
private
96+
7697
def find_project
7798
@project = Project.find(params[:project_id])
7899
rescue ActiveRecord::RecordNotFound

0 commit comments

Comments
 (0)