add support for deploying to a subdirectory

This commit is contained in:
Josh 2018-06-18 10:28:47 -04:00
parent ce6ec0acfb
commit b2b2c641da
10 changed files with 74 additions and 54 deletions

3
.gitignore vendored
View File

@ -15,6 +15,9 @@
/public/system/** /public/system/**
/public/assets/** /public/assets/**
# Ignore production paths.
/db/production
# Ignore all logfiles and tempfiles. # Ignore all logfiles and tempfiles.
/log/* /log/*
/tmp/* /tmp/*

View File

@ -5,7 +5,7 @@ class RoomsController < ApplicationController
META_LISTED = "gl-listed" META_LISTED = "gl-listed"
# POST /r # POST /
def create def create
redirect_to root_path unless current_user redirect_to root_path unless current_user
@ -24,7 +24,7 @@ class RoomsController < ApplicationController
end end
end end
# GET /r/:room_uid # GET /:room_uid
def show def show
if current_user && @room.owned_by?(current_user) if current_user && @room.owned_by?(current_user)
@recordings = @room.recordings @recordings = @room.recordings
@ -34,7 +34,7 @@ class RoomsController < ApplicationController
end end
end end
# POST /r/:room_uid # POST /:room_uid
def join def join
opts = default_meeting_options opts = default_meeting_options
@ -59,7 +59,7 @@ class RoomsController < ApplicationController
end end
end end
# DELETE /r/:room_uid # DELETE /:room_uid
def destroy def destroy
# Don't delete the users home room. # Don't delete the users home room.
@room.destroy if @room != current_user.main_room @room.destroy if @room != current_user.main_room
@ -67,7 +67,7 @@ class RoomsController < ApplicationController
redirect_to current_user.main_room redirect_to current_user.main_room
end end
# POST /r/:room_uid/start # POST /:room_uid/start
def start def start
# Join the user in and start the meeting. # Join the user in and start the meeting.
opts = default_meeting_options opts = default_meeting_options
@ -80,13 +80,13 @@ class RoomsController < ApplicationController
NotifyUserWaitingJob.set(wait: 5.seconds).perform_later(@room) NotifyUserWaitingJob.set(wait: 5.seconds).perform_later(@room)
end end
# GET /r/:room_uid/logout # GET /:room_uid/logout
def logout def logout
# Redirect the correct page. # Redirect the correct page.
redirect_to @room redirect_to @room
end end
# POST /r/:room_uid/home # POST /:room_uid/home
def home def home
current_user.main_room = @room current_user.main_room = @room
current_user.save current_user.save
@ -94,7 +94,7 @@ class RoomsController < ApplicationController
redirect_to @room redirect_to @room
end end
# POST /r/:room_uid/:record_id # POST /:room_uid/:record_id
def update_recording def update_recording
meta = { meta = {
"meta_#{META_LISTED}": (params[:state] == "public") "meta_#{META_LISTED}": (params[:state] == "public")
@ -104,7 +104,7 @@ class RoomsController < ApplicationController
redirect_to @room if res[:updated] redirect_to @room if res[:updated]
end end
# DELETE /r/:room_uid/:record_id # DELETE /:room_uid/:record_id
def delete_recording def delete_recording
@room.delete_recording(params[:record_id]) @room.delete_recording(params[:record_id])

View File

@ -3,7 +3,7 @@ class UsersController < ApplicationController
before_action :find_user, only: [:edit, :update] before_action :find_user, only: [:edit, :update]
before_action :ensure_unauthenticated, only: [:new, :create] before_action :ensure_unauthenticated, only: [:new, :create]
# POST /users # POST /u
def create def create
# Verify that GreenLight is configured to allow user signup. # Verify that GreenLight is configured to allow user signup.
return unless Rails.configuration.allow_user_signup return unless Rails.configuration.allow_user_signup
@ -28,7 +28,7 @@ class UsersController < ApplicationController
end end
end end
# GET /users/:user_uid/edit # GET /u/:user_uid/edit
def edit def edit
if current_user if current_user
redirect_to current_user.room unless @user == current_user redirect_to current_user.room unless @user == current_user
@ -37,42 +37,41 @@ class UsersController < ApplicationController
end end
end end
# PATCH /users/:user_uid # PATCH /u/:user_uid
def update def update
# Update account information if passed. if params[:setting] == "password"
@user.name = user_params[:name] if user_params[:name] # Update the users password.
@user.email = user_params[:email] if user_params[:email]
@user.image = user_params[:image] if user_params[:image]
# Custom errors not generated by validations.
errors = {} errors = {}
# Verify that the provided password is correct.
if user_params[:password]
if @user.authenticate(user_params[:password]) if @user.authenticate(user_params[:password])
# Verify that the new passwords match. # Verify that the new passwords match.
if user_params[:new_password] == user_params[:password_confirmation] if user_params[:new_password] == user_params[:password_confirmation]
@user.password = user_params[:new_password] @user.password = user_params[:new_password]
else else
# New passwords don't match. # New passwords don't match.
errors[:password_confirmation] = "'s don't match" errors[:password_confirmation] = "doesn't match"
end end
else else
# Original password is incorrect, can't update. # Original password is incorrect, can't update.
errors[:password] = "is incorrect" errors[:password] = "is incorrect"
end end
end
if @user.save! if errors.empty? && @user.save
# Notify the use that their account has been updated. # Notify the use that their account has been updated.
redirect_to edit_user_path(@user), notice: "Information successfully updated." redirect_to edit_user_path(@user), notice: "Information successfully updated."
else else
# Append custom errors. # Append custom errors.
errors.each do |k, v| @user.errors.add(k, v) end errors.each do |k, v| @user.errors.add(k, v) end
# Handle validation errors.
render :edit render :edit
end end
else
# Update the core user attributes.
if @user.update_attributes(user_params)
redirect_to edit_user_path(@user), notice: "Information successfully updated."
else
render :edit
end
end
end end
private private

View File

@ -21,7 +21,7 @@ class Room < ApplicationRecord
# Determines the invite URL for the room. # Determines the invite URL for the room.
def invite_path def invite_path
"/r/#{uid}" "#{Rails.configuration.relative_url_root}/#{uid}"
end end
# Creates a meeting on the BigBlueButton server. # Creates a meeting on the BigBlueButton server.

View File

@ -13,7 +13,7 @@ class User < ApplicationRecord
uniqueness: { case_sensitive: false }, uniqueness: { case_sensitive: false },
format: {with: /\A[\w+\-.]+@[a-z\d\-.]+\.[a-z]+\z/i } format: {with: /\A[\w+\-.]+@[a-z\d\-.]+\.[a-z]+\z/i }
validates :password, length: { minimum: 6 }, presence: true, confirmation: true, allow_blank: true, if: :greenlight_account? validates :password, length: { minimum: 6 }, confirmation: true, if: :greenlight_account?
# We don't want to require password validations on all accounts. # We don't want to require password validations on all accounts.
has_secure_password(validations: false) has_secure_password(validations: false)
@ -57,7 +57,7 @@ class User < ApplicationRecord
end end
def twitter_image(auth) def twitter_image(auth)
auth['info']['image'].gsub!("_normal", "") auth['info']['image'].gsub("_normal", "")
end end
def google_name(auth) def google_name(auth)

View File

@ -2,4 +2,6 @@
require_relative 'config/environment' require_relative 'config/environment'
run Rails.application map Greenlight::Application.config.relative_url_root || "/" do
run Rails.application
end

View File

@ -6,7 +6,7 @@ require 'rails/all'
# you've limited to :test, :development, or :production. # you've limited to :test, :development, or :production.
Bundler.require(*Rails.groups) Bundler.require(*Rails.groups)
module Greenlight20 module Greenlight
class Application < Rails::Application class Application < Rails::Application
# Settings in config/environments/* take precedence over those specified here. # Settings in config/environments/* take precedence over those specified here.
# Application configuration should go into files in config/initializers # Application configuration should go into files in config/initializers

View File

@ -83,4 +83,11 @@ Rails.application.configure do
# Do not dump schema after migrations. # Do not dump schema after migrations.
config.active_record.dump_schema_after_migration = false config.active_record.dump_schema_after_migration = false
# Set the relative url root for deployment to a subdirectory.
if ENV['RELATIVE_URL_ROOT'].present?
config.relative_url_root = ENV['RELATIVE_URL_ROOT']
else
config.relative_url_root = ""
end
end end

View File

@ -5,29 +5,12 @@ Rails.application.routes.draw do
match '/422', to: 'errors#unprocessable', via: :all match '/422', to: 'errors#unprocessable', via: :all
match '/500', to: 'errors#internal_error', via: :all match '/500', to: 'errors#internal_error', via: :all
# Room resources.
resources :rooms, only: [:create, :show, :destroy], param: :room_uid, path: '/r'
# Extended room routes.
scope '/r/:room_uid' do
post '/', to: 'rooms#join'
post '/start', to: 'rooms#start', as: :start_room
get '/logout', to: 'rooms#logout', as: :logout_room
post '/home', to: 'rooms#home', as: :make_home
# Mange recordings.
scope '/:record_id' do
post '/', to: 'rooms#update_recording', as: :update_recording
delete '/', to: 'rooms#delete_recording', as: :delete_recording
end
end
# Signup routes. # Signup routes.
get '/signup', to: 'users#new', as: :signup get '/signup', to: 'users#new', as: :signup
post '/signup', to: 'users#create', as: :create_user post '/signup', to: 'users#create', as: :create_user
# User resources. # User resources.
scope '/users' do scope '/u' do
get '/:user_uid/edit', to: 'users#edit', as: :edit_user get '/:user_uid/edit', to: 'users#edit', as: :edit_user
patch '/:user_uid/edit', to: 'users#update', as: :update_user patch '/:user_uid/edit', to: 'users#update', as: :update_user
@ -45,5 +28,22 @@ Rails.application.routes.draw do
match '/auth/:provider/callback', to: 'sessions#omniauth', via: [:get, :post], as: :omniauth_session match '/auth/:provider/callback', to: 'sessions#omniauth', via: [:get, :post], as: :omniauth_session
get '/auth/failure', to: 'sessions#fail' get '/auth/failure', to: 'sessions#fail'
# Room resources.
resources :rooms, only: [:create, :show, :destroy], param: :room_uid, path: '/'
# Extended room routes.
scope '/:room_uid' do
post '/', to: 'rooms#join'
post '/start', to: 'rooms#start', as: :start_room
get '/logout', to: 'rooms#logout', as: :logout_room
post '/home', to: 'rooms#home', as: :make_home
# Mange recordings.
scope '/:record_id' do
post '/', to: 'rooms#update_recording', as: :update_recording
delete '/', to: 'rooms#delete_recording', as: :delete_recording
end
end
root to: 'main#index' root to: 'main#index'
end end

View File

@ -46,3 +46,12 @@ TWITTER_SECRET=
# Omniauth. This will allow users to create an account at www.hostname.com/signup # Omniauth. This will allow users to create an account at www.hostname.com/signup
# and use that account to fully interact with GreenLight. # and use that account to fully interact with GreenLight.
ALLOW_GREENLIGHT_ACCOUNTS=false ALLOW_GREENLIGHT_ACCOUNTS=false
# Prefix for the applications root URL.
# Useful for deploying the application to a subdirectory, which is highly recommended
# if deploying on a BigBlueButton server. Keep in mind that if you change this, you'll
# have to update your authentication callback URL's to reflect this change.
#
# The recommended prefix is "/gl".
#
RELATIVE_URL_ROOT=/gl