From 5b7096b3a4b720f26e00ed8ec039451dac09ccce Mon Sep 17 00:00:00 2001 From: wvengen Date: Sat, 13 Oct 2018 17:24:55 +0200 Subject: [PATCH] Changes after code-review (thanks @paroga) --- app/controllers/concerns/auth.rb | 20 ++++++++++---------- app/controllers/concerns/locale.rb | 4 ++-- config/application.rb | 4 ++-- config/locales/de.yml | 1 + 4 files changed, 15 insertions(+), 14 deletions(-) diff --git a/app/controllers/concerns/auth.rb b/app/controllers/concerns/auth.rb index eb287b76ca..42b14a1b9f 100644 --- a/app/controllers/concerns/auth.rb +++ b/app/controllers/concerns/auth.rb @@ -56,16 +56,16 @@ def authenticate(role = 'any') # We have an authenticated user, now check role... # Roles gets the user through his memberships. hasRole = case role - when "admin" then current_user.role_admin? - when "finance" then current_user.role_finance? - when "article_meta" then current_user.role_article_meta? - when "pickups" then current_user.role_pickups? - when "suppliers" then current_user.role_suppliers? - when "orders" then current_user.role_orders? - when "finance_or_orders" then (current_user.role_finance? || current_user.role_orders?) - when "pickups_or_orders" then (current_user.role_pickups? || current_user.role_orders?) - when "any" then true # no role required - else false # any unknown role will always fail + when 'admin' then current_user.role_admin? + when 'finance' then current_user.role_finance? + when 'article_meta' then current_user.role_article_meta? + when 'pickups' then current_user.role_pickups? + when 'suppliers' then current_user.role_suppliers? + when 'orders' then current_user.role_orders? + when 'finance_or_orders' then (current_user.role_finance? || current_user.role_orders?) + when 'pickups_or_orders' then (current_user.role_pickups? || current_user.role_orders?) + when 'any' then true # no role required + else false # any unknown role will always fail end if hasRole current_user diff --git a/app/controllers/concerns/locale.rb b/app/controllers/concerns/locale.rb index aa79f092a3..d0e622bc46 100644 --- a/app/controllers/concerns/locale.rb +++ b/app/controllers/concerns/locale.rb @@ -10,7 +10,7 @@ def explicitly_requested_language end def user_settings_language - current_user.locale if current_user + current_user&.locale end def session_language @@ -30,7 +30,7 @@ def default_language def select_language_according_to_priority language = explicitly_requested_language || session_language || user_settings_language language ||= browser_language unless FoodsoftConfig[:ignore_browser_locale] - language.to_sym unless language.blank? + language.presence&.to_sym unless language.blank? end def available_locales diff --git a/config/application.rb b/config/application.rb index 912bf72bd2..f954206208 100644 --- a/config/application.rb +++ b/config/application.rb @@ -63,11 +63,11 @@ class Application < Rails::Application config.assets.precompile += [ 'vendor/assets/javascripts/*.js' ] # CORS for API - config.middleware.insert_before 0, "Rack::Cors" do + config.middleware.insert_before 0, 'Rack::Cors' do allow do origins '*' # this restricts Foodsoft scopes to certain characters - let's discuss it when it becomes an actual problem - resource %r{\A/[-a-zA-Z0-9_]+/api/v1/}, :headers => :any, :methods => :any + resource %r{\A/[-a-zA-Z0-9_]+/api/v1/}, headers: :any, methods: :any end end end diff --git a/config/locales/de.yml b/config/locales/de.yml index 787346f434..77fc98e269 100644 --- a/config/locales/de.yml +++ b/config/locales/de.yml @@ -663,6 +663,7 @@ de: use_wiki: Wiki verwenden webstats_tracking_code: Code für Websiteanalysetool tabs: + applications: Apps foodcoop: Foodcoop language: Sprache layout: Layout