handle errors and fix join form

This commit is contained in:
Josh 2018-06-11 13:05:54 -04:00
parent 2b0f75e62b
commit 2b065eb7fa
23 changed files with 114 additions and 239 deletions

View File

@ -0,0 +1,3 @@
# Place all the behaviors and hooks related to the matching controller here.
# All this logic will automatically be available in application.js.
# You can use CoffeeScript in this file: http://coffeescript.org/

View File

@ -85,6 +85,13 @@ a {
width: 60%;
}
.center-page {
position: absolute;
top: 50%;
left:50%;
transform: translate(-50%,-50%);
}
iframe{
position: absolute;
top: 0;

View File

@ -0,0 +1,3 @@
// Place all the styles related to the Errors controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/

View File

@ -35,14 +35,6 @@ class ApplicationController < ActionController::Base
end
helper_method :allow_greenlight_users?
# 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
# Determines if a form field needs the is-invalid class.
def form_is_invalid?(obj, key)
'is-invalid' if !obj.errors.messages[key].empty?

View File

@ -0,0 +1,14 @@
class ErrorsController < ApplicationController
def not_found
render status: 404
end
def unprocessable
render status: 422
end
def internal_error
render status: 500
end
end

View File

@ -35,14 +35,18 @@ class RoomsController < ApplicationController
opts = default_meeting_options
# Assign join name if passed.
if params[@room.invite_path]
if params[@room.invite_path][:join_name]
@join_name = params[@room.invite_path][:join_name]
else
# Join name not passed.
return
end
if @room.is_running?
if current_user
redirect_to @room.join_path(current_user, opts)
elsif join_name = params[:join_name] || params[@room.invite_path][:join_name]
redirect_to @room.join_path(current_user.name, opts, current_user.uid)
else
join_name = params[@room.invite_path][:join_name]
redirect_to @room.join_path(join_name, opts)
end
else
@ -65,7 +69,7 @@ class RoomsController < ApplicationController
opts = default_meeting_options
opts[:user_is_moderator] = true
redirect_to @room.join_path(current_user, opts)
redirect_to @room.join_path(current_user.name, opts, current_user.uid)
# Notify users that the room has started.
# Delay 5 seconds to allow for server start, although the request will retry until it succeeds.

View File

@ -0,0 +1,2 @@
module ErrorsHelper
end

View File

@ -7,7 +7,6 @@ class Room < ApplicationRecord
belongs_to :owner, class_name: 'User', foreign_key: :user_id
has_one :meeting
ROOM_ICONS = %w(circle star certificate play cloud heart square bookmark cog)
RETURNCODE_SUCCESS = "SUCCESS"
# Determines if a user owns a room.
@ -21,19 +20,6 @@ class Room < ApplicationRecord
bbb.is_meeting_running?(bbb_id)
end
# Retrieves all the users in a room.
def participants
begin
res = bbb.get_meeting_info(bbb_id, nil)
res[:attendees].map do |att|
User.find_by(uid: att[:userID], name: att[:fullName])
end
rescue BigBlueButton::BigBlueButtonException => exc
# The meeting is most likely not running.
[]
end
end
# Determines the invite URL for the room.
def invite_path
"/r/#{uid}"
@ -68,7 +54,7 @@ class Room < ApplicationRecord
end
# Returns a URL to join a user into a meeting.
def join_path(user, options = {})
def join_path(name, options = {}, uid = nil)
# Create the meeting if it isn't running.
start_session(options) unless is_running?
@ -95,10 +81,10 @@ class Room < ApplicationRecord
end
# Generate the join URL.
if user.is_a?(User)
bbb.join_meeting_url(bbb_id, user.name, password, {userID: user.uid})
if uid
bbb.join_meeting_url(bbb_id, name, password, {userID: uid})
else
bbb.join_meeting_url(bbb_id, user, password)
bbb.join_meeting_url(bbb_id, name, password)
end
end
@ -109,6 +95,19 @@ class Room < ApplicationRecord
})
end
# Retrieves all the users in a room.
def participants
begin
res = bbb.get_meeting_info(bbb_id, nil)
res[:attendees].map do |att|
User.find_by(uid: att[:userID], name: att[:fullName])
end
rescue BigBlueButton::BigBlueButtonException => exc
# The meeting is most likely not running.
[]
end
end
# Fetches all recordings for a meeting.
def recordings
res = bbb.get_recordings(meetingID: bbb_id)
@ -168,8 +167,6 @@ class Room < ApplicationRecord
def setup
self.uid = [owner.firstname, (0...9).map { (65 + rand(26)).chr }.join].join('-').downcase
self.bbb_id = Digest::SHA1.hexdigest(Rails.application.secrets[:secret_key_base] + Time.now.to_i.to_s).to_s
self.icon = ROOM_ICONS.sample
end
# Rereives the loadbalanced BigBlueButton credentials for a user.

