Skip to content

Commit

Permalink
Allow using fake authentication in dev
Browse files Browse the repository at this point in the history
  • Loading branch information
peter-hank committed Jan 26, 2023
1 parent 2ced337 commit 3cf5804
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 0 deletions.
16 changes: 16 additions & 0 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {}

Expand Down Expand Up @@ -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
6 changes: 6 additions & 0 deletions config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
3 changes: 3 additions & 0 deletions config/environments/development.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
3 changes: 3 additions & 0 deletions config/environments/test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 3cf5804

Please sign in to comment.