diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 5bd7735..5a9e7d3 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -38,6 +38,8 @@ def render_csv(param) end def authenticate + use_fake_auth and return if Rails.application.config.use_fakeauth + cas_data_file = "#{ENV['CAS_DATA_DIRECTORY']}/#{cookies[:MOD_AUTH_CAS]}" user_data = {} @@ -80,4 +82,18 @@ def authenticate def is_admin redirect_to root_url unless @session_user.superadmin end + + def use_fake_auth + fake_user = User.where(email: 'timetracker_fake_user@example.com').first + + if fake_user.nil? + fake_user = User.create!( + username: 'timetracker_fake_user', + email: 'timetracker_fake_user@example.com', + superadmin: true + ) + end + + @session_user = fake_user + end end diff --git a/config/application.rb b/config/application.rb index 8ba577e..3e20e9b 100644 --- a/config/application.rb +++ b/config/application.rb @@ -89,5 +89,11 @@ class Application < Rails::Application # TODO: To make the CMS work, can be removed when the CMS is ready to work # with the latest Rails version. config.active_record.yaml_column_permitted_classes = [Symbol] + + # Set host allowed by the application + config.hosts << ENV['ALLOWED_HOST'] if ENV['ALLOWED_HOST'].present? + + # Set the default value for bypassing the authentication + config.use_fakeauth = false end end diff --git a/config/environments/development.rb b/config/environments/development.rb index 9dff2ee..34286a9 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -88,4 +88,7 @@ # Allow any hostname config.hosts.clear + + # In the development mode, you may want to avoid using the CAS server. + config.use_fakeauth = (ENV['USE_FAKEAUTH'] == 'true') || false end diff --git a/config/environments/test.rb b/config/environments/test.rb index efee233..a134055 100644 --- a/config/environments/test.rb +++ b/config/environments/test.rb @@ -64,4 +64,7 @@ config.active_storage.service = :test config.maintain_test_schema = false + + # In the test mode, you may want to avoid using the CAS server. + config.use_fakeauth = (ENV['USE_FAKEAUTH'] == 'true') || false end