diff --git a/Gemfile b/Gemfile index c9e771e5..6b63cfb8 100644 --- a/Gemfile +++ b/Gemfile @@ -5,7 +5,7 @@ end source 'https://rubygems.org' -ruby ENV['OSEM_RUBY_VERSION'] || '3.1.2' +ruby ENV.fetch('OSEM_RUBY_VERSION', '3.1.2') # rails-assets requires >= 1.8.4 if Gem::Version.new(Bundler::VERSION) < Gem::Version.new('1.8.4') diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 0d1a1ed4..e3474111 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -116,7 +116,7 @@ module ApplicationHelper end def sign_in_path - if ENV['OSEM_ICHAIN_ENABLED'] == 'true' + if ENV.fetch('OSEM_ICHAIN_ENABLED', nil) == 'true' new_user_ichain_session_path else new_user_session_path @@ -140,9 +140,7 @@ module ApplicationHelper def nav_root_link_for(conference) link_text = ( - conference.try(:organization).try(:name) || - ENV['OSEM_NAME'] || - 'OSEM' + conference.try(:organization).try(:name) || ENV.fetch('OSEM_NAME', 'OSEM') ) link_to( link_text, diff --git a/app/helpers/users_helper.rb b/app/helpers/users_helper.rb index 1ee065ea..906e6f3b 100644 --- a/app/helpers/users_helper.rb +++ b/app/helpers/users_helper.rb @@ -19,7 +19,7 @@ module UsersHelper unless Rails.application.secrets.send(provider_key).blank? || Rails.application.secrets.send(provider_secret).blank? providers << provider end - providers << provider if !ENV["OSEM_#{provider.upcase}_KEY"].blank? && !ENV["OSEM_#{provider.upcase}_SECRET"].blank? + providers << provider if ENV.fetch("OSEM_#{provider.upcase}_KEY", nil).present? && ENV.fetch("OSEM_#{provider.upcase}_SECRET", nil).present? end providers.uniq diff --git a/app/models/ability.rb b/app/models/ability.rb index 4fc5ae34..77746620 100644 --- a/app/models/ability.rb +++ b/app/models/ability.rb @@ -42,7 +42,7 @@ class Ability can [:index, :show], Survey, surveyable_type: 'Conference' # Things that are possible without ichain enabled that are **not*+ possible with ichain mode enabled. - if ENV['OSEM_ICHAIN_ENABLED'] != 'true' + if ENV.fetch('OSEM_ICHAIN_ENABLED', nil) != 'true' # There is no reliable way for this workflow (enable not logged in users to fill out a form, then telling # them to sign up once they submit) in ichain. So enable it only without ichain. diff --git a/app/models/admin_ability.rb b/app/models/admin_ability.rb index 4046d29f..6100455c 100644 --- a/app/models/admin_ability.rb +++ b/app/models/admin_ability.rb @@ -51,7 +51,7 @@ class AdminAbility # for admins can :manage, :all if user.is_admin # even admin cannot create new users with ICHAIN enabled - cannot [:new, :create], User if ENV['OSEM_ICHAIN_ENABLED'] == 'true' + cannot [:new, :create], User if ENV.fetch('OSEM_ICHAIN_ENABLED', nil) == 'true' cannot :revert_object, PaperTrail::Version do |version| (version.event == 'create' && %w[Conference User Event].include?(version.item_type)) end diff --git a/app/models/email_settings.rb b/app/models/email_settings.rb index 55487496..053a82db 100644 --- a/app/models/email_settings.rb +++ b/app/models/email_settings.rb @@ -13,12 +13,12 @@ class EmailSettings < ApplicationRecord 'conference_start_date' => conference.start_date, 'conference_end_date' => conference.end_date, 'registrationlink' => Rails.application.routes.url_helpers.conference_conference_registration_url( - conference.short_title, host: (ENV['OSEM_HOSTNAME'] || 'localhost:3000')), + conference.short_title, host: ENV.fetch('OSEM_HOSTNAME', 'localhost:3000')), 'conference_splash_link' => Rails.application.routes.url_helpers.conference_url( - conference.short_title, host: (ENV['OSEM_HOSTNAME'] || 'localhost:3000')), + conference.short_title, host: ENV.fetch('OSEM_HOSTNAME', 'localhost:3000')), 'schedule_link' => Rails.application.routes.url_helpers.conference_schedule_url( - conference.short_title, host: (ENV['OSEM_HOSTNAME'] || 'localhost:3000')) + conference.short_title, host: ENV.fetch('OSEM_HOSTNAME', 'localhost:3000')) } if conference.program.cfp @@ -45,7 +45,7 @@ class EmailSettings < ApplicationRecord if event h['eventtitle'] = event.title h['proposalslink'] = Rails.application.routes.url_helpers.conference_program_proposals_url( - conference.short_title, host: (ENV['OSEM_HOSTNAME'] || 'localhost:3000')) + conference.short_title, host: ENV.fetch('OSEM_HOSTNAME', 'localhost:3000')) end if booth diff --git a/app/models/user.rb b/app/models/user.rb index 8c7f92ec..993d4892 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -51,7 +51,7 @@ class User < ApplicationRecord # :lockable, :timeoutable and :omniauthable devise_modules = [] - devise_modules += if ENV['OSEM_ICHAIN_ENABLED'] == 'true' + devise_modules += if ENV.fetch('OSEM_ICHAIN_ENABLED', nil) == 'true' [:ichain_authenticatable, :ichain_registerable, :omniauthable, omniauth_providers: []] else [:database_authenticatable, :registerable, diff --git a/app/views/conference_registrations/edit.html.haml b/app/views/conference_registrations/edit.html.haml index 25a22666..4ec17f4d 100644 --- a/app/views/conference_registrations/edit.html.haml +++ b/app/views/conference_registrations/edit.html.haml @@ -11,7 +11,7 @@ %legend %span =link_to('#signup', role: 'tab', "aria-controls" => "home", "data-toggle" => "tab") do - = ENV['OSEM_NAME'] || 'OSEM' + = ENV.fetch('OSEM_NAME', 'OSEM') Account %span.pull-right#account-already =link_to('#signin', role: 'tab', "aria-controls" => "home", "data-toggle" => "tab") do diff --git a/app/views/conference_registrations/new.html.haml b/app/views/conference_registrations/new.html.haml index 25a22666..4ec17f4d 100644 --- a/app/views/conference_registrations/new.html.haml +++ b/app/views/conference_registrations/new.html.haml @@ -11,7 +11,7 @@ %legend %span =link_to('#signup', role: 'tab', "aria-controls" => "home", "data-toggle" => "tab") do - = ENV['OSEM_NAME'] || 'OSEM' + = ENV.fetch('OSEM_NAME', 'OSEM') Account %span.pull-right#account-already =link_to('#signin', role: 'tab', "aria-controls" => "home", "data-toggle" => "tab") do diff --git a/app/views/conferences/new_install.html.haml b/app/views/conferences/new_install.html.haml index 1b7b1072..772511aa 100644 --- a/app/views/conferences/new_install.html.haml +++ b/app/views/conferences/new_install.html.haml @@ -9,7 +9,7 @@ installation! %p The first user to - - if ENV['OSEM_ICHAIN_ENABLED'] == 'true' + - if ENV.fetch('OSEM_ICHAIN_ENABLED', nil) == 'true' = link_to(new_ichain_registration_path('user')) do sign up - else diff --git a/app/views/conferences/show.html.haml b/app/views/conferences/show.html.haml index e8f64db3..85b2bac6 100644 --- a/app/views/conferences/show.html.haml +++ b/app/views/conferences/show.html.haml @@ -1,6 +1,6 @@ - content_for :head do %meta{ property: "og:title", content: @conference.title } - %meta{ property: "og:site_name", content: (ENV['OSEM_NAME'] || 'OSEM') } + %meta{ property: "og:site_name", content: ENV.fetch('OSEM_NAME', 'OSEM') } %meta{ property: "og:description", content: @conference.description } %meta{ property: "og:url", content: conference_url(@conference.short_title) } %meta{ property: "twitter:title", content: (@conference.title) } diff --git a/app/views/devise/sessions/_new_embedded.html.haml b/app/views/devise/sessions/_new_embedded.html.haml index 16f21c52..193a6335 100644 --- a/app/views/devise/sessions/_new_embedded.html.haml +++ b/app/views/devise/sessions/_new_embedded.html.haml @@ -1,4 +1,4 @@ -- if ENV['OSEM_ICHAIN_ENABLED'] != 'true' +- if ENV.fetch('OSEM_ICHAIN_ENABLED', nil) != 'true' = form_tag(new_user_session_path, class: 'form-horizontal') do %legend %span diff --git a/app/views/layouts/_admin_sidebar_index.html.haml b/app/views/layouts/_admin_sidebar_index.html.haml index 0283bf72..65735952 100644 --- a/app/views/layouts/_admin_sidebar_index.html.haml +++ b/app/views/layouts/_admin_sidebar_index.html.haml @@ -37,7 +37,7 @@ = link_to(admin_revision_history_path) do %span.fa.fa-history Revision History - - if ENV['ORGANIZATIONS_ENABLED'] == 'true' + - if ENV.fetch('ORGANIZATIONS_ENABLED', nil) == 'true' %li = link_to(admin_organizations_path) do %span.fa.fa-group diff --git a/app/views/layouts/_navigation.html.haml b/app/views/layouts/_navigation.html.haml index deea4f09..338f4f0e 100644 --- a/app/views/layouts/_navigation.html.haml +++ b/app/views/layouts/_navigation.html.haml @@ -32,7 +32,7 @@ = render 'layouts/user_menu' - else %ul.nav.navbar-nav.navbar-right - - if ENV['OSEM_ICHAIN_ENABLED'] == 'true' + - if ENV.fetch('OSEM_ICHAIN_ENABLED', nil) == 'true' %li{class: "#{active_nav_li(new_ichain_registration_path('user'))}"} = link_to(new_ichain_registration_path('user')) do %span.fa.fa-heart @@ -48,7 +48,7 @@ Sign In %span.caret .dropdown-menu - - if ENV['OSEM_ICHAIN_ENABLED'] == 'true' + - if ENV.fetch('OSEM_ICHAIN_ENABLED', nil) == 'true' = form_tag User.ichain_login_url do = text_field_tag 'username', nil, id: 'user_ichain_email_dd', class: 'form-control', placeholder: 'Username' = password_field_tag 'password', nil, id: 'user_ichain_password_dd', class: 'form-control', placeholder: 'Password' diff --git a/app/views/layouts/_user_menu.html.haml b/app/views/layouts/_user_menu.html.haml index b839f913..787c8eb2 100644 --- a/app/views/layouts/_user_menu.html.haml +++ b/app/views/layouts/_user_menu.html.haml @@ -10,7 +10,7 @@ %li= link_to "See all unread Comments (#{unread_notifications(current_user).length})", admin_comments_path %li= link_to 'See all Comments', admin_comments_path(anchor: 'all_comments') %li.divider -- unless ENV['OSEM_ICHAIN_ENABLED'] == 'true' +- unless ENV.fetch('OSEM_ICHAIN_ENABLED', nil) == 'true' %li = link_to(edit_user_registration_path) do %span.fa.fa-wrench @@ -40,7 +40,7 @@ %span.fa.fa-shopping-bag My #{(t'booth').capitalize } Requests %li - - if ENV['OSEM_ICHAIN_ENABLED'] == 'true' + - if ENV.fetch('OSEM_ICHAIN_ENABLED', nil) == 'true' = link_to(destroy_user_ichain_session_path, method: 'delete') do %span.fa.fa-minus Sign out @@ -76,7 +76,7 @@ = link_to(admin_revision_history_path) do %span.fa.fa-history Revision History - - if ENV['ORGANIZATIONS_ENABLED'] == 'true' + - if ENV.fetch('OSEM_ICHAIN_ENABLED', nil) == 'true' %li = link_to(admin_organizations_path) do %span.fa.fa-group diff --git a/app/views/layouts/application.html.haml b/app/views/layouts/application.html.haml index 7dfaf2c8..2b2eca75 100644 --- a/app/views/layouts/application.html.haml +++ b/app/views/layouts/application.html.haml @@ -2,7 +2,7 @@ %head %meta{charset: 'utf-8'} %meta{name: 'viewport', content: 'width=device-width, initial-scale=1, maximum-scale=1'} - %title= content_for?(:title) ? yield(:title) : (ENV['OSEM_NAME'] || 'OSEM') + %title= content_for?(:title) ? yield(:title) : ENV.fetch('OSEM_NAME', 'OSEM') %meta{content: '', name: 'description'} %meta{content: '', name: 'author'} = stylesheet_link_tag "application", media: 'all' @@ -10,7 +10,7 @@ = csrf_meta_tags = content_for(:script_head) - - if ENV['OSEM_TRANSIFEX_APIKEY'] + - if ENV.fetch('OSEM_TRANSIFEX_APIKEY', nil) :javascript window.liveSettings = { api_key: "#{ENV['OSEM_TRANSIFEX_APIKEY']}", @@ -46,7 +46,7 @@ You can run, copy, distribute, study, change and improve it. The source code and the developers are on #{link_to "GitHub", "https://github.com/openSUSE/osem"}. - - if ENV["SKYLIGHT_PUBLIC_DASHBOARD_URL"].present? + - if ENV.fetch('SKYLIGHT_PUBLIC_DASHBOARD_URL', nil) Performance data is available on #{link_to "Skylight", ENV["SKYLIGHT_PUBLIC_DASHBOARD_URL"]}. = yield :script_body diff --git a/app/views/payments/_payment.html.haml b/app/views/payments/_payment.html.haml index 56af80f7..3fa79e6b 100644 --- a/app/views/payments/_payment.html.haml +++ b/app/views/payments/_payment.html.haml @@ -22,6 +22,6 @@ = form_tag conference_payments_path do %script.stripe-button{ src: "https://checkout.stripe.com/checkout.js", data: { amount: @total_amount_to_pay.cents, label: "Pay #{humanized_money_with_symbol @total_amount_to_pay}", - email: current_user.email, currency: @total_amount_to_pay.currency, name: ENV['OSEM_NAME'] || 'OSEM', + email: current_user.email, currency: @total_amount_to_pay.currency, name: ENV.fetch('OSEM_NAME', 'OSEM'), description: "book your tickets", key: Rails.application.secrets.stripe_publishable_key, locale: "auto"}} = link_to 'Edit Purchase', conference_tickets_path(@conference.short_title), class: 'btn btn-default' diff --git a/app/views/proposals/new.html.haml b/app/views/proposals/new.html.haml index 794fde6d..212ef458 100644 --- a/app/views/proposals/new.html.haml +++ b/app/views/proposals/new.html.haml @@ -17,7 +17,7 @@ %legend %span =link_to('#signup', role: 'tab', 'aria-controls' => 'home', 'data-toggle' => 'tab') do - = ENV['OSEM_NAME'] || 'OSEM' + = ENV.fetch('OSEM_NAME', 'OSEM') Account %span.pull-right#account-already =link_to('#signin', role: 'tab', 'aria-controls' => 'home', 'data-toggle' => 'tab') do diff --git a/app/views/proposals/show.html.haml b/app/views/proposals/show.html.haml index a7a155bb..a4f947fd 100644 --- a/app/views/proposals/show.html.haml +++ b/app/views/proposals/show.html.haml @@ -2,7 +2,7 @@ %meta{ property: "og:title", content: @event.title } %meta{ property: "og:url", content: conference_program_proposal_url(@conference.short_title, @event) } %meta{ property: "og:description", content: @event.abstract } - %meta{ property: "og:site_name", content: (ENV['OSEM_NAME'] || 'OSEM') } + %meta{ property: "og:site_name", content: ENV.fetch('OSEM_NAME', 'OSEM') } - if @speakers_ordered.any? %meta{ property: "og:image", content: @speakers_ordered.first.gravatar_url } %meta{ property: "og:image:secure_url", content: @speakers_ordered.first.gravatar_url } diff --git a/bin/bundle b/bin/bundle index 96131dad..1c6e5116 100755 --- a/bin/bundle +++ b/bin/bundle @@ -18,7 +18,7 @@ m = Module.new do end def env_var_version - ENV['BUNDLER_VERSION'] + ENV.fetch('BUNDLER_VERSION', nil) end def cli_arg_version @@ -40,7 +40,7 @@ m = Module.new do end def gemfile - gemfile = ENV['BUNDLE_GEMFILE'] + gemfile = ENV.fetch('BUNDLE_GEMFILE', nil) return gemfile if gemfile && !gemfile.empty? File.expand_path('../../Gemfile', __FILE__) diff --git a/config/database.yml b/config/database.yml index dd8ac693..96ef1936 100644 --- a/config/database.yml +++ b/config/database.yml @@ -1,19 +1,19 @@ <% encoding = 'unicode' - if ENV['OSEM_DB_ADAPTER'] == 'mysql2' + if ENV.fetch('OSEM_DB_ADAPTER', nil) == 'mysql2' encoding = 'utf8' end %> default: &default - adapter: <%= ENV['OSEM_DB_ADAPTER'] || 'postgresql' %> + adapter: <%= ENV.fetch('OSEM_DB_ADAPTER', 'postgresql') %> encoding: <%= encoding %> - host: <%= ENV['OSEM_DB_HOST'] || 'database' %> - port: <%= ENV['OSEM_DB_PORT'] || '5432' %> - username: <%= ENV['OSEM_DB_USER'] || 'postgres' %> - password: <%= ENV['OSEM_DB_PASSWORD'] || 'mysecretpassword' %> - database: <%= ENV['OSEM_DB_NAME'] || 'postgres' %> + host: <%= ENV.fetch('OSEM_DB_HOST', 'database') %> + port: <%= ENV.fetch('OSEM_DB_PORT', '5432') %> + username: <%= ENV.fetch('OSEM_DB_USER', 'postgres') %> + password: <%= ENV.fetch('OSEM_DB_PASSWORD', 'mysecretpassword') %> + database: <%= ENV.fetch('OSEM_DB_NAME', 'postgres') %> pool: 5 timeout: 5000 diff --git a/config/environments/development.rb b/config/environments/development.rb index 7c66d30e..0397ea88 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -55,7 +55,7 @@ Rails.application.configure do # config.action_view.annotate_rendered_view_with_filenames = true # Set the detault url for action mailer - config.action_mailer.default_url_options = { host: (ENV['OSEM_HOSTNAME'] || 'localhost:3000') } + config.action_mailer.default_url_options = { host: ENV.fetch('OSEM_HOSTNAME', 'localhost:3000') } # Access all mails sent at http://localhost:3000/letter_opener config.action_mailer.delivery_method = :letter_opener diff --git a/config/initializers/devise.rb b/config/initializers/devise.rb index 76f615a0..69c2d9e3 100644 --- a/config/initializers/devise.rb +++ b/config/initializers/devise.rb @@ -7,16 +7,16 @@ Devise.setup do |config| # Pass each provider to User model in :omniauth_providers (for open_id providers use their name) config.omniauth :open_id, name: 'suse', identifier: 'http://www.opensuse.org/openid/user' - config.omniauth :google_oauth2, (ENV['OSEM_GOOGLE_KEY'] || Rails.application.secrets.google_key), (ENV['OSEM_GOOGLE_SECRET'] || Rails.application.secrets.google_secret), + config.omniauth :google_oauth2, ENV.fetch('OSEM_GOOGLE_KEY', Rails.application.secrets.google_key), ENV.fetch('OSEM_GOOGLE_SECRET', Rails.application.secrets.google_secret), name: 'google', scope: 'email' - config.omniauth :facebook, (ENV['OSEM_FACEBOOK_KEY'] || Rails.application.secrets.facebook_key), (ENV['OSEM_FACEBOOK_SECRET'] || Rails.application.secrets.facebook_secret) - config.omniauth :github, (ENV['OSEM_GITHUB_KEY'] || Rails.application.secrets.github_key), (ENV['OSEM_GITHUB_SECRET'] || Rails.application.secrets.github_secret) + config.omniauth :facebook, ENV.fetch('OSEM_FACEBOOK_KEY', Rails.application.secrets.facebook_key), ENV.fetch('OSEM_FACEBOOK_SECRET', Rails.application.secrets.facebook_secret) + config.omniauth :github, ENV.fetch('OSEM_GITHUB_KEY', Rails.application.secrets.github_key), ENV.fetch('OSEM_GITHUB_SECRET', Rails.application.secrets.github_secret) # ==> Mailer Configuration # Configure the e-mail address which will be shown in Devise::Mailer, # note that it will be overwritten if you use your own mailer class with default "from" parameter. - config.mailer_sender = ENV['OSEM_EMAIL_ADDRESS'] || 'no-reply@localhost' + config.mailer_sender = ENV.fetch('OSEM_EMAIL_ADDRESS', 'no-reply@localhost') # Configure the class responsible to send e-mails. # config.mailer = "Devise::Mailer" diff --git a/config/piwik.yml b/config/piwik.yml index 9b92a97c..afc903a1 100644 --- a/config/piwik.yml +++ b/config/piwik.yml @@ -13,9 +13,9 @@ default: &default id_site: <%= ENV['OSEM_PIWIK_ID'] %> url: <%= ENV['OSEM_PIWIK_URL'] %> - use_async: <%= ENV['OSEM_PIWIK_ASYNC'] || false %> - disabled: <%= ENV['OSEM_PIWIK_DISABLED'] || true %> - hostname: <%= ENV['OSEM_PIWIK_HOSTNAME'] || 'localhost' %> + use_async: <%= ENV.fetch('OSEM_PIWIK_ASYNC', false) %> + disabled: <%= ENV.fetch('OSEM_PIWIK_DISABLED', true) %> + hostname: <%= ENV.fetch('OSEM_PIWIK_HOSTNAME', 'localhost') %> production: piwik: diff --git a/config/routes.rb b/config/routes.rb index 4ac25755..5865281d 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -5,7 +5,7 @@ Osem::Application.routes.draw do get '/', to: 'conferences#show' end - if ENV['OSEM_ICHAIN_ENABLED'] == 'true' + if ENV.fetch('OSEM_ICHAIN_ENABLED', nil) == 'true' devise_for :users, controllers: { registrations: :registrations } else devise_for :users, @@ -225,8 +225,8 @@ Osem::Application.routes.draw do get '/calendar' => 'conferences#calendar' - unless ENV['OSEM_ROOT_CONFERENCE'].blank? - root to: redirect("/conferences/#{ENV['OSEM_ROOT_CONFERENCE']}") + if ENV.fetch('OSEM_ROOT_CONFERENCE', nil) + root to: redirect("/conferences/#{ENV.fetch('OSEM_ROOT_CONFERENCE')}") else root to: 'conferences#index', via: [:get, :options] end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 10cab9e5..59310381 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -85,7 +85,7 @@ RSpec.configure do |config| # use a real browser for JS tests Capybara.javascript_driver = ( - ENV['OSEM_TEST_DRIVER'].try(:to_sym) || :chrome_headless + ENV.fetch('OSEM_TEST_DRIVER', 'chrome_headless').to_sym ) # Includes helpers and connect them to specific types of tests diff --git a/spec/support/deprecation_shitlist.rb b/spec/support/deprecation_shitlist.rb index bbaea59b..fc962504 100644 --- a/spec/support/deprecation_shitlist.rb +++ b/spec/support/deprecation_shitlist.rb @@ -1,10 +1,10 @@ RSpec.configure do |config| # Tracker deprecation messages in each file - if ENV['DEPRECATION_TRACKER'] + if ENV.fetch('DEPRECATION_TRACKER', nil) DeprecationTracker.track_rspec( config, shitlist_path: 'spec/support/deprecation_shitlist.json', - mode: ENV['DEPRECATION_TRACKER'], + mode: ENV.fetch('DEPRECATION_TRACKER'), transform_message: ->(message) { message.gsub("#{Rails.root}/", '') } ) end