forked from External/greenlight
reworking routes
This commit is contained in:
parent
1ddc3172eb
commit
6cdcd89387
|
@ -35,15 +35,21 @@ class ApplicationController < ActionController::Base
|
||||||
end
|
end
|
||||||
helper_method :allow_greenlight_users?
|
helper_method :allow_greenlight_users?
|
||||||
|
|
||||||
private
|
# Generate a URL to start a meeting.
|
||||||
|
def owner_meeting_url
|
||||||
|
opts = default_meeting_options
|
||||||
|
opts[:user_is_moderator] = true
|
||||||
|
@room.meeting.join_path(current_user.name, opts)
|
||||||
|
end
|
||||||
|
helper_method :owner_meeting_url
|
||||||
|
|
||||||
# Ensure the user is logged into the room they are accessing.
|
# Default, unconfigured meeting options.
|
||||||
def verify_room_ownership
|
def default_meeting_options
|
||||||
# Redirect to correct room or root if not logged in.
|
{
|
||||||
if current_user.nil?
|
user_is_moderator: false,
|
||||||
redirect_to root_path
|
meeting_logout_url: request.base_url + logout_room_path(@room.uid),
|
||||||
elsif @room.nil? || current_user != @room.user
|
meeting_recorded: true,
|
||||||
redirect_to room_path(current_user.room.uid)
|
moderator_message: "To invite someone to the meeting, send them this link:\n\n#{request.base_url + room_path(@room.uid)}"
|
||||||
end
|
}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
class MeetingsController < ApplicationController
|
class MeetingsController < ApplicationController
|
||||||
|
|
||||||
before_action :verify_room_ownership
|
#before_action :verify_room_ownership
|
||||||
|
|
||||||
# GET /rooms/:room_uid/meetings
|
# GET /r/:room_uid/meetings
|
||||||
def index
|
def index
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -1,24 +1,50 @@
|
||||||
class RoomsController < ApplicationController
|
class RoomsController < ApplicationController
|
||||||
|
|
||||||
before_action :find_room, :verify_room_ownership
|
before_action :find_room, :verify_room_ownership
|
||||||
skip_before_action :verify_room_ownership, only: [:join, :wait]
|
skip_before_action :verify_room_ownership, only: [:index, :join, :wait]
|
||||||
|
|
||||||
# GET /rooms/:room_uid
|
# GET /r/:room_uid
|
||||||
def index
|
def index
|
||||||
|
|
||||||
end
|
|
||||||
|
|
||||||
# GET /rooms/:room_uid/join
|
|
||||||
def join
|
|
||||||
if @meeting
|
|
||||||
opts = default_meeting_options
|
opts = default_meeting_options
|
||||||
|
|
||||||
if @meeting.is_running?
|
if @meeting.is_running?
|
||||||
if current_user
|
if current_user
|
||||||
# Check if the current user is the room/session owner.
|
# If you don't own the room but the meeting is running, join up.
|
||||||
opts[:user_is_moderator] = @meeting.room.owned_by?(current_user)
|
if !@room.owned_by?(current_user)
|
||||||
|
opts[:user_is_moderator] = false
|
||||||
|
redirect_to @meeting.join_path(current_user.name, opts)
|
||||||
|
end
|
||||||
|
else
|
||||||
|
# If you're unauthenticated, you must enter a name to join the meeting.
|
||||||
|
redirect_to join_room_path(@room.uid)
|
||||||
|
end
|
||||||
|
else
|
||||||
|
# If the meeting isn't running and you don't own the room, go to the waiting page.
|
||||||
|
if !@room.owned_by?(current_user)
|
||||||
|
redirect_to wait_room_path(@room.uid)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
# GET /r/:room_uid/start
|
||||||
|
def start
|
||||||
|
# Join the user in and start the meeting.
|
||||||
|
opts = default_meeting_options
|
||||||
|
opts[:user_is_moderator] = true
|
||||||
|
redirect_to @meeting.join_path(current_user.name, opts)
|
||||||
|
end
|
||||||
|
|
||||||
|
# GET /r/:room_uid/join
|
||||||
|
def join
|
||||||
|
if @meeting.is_running?
|
||||||
|
opts = default_meeting_options
|
||||||
|
|
||||||
|
if current_user
|
||||||
|
# If the user exists, join them in.
|
||||||
|
opts[:user_is_moderator] = @room.owned_by?(current_user)
|
||||||
redirect_to @meeting.join_path(current_user.name, opts)
|
redirect_to @meeting.join_path(current_user.name, opts)
|
||||||
else
|
else
|
||||||
# If the unauthenticated user has supplied a join name.
|
# If they are unauthenticated, prompt for join name.
|
||||||
if params[:join_name]
|
if params[:join_name]
|
||||||
redirect_to @meeting.join_path(params[:join_name], opts)
|
redirect_to @meeting.join_path(params[:join_name], opts)
|
||||||
else
|
else
|
||||||
|
@ -27,25 +53,18 @@ class RoomsController < ApplicationController
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
# Only start the meeting if owner is joining first.
|
if @room.owned_by?(current_user)
|
||||||
if current_user && @room.owned_by?(current_user)
|
# Redirect owner to room.
|
||||||
opts[:user_is_moderator] = true
|
redirect_to room_path(@room.uid)
|
||||||
redirect_to @meeting.join_path(current_user.name, opts)
|
|
||||||
else
|
else
|
||||||
# Send the user to a polling page that will auto join them when it starts.
|
# Otherwise, they have to wait for the meeting to start.
|
||||||
# The wait action/page handles input of name for unauthenticated users.
|
redirect_to wait_room_path(@room.uid)
|
||||||
redirect_to wait_room_path(room_uid: @room.uid)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
else
|
|
||||||
# Handle room doesn't exist.
|
|
||||||
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# GET /rooms/:room_uid/wait
|
# GET /r/:room_uid/wait
|
||||||
def wait
|
def wait
|
||||||
if @room
|
|
||||||
if @meeting.is_running?
|
if @meeting.is_running?
|
||||||
if current_user
|
if current_user
|
||||||
# If they are logged in and waiting, use their account name.
|
# If they are logged in and waiting, use their account name.
|
||||||
|
@ -55,10 +74,12 @@ class RoomsController < ApplicationController
|
||||||
redirect_to @meeting.join_path(params[:unauthenticated_join_name], default_meeting_options)
|
redirect_to @meeting.join_path(params[:unauthenticated_join_name], default_meeting_options)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
else
|
|
||||||
# Handle room doesn't exist.
|
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# GET /r/:room_uid/logout
|
||||||
|
def logout
|
||||||
|
# Redirect the owner to their room.
|
||||||
|
redirect_to room_path(@room.uid)
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
@ -66,17 +87,28 @@ class RoomsController < ApplicationController
|
||||||
# Find the room from the uid.
|
# Find the room from the uid.
|
||||||
def find_room
|
def find_room
|
||||||
@room = Room.find_by(uid: params[:room_uid])
|
@room = Room.find_by(uid: params[:room_uid])
|
||||||
|
|
||||||
|
if @room.nil?
|
||||||
|
# Handle room doesn't exist.
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
@meeting = @room.meeting
|
@meeting = @room.meeting
|
||||||
end
|
end
|
||||||
|
|
||||||
# Default, unconfigured meeting options.
|
# Ensure the user is logged into the room they are accessing.
|
||||||
def default_meeting_options
|
def verify_room_ownership
|
||||||
{
|
bring_to_room if !@room.owned_by?(current_user)
|
||||||
user_is_moderator: false,
|
end
|
||||||
meeting_logout_url: request.base_url + room_path(room_uid: @room.uid),
|
|
||||||
meeting_recorded: true,
|
# Redirects a user to their room.
|
||||||
moderator_message: "To invite someone to the meeting, send them this link:
|
def bring_to_room
|
||||||
#{request.base_url + join_room_path(room_uid: @room.uid)}"
|
if current_user
|
||||||
}
|
# Redirect authenticated users to their room.
|
||||||
|
redirect_to room_path(current_user.room.uid)
|
||||||
|
else
|
||||||
|
# Redirect unauthenticated users to root.
|
||||||
|
redirect_to root_path
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
|
@ -1,4 +1,5 @@
|
||||||
module ApplicationHelper
|
module ApplicationHelper
|
||||||
|
include MeetingsHelper
|
||||||
|
|
||||||
# Gets all configured omniauth providers.
|
# Gets all configured omniauth providers.
|
||||||
def configured_providers
|
def configured_providers
|
||||||
|
|
|
@ -5,6 +5,7 @@ class Room < ApplicationRecord
|
||||||
belongs_to :user
|
belongs_to :user
|
||||||
has_one :meeting
|
has_one :meeting
|
||||||
|
|
||||||
|
# Determines if a user owns a room.
|
||||||
def owned_by?(user)
|
def owned_by?(user)
|
||||||
return false if user.nil?
|
return false if user.nil?
|
||||||
user.room == self
|
user.room == self
|
||||||
|
@ -16,6 +17,7 @@ class Room < ApplicationRecord
|
||||||
def set_uid
|
def set_uid
|
||||||
digest = user.id.to_s + user.provider + user.username
|
digest = user.id.to_s + user.provider + user.username
|
||||||
digest += user.uid unless user.uid.nil?
|
digest += user.uid unless user.uid.nil?
|
||||||
self.uid = Digest::SHA1.hexdigest(digest)[0..12]
|
|
||||||
|
self.uid = [user.name.split(' ').first.downcase, Digest::SHA1.hexdigest(digest)[0..7]].join('-')
|
||||||
end
|
end
|
||||||
end
|
end
|
|
@ -13,9 +13,7 @@
|
||||||
<% if @room.meeting.is_running? %>
|
<% if @room.meeting.is_running? %>
|
||||||
<p>meeting is already running</p>
|
<p>meeting is already running</p>
|
||||||
<% else %>
|
<% else %>
|
||||||
<%= form_tag join_room_path, method: :get do %>
|
<%= link_to "Start Meeting", start_room_path(@room.uid) %>
|
||||||
<%= submit_tag 'Start Meeting' %>
|
|
||||||
<% end %>
|
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
||||||
<br><br>
|
<br><br>
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
<p>The join the meeting, enter a name.</p>
|
<p>The join the meeting, enter a name.</p>
|
||||||
|
|
||||||
<p>Enter a name to start a session.</p>
|
<p>Enter a name to start a session.</p>
|
||||||
<%= form_tag join_meeting_path(room_uid: @meeting.room.uid, meeting_uid: @meeting.uid) do %>
|
<%= form_tag join_room_path(room_uid: @room.uid) do %>
|
||||||
<%= text_field_tag "join_name" %>
|
<%= text_field_tag "join_name" %>
|
||||||
<%= submit_tag "Join" %>
|
<%= submit_tag "Join" %>
|
||||||
<% end %>
|
<% end %>
|
|
@ -1,10 +1,12 @@
|
||||||
Rails.application.routes.draw do
|
Rails.application.routes.draw do
|
||||||
|
|
||||||
# Room and Meeting routes.
|
# Room and Meeting routes.
|
||||||
scope '/rooms/:room_uid' do
|
scope '/r/:room_uid' do
|
||||||
get '/', to: 'rooms#index', as: :room
|
get '/', to: 'rooms#index', as: :room
|
||||||
|
match '/start', to: 'rooms#start', as: :start_room, via: [:get, :post]
|
||||||
match '/join', to: 'rooms#join', as: :join_room, via: [:get, :post]
|
match '/join', to: 'rooms#join', as: :join_room, via: [:get, :post]
|
||||||
match '/wait', to: 'rooms#wait', as: :wait_room, via: [:get, :post]
|
match '/wait', to: 'rooms#wait', as: :wait_room, via: [:get, :post]
|
||||||
|
match '/logout', to: 'rooms#logout', as: :logout_room, via: [:get, :post]
|
||||||
resources :meetings, only: [:index], param: :meeting_uid
|
resources :meetings, only: [:index], param: :meeting_uid
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -8,9 +8,6 @@ class RoomsControllerTest < ActionDispatch::IntegrationTest
|
||||||
|
|
||||||
@kitchen = rooms(:kitchen)
|
@kitchen = rooms(:kitchen)
|
||||||
@garage = rooms(:garage)
|
@garage = rooms(:garage)
|
||||||
|
|
||||||
@steve.room = @kitchen
|
|
||||||
@mark.room = @garage
|
|
||||||
end
|
end
|
||||||
|
|
||||||
test 'should redirect to root if not logged in.' do
|
test 'should redirect to root if not logged in.' do
|
||||||
|
|
|
@ -6,7 +6,9 @@
|
||||||
#
|
#
|
||||||
|
|
||||||
kitchen:
|
kitchen:
|
||||||
|
user: steve
|
||||||
uid: "13579"
|
uid: "13579"
|
||||||
|
|
||||||
garage:
|
garage:
|
||||||
|
user: mark
|
||||||
uid: "02468"
|
uid: "02468"
|
Loading…
Reference in New Issue