View File

@ -0,0 +1,7 @@
<div class="text-center center-page">
<h1 class="display-2 font-weight-400">Oh no!</h1>
<h3>Looks like something went wrong on our end.</h3>
<%= link_to root_url do %>
<h4>Return to home page.</h4>
<% end %>
</div>

View File

@ -0,0 +1,8 @@
<div class="text-center center-page">
<h1 class="display-2 font-weight-400">Whoops!</h1>
<h2>Looks like we can't find that resource.</h2>
<h3>Is it possible its been removed?</h3>
<%= link_to root_url do %>
<h4>Return to home page.</h4>
<% end %>
</div>

View File

@ -0,0 +1,7 @@
<div class="text-center center-page">
<h1 class="display-2 font-weight-400">Oops!</h1>
<h3>Request is unprocessable.</h3>
<%= link_to root_url do %>
<h4>Return to home page.</h4>
<% end %>
</div>

View File

@ -1,7 +1,12 @@
<%= render 'shared/room_event' do %>
<%= form_for room_path, method: :post do |f| %>
<div class="input-group" style="height: 48px;">
<%= f.text_field :join_name, class: "form-control main-large", placeholder: "Enter your name!", value: "#{current_user ? current_user.name : ''}" %>
<%= f.text_field :join_name,
required: true,
class: "form-control main-large",
placeholder: "Enter your name!",
value: "#{current_user ? current_user.name : ''}",
readonly: !current_user.nil? %>
<span class="input-group-append">
<%= f.submit "Join", class: "btn btn-primary px-7 main-large" %>
</span>

View File

@ -3,6 +3,7 @@
<p class="subtitle"><%= subtitle %></p>
</div>
<% if search %>
<!--
<div class="col-3">
<div class="input-icon">
<span class="input-icon-addon">
@ -11,6 +12,7 @@
<input type="text" class="form-control btn-pill" placeholder="Search...">
</div>
</div>
-->
<% end %>
</div>
<hr class="mt-0">

View File

@ -12,6 +12,8 @@ module Greenlight20
# Application configuration should go into files in config/initializers
# -- all .rb files in that directory are automatically loaded.
config.exceptions_app = self.routes
config.loadbalanced_configuration = (ENV["USE_LOADBALANCED_CONFIGURATION"] == "true")
# Setup BigBlueButton configuration.
@ -33,4 +35,4 @@ module Greenlight20
# Determine if GreenLight should allow non-omniauth signup/login.
config.greenlight_accounts = (ENV['ALLOW_GREENLIGHT_ACCOUNTS'] == "true")
end
end
end

View File

@ -9,8 +9,8 @@ Rails.application.configure do
# Do not eager load code on boot.
config.eager_load = false
# Show full error reports.
config.consider_all_requests_local = true
# Show custom error pages in development.
config.consider_all_requests_local = false
# Enable/disable caching. By default caching is disabled.
if Rails.root.join('tmp/caching-dev.txt').exist?

View File

@ -1,5 +1,10 @@
Rails.application.routes.draw do
# Error routes.
match '/404', to: 'errors#not_found', via: :all
match '/422', to: 'errors#unprocessable', via: :all
match '/500', to: 'errors#internal_error', via: :all
# Room resources.
resources :rooms, only: [:create, :show, :destroy], param: :room_uid, path: '/r'

View File

@ -5,7 +5,6 @@ class CreateRooms < ActiveRecord::Migration[5.0]
t.string :name, index: true
t.string :uid, index: true
t.string :bbb_id, index: true
t.string :icon, index: true
t.integer :sessions, index: true, default: 0
t.datetime :last_session, index: true

View File

@ -17,13 +17,11 @@ ActiveRecord::Schema.define(version: 20180504131705) do
t.string "name"
t.string "uid"
t.string "bbb_id"
t.string "icon"
t.integer "sessions", default: 0
t.datetime "last_session"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.index ["bbb_id"], name: "index_rooms_on_bbb_id"
t.index ["icon"], name: "index_rooms_on_icon"
t.index ["last_session"], name: "index_rooms_on_last_session"
t.index ["name"], name: "index_rooms_on_name"
t.index ["sessions"], name: "index_rooms_on_sessions"

View File

