From 89f36c17665708376786240bd76d422c3a4367eb Mon Sep 17 00:00:00 2001 From: farhatahmad <35435341+farhatahmad@users.noreply.github.com> Date: Wed, 14 Aug 2019 14:25:52 -0400 Subject: [PATCH] GRN2-224: Added event logs and production caching (#739) * Added event logs and production caching * Added Support: before logs for easy identification * Added more Support for log errors * Reverted change to assets precompile check * Added vendor assets to precompile list * Travis fix --- app/assets/stylesheets/application.scss | 3 +-- app/controllers/account_activations_controller.rb | 2 +- app/controllers/admins_controller.rb | 2 +- app/controllers/password_resets_controller.rb | 2 +- app/controllers/rooms_controller.rb | 10 ++++++++++ app/controllers/sessions_controller.rb | 6 +++++- app/controllers/users_controller.rb | 12 +++++++++--- app/helpers/sessions_helper.rb | 2 ++ config/environments/production.rb | 10 +++++++++- config/initializers/assets.rb | 4 ++-- 10 files changed, 41 insertions(+), 12 deletions(-) diff --git a/app/assets/stylesheets/application.scss b/app/assets/stylesheets/application.scss index 19325c67..27b70c7b 100644 --- a/app/assets/stylesheets/application.scss +++ b/app/assets/stylesheets/application.scss @@ -44,8 +44,7 @@ @import "sessions"; @import "monolith.min.css"; -@import url(https://fonts.googleapis.com/css?family=Source+Sans+Pro:300,300i,400,400i,500,500i,600,600i,700,700i&subset=latin-ext); -@import url(https://fonts.googleapis.com/css?family=Roboto:400,500); +@import url(https://fonts.googleapis.com/css?family=Roboto:400,500|Source+Sans+Pro:300,300i,400,400i,600,600i,700,700i&display=swap&subset=latin-ext); * { outline: none !important; diff --git a/app/controllers/account_activations_controller.rb b/app/controllers/account_activations_controller.rb index 1aa32ca5..fd7450c3 100644 --- a/app/controllers/account_activations_controller.rb +++ b/app/controllers/account_activations_controller.rb @@ -52,7 +52,7 @@ class AccountActivationsController < ApplicationController begin send_activation_email(@user) rescue => e - logger.error "Error in email delivery: #{e}" + logger.error "Support: Error in email delivery: #{e}" flash[:alert] = I18n.t(params[:message], default: I18n.t("delivery_error")) else flash[:success] = I18n.t("email_sent", email_type: t("verify.verification")) diff --git a/app/controllers/admins_controller.rb b/app/controllers/admins_controller.rb index a3be2280..d133ba9c 100644 --- a/app/controllers/admins_controller.rb +++ b/app/controllers/admins_controller.rb @@ -97,7 +97,7 @@ class AdminsController < ApplicationController send_invitation_email(current_user.name, email, invitation.invite_token) rescue => e - logger.error "Error in email delivery: #{e}" + logger.error "Support: Error in email delivery: #{e}" flash[:alert] = I18n.t(params[:message], default: I18n.t("delivery_error")) else flash[:success] = I18n.t("administrator.flash.invite", email: email) diff --git a/app/controllers/password_resets_controller.rb b/app/controllers/password_resets_controller.rb index 707af55e..84ccb389 100644 --- a/app/controllers/password_resets_controller.rb +++ b/app/controllers/password_resets_controller.rb @@ -39,7 +39,7 @@ class PasswordResetsController < ApplicationController redirect_to new_password_reset_path end rescue => e - logger.error "Error in email delivery: #{e}" + logger.error "Support: Error in email delivery: #{e}" redirect_to root_path, alert: I18n.t(params[:message], default: I18n.t("delivery_error")) end diff --git a/app/controllers/rooms_controller.rb b/app/controllers/rooms_controller.rb index 1c0867cf..227addb2 100644 --- a/app/controllers/rooms_controller.rb +++ b/app/controllers/rooms_controller.rb @@ -42,6 +42,8 @@ class RoomsController < ApplicationController room_params[:require_moderator_approval], room_params[:anyone_can_start], room_params[:all_join_moderator]) if @room.save + logger.info("Support: #{current_user.email} has created a new room #{@room.uid}.") + if room_params[:auto_join] == "1" start else @@ -138,6 +140,8 @@ class RoomsController < ApplicationController .uniq[0..2] end + logger.info("Support: #{current_user.present? ? current_user.email : @join_name} is joining room #{@room.uid}") + join_room(opts) end @@ -166,6 +170,8 @@ class RoomsController < ApplicationController # POST /:room_uid/start def start + logger.info("Support: #{current_user.email} is starting room #{@room.uid}") + # Join the user in and start the meeting. opts = default_meeting_options opts[:user_is_moderator] = true @@ -178,6 +184,8 @@ class RoomsController < ApplicationController begin redirect_to @room.join_path(current_user.name, opts, current_user.uid) rescue BigBlueButton::BigBlueButtonException => e + logger.error("Support: #{@room.uid} start failed: #{e}") + redirect_to room_path, alert: I18n.t(e.key.to_s.underscore, default: I18n.t("bigbluebutton_exception")) end @@ -208,6 +216,8 @@ class RoomsController < ApplicationController # GET /:room_uid/logout def logout + logger.info("Support: #{current_user.present? ? current_user.email : 'Guest'} has left room #{@room.uid}") + # Redirect the correct page. redirect_to @room end diff --git a/app/controllers/sessions_controller.rb b/app/controllers/sessions_controller.rb index 2a319eb0..c56efc39 100644 --- a/app/controllers/sessions_controller.rb +++ b/app/controllers/sessions_controller.rb @@ -31,6 +31,8 @@ class SessionsController < ApplicationController # POST /users/login def create + logger.info("Support: #{session_params[:email]} is attempting to login.") + admin = User.find_by(email: session_params[:email]) if admin&.has_role? :super_admin user = admin @@ -118,6 +120,8 @@ class SessionsController < ApplicationController user = User.from_omniauth(@auth) + logger.info("Support: Auth user #{user.email} is attempting to login.") + # Add pending role if approval method and is a new user if approval_registration && !@user_exists user.add_role :pending @@ -143,7 +147,7 @@ class SessionsController < ApplicationController end end rescue => e - logger.error "Error authenticating via omniauth: #{e}" + logger.error "Support: Error authenticating via omniauth: #{e}" omniauth_fail end end diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index ba652695..527c381a 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -43,6 +43,8 @@ class UsersController < ApplicationController # User has passed all validations required @user.save + logger.info("Support: #{@user.email} user has been created.") + # Set user to pending and redirect if Approval Registration is set if approval_registration @user.add_role :pending @@ -161,6 +163,8 @@ class UsersController < ApplicationController # DELETE /u/:user_uid def destroy + logger.info("Support: #{current_user.email} is deleting #{@user.email}.") + if current_user && current_user == @user @user.destroy session.delete(:user_id) @@ -168,7 +172,7 @@ class UsersController < ApplicationController begin @user.destroy rescue => e - logger.error "Error in user deletion: #{e}" + logger.error "Support: Error in user deletion: #{e}" flash[:alert] = I18n.t(params[:message], default: I18n.t("administrator.flash.delete_fail")) else flash[:success] = I18n.t("administrator.flash.delete") @@ -220,7 +224,7 @@ class UsersController < ApplicationController begin send_activation_email(@user) rescue => e - logger.error "Error in email delivery: #{e}" + logger.error "Support: Error in email delivery: #{e}" flash[:alert] = I18n.t(params[:message], default: I18n.t("delivery_error")) else flash[:success] = I18n.t("email_sent", email_type: t("verify.verification")) @@ -235,7 +239,7 @@ class UsersController < ApplicationController send_approval_user_signup_email(@user) end rescue => e - logger.error "Error in email delivery: #{e}" + logger.error "Support: Error in email delivery: #{e}" flash[:alert] = I18n.t(params[:message], default: I18n.t("delivery_error")) end end @@ -245,6 +249,8 @@ class UsersController < ApplicationController valid_user = @user.valid? valid_captcha = Rails.configuration.recaptcha_enabled ? verify_recaptcha(model: @user) : true + logger.error("Support: #{@user.email} creation failed: User params are not valid.") unless valid_user + valid_user && valid_captcha end diff --git a/app/helpers/sessions_helper.rb b/app/helpers/sessions_helper.rb index dfce58c1..e0183be6 100644 --- a/app/helpers/sessions_helper.rb +++ b/app/helpers/sessions_helper.rb @@ -23,6 +23,8 @@ module SessionsHelper session[:user_id] = user.id + logger.info("Support: #{user.email} has successfully logged in.") + # If there are not terms, or the user has accepted them, check for email verification if !Rails.configuration.terms || user.accepted_terms check_email_verified(user) diff --git a/config/environments/production.rb b/config/environments/production.rb index e309a9a8..9a7250a3 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -6,6 +6,14 @@ Rails.application.configure do # Code is not reloaded between requests. config.cache_classes = true + # Cache controller code + config.action_controller.perform_caching = true + + config.cache_store = :memory_store + config.public_file_server.headers = { + 'Cache-Control' => "public, max-age=#{1.years.to_i}" + } + # Eager load code on boot. This eager loads most of Rails and # your application in memory, allowing both threaded web servers # and those relying on copy on write to perform better. @@ -29,7 +37,7 @@ Rails.application.configure do # config.assets.css_compressor = :sass # Do not fallback to assets pipeline if a precompiled asset is missed. - config.assets.compile = true + config.assets.compile = false # `config.assets.precompile` and `config.assets.version` have moved to config/initializers/assets.rb diff --git a/config/initializers/assets.rb b/config/initializers/assets.rb index a9b0d0f1..389a12d7 100644 --- a/config/initializers/assets.rb +++ b/config/initializers/assets.rb @@ -8,9 +8,9 @@ Rails.application.config.assets.version = '1.0' # Add additional assets to the asset load path. # Rails.application.config.assets.paths << Emoji.images_path # Add Yarn node_modules folder to the asset load path. -Rails.application.config.assets.paths << Rails.root.join('node_modules') +# Rails.application.config.assets.paths << Rails.root.join('node_modules') # Precompile additional assets. # application.js, application.css, and all non-JS/CSS in the app/assets # folder are already added. -# Rails.application.config.assets.precompile += %w( admin.js admin.css ) +Rails.application.config.assets.precompile += %w(pickr.min.js pickr.min.js.map monolith.min.css)