Skip to content

Commit

Permalink
Merge branch 'v2'
Browse files Browse the repository at this point in the history
  • Loading branch information
jfederico committed Jul 29, 2019
2 parents beadd4c + 403a7c4 commit 2775b18
Show file tree
Hide file tree
Showing 7 changed files with 12 additions and 46 deletions.
11 changes: 1 addition & 10 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,6 @@ class ApplicationController < ActionController::Base
# Manually handle BigBlueButton errors
rescue_from BigBlueButton::BigBlueButtonException, with: :handle_bigbluebutton_error

# Manually Handle errors when application is in readonly mode
rescue_from ActiveRecord::ReadOnlyRecord, with: :handle_readonly_error

protect_from_forgery with: :exception

MEETING_NAME_LIMIT = 90
Expand All @@ -56,7 +53,7 @@ def migration_error?
end

def maintenance_mode?
if ENV["MAINTENANCE_MODE"] == "full"
if ENV["MAINTENANCE_MODE"] == "true"
render "errors/greenlight_error", status: 503, formats: :html,
locals: {
status_code: 503,
Expand Down Expand Up @@ -202,10 +199,4 @@ def check_user_role
def handle_bigbluebutton_error
render "errors/bigbluebutton_error"
end

# Manually Handle errors when application is in readonly mode
def handle_readonly_error
flash.clear
redirect_to request.referrer || root_path, flash: { alert: I18n.t("errors.maintenance.readonly") }
end
end
4 changes: 0 additions & 4 deletions app/models/application_record.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,4 @@ class ApplicationRecord < ActiveRecord::Base
def to_param
uid
end

def readonly?
ENV["MAINTENANCE_MODE"] == "readonly"
end
end
2 changes: 1 addition & 1 deletion app/models/room.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def start_session(options = {})
# Update session info.
unless meeting[:messageKey] == 'duplicateWarning'
update_attributes(sessions: sessions + 1,
last_session: DateTime.now) unless ENV["MAINTENANCE_MODE"] == "readonly"
last_session: DateTime.now)
end
rescue BigBlueButton::BigBlueButtonException => e
puts "BigBlueButton failed on create: #{e.key}: #{e.message}"
Expand Down
31 changes: 7 additions & 24 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,31 +54,14 @@ class << self
def from_omniauth(auth)
# Provider is the customer name if in loadbalanced config mode
provider = auth['provider'] == "bn_launcher" ? auth['info']['customer'] : auth['provider']
u = find_by(social_uid: auth['uid'], provider: provider)

if ENV["MAINTENANCE_MODE"] == "readonly"
raise ActiveRecord::ReadOnlyRecord if u.nil?

return u
find_or_initialize_by(social_uid: auth['uid'], provider: provider).tap do |u|
u.name = auth_name(auth) unless u.name
u.username = auth_username(auth) unless u.username
u.email = auth_email(auth)
u.image = auth_image(auth)
u.email_verified = true
u.save!
end

return User.create(
name: auth_name(auth),
username: auth_username(auth),
email: auth_email(auth),
social_uid: auth['uid'],
provider: provider,
image: auth_image(auth),
email_verified: true
) if u.nil?

u.name = auth_name(auth) unless u.name
u.username = auth_username(auth) unless u.username
u.email = auth_email(auth)
u.image = auth_image(auth) unless u.image
u.email_verified = true
u.save!
u
end

private
Expand Down
6 changes: 2 additions & 4 deletions bin/start
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,8 @@ fi

bundle exec rake db:create

if [ "$MAINTENANCE_MODE" != "readonly" ] && [ "$MAINTENANCE_MODE" != "full" ]; then
if ! bundle exec rake db:migrate ; then
export DB_MIGRATE_FAILED=1
fi
if ! bundle exec rake db:migrate ; then
export DB_MIGRATE_FAILED=1
fi

bundle exec rake assets:precompile
Expand Down
1 change: 0 additions & 1 deletion config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,6 @@ en:
maintenance:
message: Sorry, we're down for maintenance.
help: We'll be back soon!
readonly: This application is under maintenance. You will not be able to perform this action
migration_error:
contact_admin: If you are not an administrator, please contact one.
continue: I'd like to stay using 1.0.
Expand Down
3 changes: 1 addition & 2 deletions sample.env
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,7 @@ ENABLE_GOOGLE_CALENDAR_BUTTON=
# Set the application into Maintenance Mode
#
# Current options supported:
# full: Renders an error page that does not allow users to access any of the features in the application
# readonly: Sets the database to readonly mode, which allows users to use actions that dont write to the database
# true: Renders an error page that does not allow users to access any of the features in the application
# false: Application runs normally
MAINTENANCE_MODE=false

Expand Down

0 comments on commit 2775b18

Please sign in to comment.