From f595b0dba957b388771eef0582ad8bce39b6d617 Mon Sep 17 00:00:00 2001 From: benji Date: Tue, 6 Jan 2015 20:33:11 +0100 Subject: [PATCH] Add controller action to define root based on user role --- app/assets/stylesheets/root.css.scss | 3 +++ app/controllers/orders_controller.rb | 2 +- app/controllers/root_controller.rb | 11 +++++++++++ app/helpers/root_helper.rb | 2 ++ .../orders/{index.html.erb => overview.html.erb} | 0 app/views/users/show.html.erb | 1 + config/routes.rb | 3 ++- test/controllers/root_controller_test.rb | 7 +++++++ test/helpers/root_helper_test.rb | 4 ++++ 9 files changed, 31 insertions(+), 2 deletions(-) create mode 100644 app/assets/stylesheets/root.css.scss create mode 100644 app/controllers/root_controller.rb create mode 100644 app/helpers/root_helper.rb rename app/views/orders/{index.html.erb => overview.html.erb} (100%) create mode 100644 test/controllers/root_controller_test.rb create mode 100644 test/helpers/root_helper_test.rb diff --git a/app/assets/stylesheets/root.css.scss b/app/assets/stylesheets/root.css.scss new file mode 100644 index 0000000..7c37211 --- /dev/null +++ b/app/assets/stylesheets/root.css.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the root controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/app/controllers/orders_controller.rb b/app/controllers/orders_controller.rb index 10ff98e..49a3d62 100644 --- a/app/controllers/orders_controller.rb +++ b/app/controllers/orders_controller.rb @@ -27,7 +27,7 @@ class OrdersController < ApplicationController end end - def index + def overview @users_by_name = User.members.order(:name) @users_by_order = User.members.order(:orders_count).reverse_order end diff --git a/app/controllers/root_controller.rb b/app/controllers/root_controller.rb new file mode 100644 index 0000000..998ad09 --- /dev/null +++ b/app/controllers/root_controller.rb @@ -0,0 +1,11 @@ +class RootController < ApplicationController + def root + if !current_user + redirect_to new_user_session_path + elsif current_user.koelkast? + redirect_to orders_path + else + redirect_to current_user + end + end +end diff --git a/app/helpers/root_helper.rb b/app/helpers/root_helper.rb new file mode 100644 index 0000000..04269a6 --- /dev/null +++ b/app/helpers/root_helper.rb @@ -0,0 +1,2 @@ +module RootHelper +end diff --git a/app/views/orders/index.html.erb b/app/views/orders/overview.html.erb similarity index 100% rename from app/views/orders/index.html.erb rename to app/views/orders/overview.html.erb diff --git a/app/views/users/show.html.erb b/app/views/users/show.html.erb index e486ac3..daa8a5e 100644 --- a/app/views/users/show.html.erb +++ b/app/views/users/show.html.erb @@ -1,3 +1,4 @@ +<%= render partial: 'flash' %>