From 2b065eb7fa47d7005ae0798efb6aef5cbb23be4e Mon Sep 17 00:00:00 2001 From: Josh Date: Mon, 11 Jun 2018 13:05:54 -0400 Subject: [PATCH] handle errors and fix join form --- app/assets/javascripts/errors.coffee | 3 + app/assets/stylesheets/application.scss | 7 ++ app/assets/stylesheets/errors.scss | 3 + app/controllers/application_controller.rb | 8 --- app/controllers/errors_controller.rb | 14 ++++ app/controllers/rooms_controller.rb | 12 ++-- app/helpers/errors_helper.rb | 2 + app/models/room.rb | 37 +++++----- app/views/errors/internal_error.html.erb | 7 ++ app/views/errors/not_found.html.erb | 8 +++ app/views/errors/unprocessable.html.erb | 7 ++ app/views/rooms/join.html.erb | 7 +- .../shared/components/_subtitle.html.erb | 2 + config/application.rb | 4 +- config/environments/development.rb | 4 +- config/routes.rb | 5 ++ db/migrate/20180504131705_create_rooms.rb | 1 - db/schema.rb | 2 - public/404.html | 67 ------------------- public/422.html | 67 ------------------- public/500.html | 66 ------------------ spec/controllers/errors_controller_spec.rb | 5 ++ spec/helpers/errors_helper_spec.rb | 15 +++++ 23 files changed, 114 insertions(+), 239 deletions(-) create mode 100644 app/assets/javascripts/errors.coffee create mode 100644 app/assets/stylesheets/errors.scss create mode 100644 app/controllers/errors_controller.rb create mode 100644 app/helpers/errors_helper.rb create mode 100644 app/views/errors/internal_error.html.erb create mode 100644 app/views/errors/not_found.html.erb create mode 100644 app/views/errors/unprocessable.html.erb delete mode 100644 public/404.html delete mode 100644 public/422.html delete mode 100644 public/500.html create mode 100644 spec/controllers/errors_controller_spec.rb create mode 100644 spec/helpers/errors_helper_spec.rb diff --git a/app/assets/javascripts/errors.coffee b/app/assets/javascripts/errors.coffee new file mode 100644 index 00000000..24f83d18 --- /dev/null +++ b/app/assets/javascripts/errors.coffee @@ -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/ diff --git a/app/assets/stylesheets/application.scss b/app/assets/stylesheets/application.scss index 1bf2c6ce..0c7451b0 100644 --- a/app/assets/stylesheets/application.scss +++ b/app/assets/stylesheets/application.scss @@ -85,6 +85,13 @@ a { width: 60%; } +.center-page { + position: absolute; + top: 50%; + left:50%; + transform: translate(-50%,-50%); +} + iframe{ position: absolute; top: 0; diff --git a/app/assets/stylesheets/errors.scss b/app/assets/stylesheets/errors.scss new file mode 100644 index 00000000..03da2c4f --- /dev/null +++ b/app/assets/stylesheets/errors.scss @@ -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/ diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index e9d6f23b..cced7164 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -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? diff --git a/app/controllers/errors_controller.rb b/app/controllers/errors_controller.rb new file mode 100644 index 00000000..fd44434d --- /dev/null +++ b/app/controllers/errors_controller.rb @@ -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 diff --git a/app/controllers/rooms_controller.rb b/app/controllers/rooms_controller.rb index 8aed5af7..10769815 100644 --- a/app/controllers/rooms_controller.rb +++ b/app/controllers/rooms_controller.rb @@ -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. diff --git a/app/helpers/errors_helper.rb b/app/helpers/errors_helper.rb new file mode 100644 index 00000000..8e3b415c --- /dev/null +++ b/app/helpers/errors_helper.rb @@ -0,0 +1,2 @@ +module ErrorsHelper +end diff --git a/app/models/room.rb b/app/models/room.rb index 4e45862a..a8244ed0 100644 --- a/app/models/room.rb +++ b/app/models/room.rb @@ -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. diff --git a/app/views/errors/internal_error.html.erb b/app/views/errors/internal_error.html.erb new file mode 100644 index 00000000..01489b7a --- /dev/null +++ b/app/views/errors/internal_error.html.erb @@ -0,0 +1,7 @@ +
+

Oh no!

+

Looks like something went wrong on our end.

+ <%= link_to root_url do %> +

Return to home page.

+ <% end %> +
diff --git a/app/views/errors/not_found.html.erb b/app/views/errors/not_found.html.erb new file mode 100644 index 00000000..f4e15fa4 --- /dev/null +++ b/app/views/errors/not_found.html.erb @@ -0,0 +1,8 @@ +
+

Whoops!

+

Looks like we can't find that resource.

+

Is it possible its been removed?

+ <%= link_to root_url do %> +

Return to home page.

+ <% end %> +
diff --git a/app/views/errors/unprocessable.html.erb b/app/views/errors/unprocessable.html.erb new file mode 100644 index 00000000..a2926872 --- /dev/null +++ b/app/views/errors/unprocessable.html.erb @@ -0,0 +1,7 @@ +
+

Oops!

+

Request is unprocessable.

+ <%= link_to root_url do %> +

Return to home page.

+ <% end %> +
diff --git a/app/views/rooms/join.html.erb b/app/views/rooms/join.html.erb index afdde7bb..84d624fa 100644 --- a/app/views/rooms/join.html.erb +++ b/app/views/rooms/join.html.erb @@ -1,7 +1,12 @@ <%= render 'shared/room_event' do %> <%= form_for room_path, method: :post do |f| %>
- <%= 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? %> <%= f.submit "Join", class: "btn btn-primary px-7 main-large" %> diff --git a/app/views/shared/components/_subtitle.html.erb b/app/views/shared/components/_subtitle.html.erb index 4507f0cd..fee8b983 100644 --- a/app/views/shared/components/_subtitle.html.erb +++ b/app/views/shared/components/_subtitle.html.erb @@ -3,6 +3,7 @@

<%= subtitle %>

<% if search %> + <% end %>
diff --git a/config/application.rb b/config/application.rb index 523afd10..b0836848 100644 --- a/config/application.rb +++ b/config/application.rb @@ -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 \ No newline at end of file +end diff --git a/config/environments/development.rb b/config/environments/development.rb index 6f719704..4b601329 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -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? diff --git a/config/routes.rb b/config/routes.rb index 633ef723..a95da457 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -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' diff --git a/db/migrate/20180504131705_create_rooms.rb b/db/migrate/20180504131705_create_rooms.rb index 2bddf940..995d108e 100644 --- a/db/migrate/20180504131705_create_rooms.rb +++ b/db/migrate/20180504131705_create_rooms.rb @@ -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 diff --git a/db/schema.rb b/db/schema.rb index 9f01aaca..c602c01f 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -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" diff --git a/public/404.html b/public/404.html deleted file mode 100644 index 2be3af26..00000000 --- a/public/404.html +++ /dev/null @@ -1,67 +0,0 @@ - - - - The page you were looking for doesn't exist (404) - - - - - - -
-
-

The page you were looking for doesn't exist.

-

You may have mistyped the address or the page may have moved.

-
-

If you are the application owner check the logs for more information.

-
- - diff --git a/public/422.html b/public/422.html deleted file mode 100644 index c08eac0d..00000000 --- a/public/422.html +++ /dev/null @@ -1,67 +0,0 @@ - - - - The change you wanted was rejected (422) - - - - - - -
-
-

The change you wanted was rejected.

-

Maybe you tried to change something you didn't have access to.

-
-

If you are the application owner check the logs for more information.

-
- - diff --git a/public/500.html b/public/500.html deleted file mode 100644 index 78a030af..00000000 --- a/public/500.html +++ /dev/null @@ -1,66 +0,0 @@ - - - - We're sorry, but something went wrong (500) - - - - - - -
-
-

We're sorry, but something went wrong.

-
-

If you are the application owner check the logs for more information.

-
- - diff --git a/spec/controllers/errors_controller_spec.rb b/spec/controllers/errors_controller_spec.rb new file mode 100644 index 00000000..34b9b5ed --- /dev/null +++ b/spec/controllers/errors_controller_spec.rb @@ -0,0 +1,5 @@ +require 'rails_helper' + +RSpec.describe ErrorsController, type: :controller do + +end diff --git a/spec/helpers/errors_helper_spec.rb b/spec/helpers/errors_helper_spec.rb new file mode 100644 index 00000000..e3592037 --- /dev/null +++ b/spec/helpers/errors_helper_spec.rb @@ -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