@ -1,67 +0,0 @@
<!DOCTYPE html>
<html>
<head>
<title>The page you were looking for doesn't exist (404)</title>
<meta name="viewport" content="width=device-width,initial-scale=1">
<style>
.rails-default-error-page {
background-color: #EFEFEF;
color: #2E2F30;
text-align: center;
font-family: arial, sans-serif;
margin: 0;
}
.rails-default-error-page div.dialog {
width: 95%;
max-width: 33em;
margin: 4em auto 0;
}
.rails-default-error-page div.dialog > div {
border: 1px solid #CCC;
border-right-color: #999;
border-left-color: #999;
border-bottom-color: #BBB;
border-top: #B00100 solid 4px;
border-top-left-radius: 9px;
border-top-right-radius: 9px;
background-color: white;
padding: 7px 12% 0;
box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
}
.rails-default-error-page h1 {
font-size: 100%;
color: #730E15;
line-height: 1.5em;
}
.rails-default-error-page div.dialog > p {
margin: 0 0 1em;
padding: 1em;
background-color: #F7F7F7;
border: 1px solid #CCC;
border-right-color: #999;
border-left-color: #999;
border-bottom-color: #999;
border-bottom-left-radius: 4px;
border-bottom-right-radius: 4px;
border-top-color: #DADADA;
color: #666;
box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
}
</style>
</head>
<body class="rails-default-error-page">
<!-- This file lives in public/404.html -->
<div class="dialog">
<div>
<h1>The page you were looking for doesn't exist.</h1>
<p>You may have mistyped the address or the page may have moved.</p>
</div>
<p>If you are the application owner check the logs for more information.</p>
</div>
</body>
</html>

View File

@ -1,67 +0,0 @@
<!DOCTYPE html>
<html>
<head>
<title>The change you wanted was rejected (422)</title>
<meta name="viewport" content="width=device-width,initial-scale=1">
<style>
.rails-default-error-page {
background-color: #EFEFEF;
color: #2E2F30;
text-align: center;
font-family: arial, sans-serif;
margin: 0;
}
.rails-default-error-page div.dialog {
width: 95%;
max-width: 33em;
margin: 4em auto 0;
}
.rails-default-error-page div.dialog > div {
border: 1px solid #CCC;
border-right-color: #999;
border-left-color: #999;
border-bottom-color: #BBB;
border-top: #B00100 solid 4px;
border-top-left-radius: 9px;
border-top-right-radius: 9px;
background-color: white;
padding: 7px 12% 0;
box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
}
.rails-default-error-page h1 {
font-size: 100%;
color: #730E15;
line-height: 1.5em;
}
.rails-default-error-page div.dialog > p {
margin: 0 0 1em;
padding: 1em;
background-color: #F7F7F7;
border: 1px solid #CCC;
border-right-color: #999;
border-left-color: #999;
border-bottom-color: #999;
border-bottom-left-radius: 4px;
border-bottom-right-radius: 4px;
border-top-color: #DADADA;
color: #666;
box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
}
</style>
</head>
<body class="rails-default-error-page">
<!-- This file lives in public/422.html -->
<div class="dialog">
<div>
<h1>The change you wanted was rejected.</h1>
<p>Maybe you tried to change something you didn't have access to.</p>
</div>
<p>If you are the application owner check the logs for more information.</p>
</div>
</body>
</html>

View File

@ -1,66 +0,0 @@
<!DOCTYPE html>
<html>
<head>
<title>We're sorry, but something went wrong (500)</title>
<meta name="viewport" content="width=device-width,initial-scale=1">
<style>
.rails-default-error-page {
background-color: #EFEFEF;
color: #2E2F30;
text-align: center;
font-family: arial, sans-serif;
margin: 0;
}
.rails-default-error-page div.dialog {
width: 95%;
max-width: 33em;
margin: 4em auto 0;
}
.rails-default-error-page div.dialog > div {
border: 1px solid #CCC;
border-right-color: #999;
border-left-color: #999;
border-bottom-color: #BBB;
border-top: #B00100 solid 4px;
border-top-left-radius: 9px;
border-top-right-radius: 9px;
background-color: white;
padding: 7px 12% 0;
box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
}
.rails-default-error-page h1 {
font-size: 100%;
color: #730E15;
line-height: 1.5em;
}
.rails-default-error-page div.dialog > p {
margin: 0 0 1em;
padding: 1em;
background-color: #F7F7F7;
border: 1px solid #CCC;
border-right-color: #999;
border-left-color: #999;
border-bottom-color: #999;
border-bottom-left-radius: 4px;
border-bottom-right-radius: 4px;
border-top-color: #DADADA;
color: #666;
box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
}
</style>
</head>
<body class="rails-default-error-page">
<!-- This file lives in public/500.html -->
<div class="dialog">
<div>
<h1>We're sorry, but something went wrong.</h1>
</div>
<p>If you are the application owner check the logs for more information.</p>
</div>
</body>
</html>

View File

@ -0,0 +1,5 @@
require 'rails_helper'
RSpec.describe ErrorsController, type: :controller do
end

View File

@ -0,0 +1,15 @@
require 'rails_helper'
# Specs in this file have access to a helper object that includes
# the ErrorsHelper. For example:
#
# describe ErrorsHelper do
# describe "string concat" do
# it "concats two strings with spaces" do
# expect(helper.concat_strings("this","that")).to eq("this that")
# end
# end
# end
RSpec.describe ErrorsHelper, type: :helper do
pending "add some examples to (or delete) #{__FILE__}"
end