diff --git a/app/constraints/user_homepage_constraint.rb b/app/constraints/user_homepage_constraint.rb new file mode 100644 index 0000000..ce78952 --- /dev/null +++ b/app/constraints/user_homepage_constraint.rb @@ -0,0 +1,5 @@ +class UserHomepageConstraint < Struct.new(:role) + def matches?(request) + role == request.env['warden'].user.koelkast? + end +end diff --git a/bin/rails b/bin/rails index 7feb6a3..728cd85 100755 --- a/bin/rails +++ b/bin/rails @@ -1,8 +1,4 @@ #!/usr/bin/env ruby -begin - load File.expand_path("../spring", __FILE__) -rescue LoadError -end APP_PATH = File.expand_path('../../config/application', __FILE__) require_relative '../config/boot' require 'rails/commands' diff --git a/bin/rake b/bin/rake index 8017a02..1724048 100755 --- a/bin/rake +++ b/bin/rake @@ -1,8 +1,4 @@ #!/usr/bin/env ruby -begin - load File.expand_path("../spring", __FILE__) -rescue LoadError -end require_relative '../config/boot' require 'rake' Rake.application.run diff --git a/config/routes.rb b/config/routes.rb index 24ee8f5..0cb9f2b 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -6,9 +6,8 @@ Rails.application.routes.draw do root to: 'devise/sessions#new' end authenticated :user do - root to: 'devise/sessions#new', constraints: lambda { |req| req.env['warden'].user.nil? }, as: 'unauth_root' - root to: 'orders#overview', constraints: lambda { |req| req.env['warden'].user.koelkast? }, as: 'koelkast_root' - root to: 'users#show', constraints: lambda { |req| !req.env['warden'].user.koelkast? }, as: 'user_root' + root to: 'orders#overview', constraints: UserHomepageConstraint.new(true), as: 'koelkast_root' + root to: 'users#show', constraints: UserHomepageConstraint.new(false), as: 'user_root' end end