From c2043891031f028ff30234fe70ceb20079d3d8e9 Mon Sep 17 00:00:00 2001 From: Mark Moser Date: Mon, 19 Oct 2015 22:05:48 -0500 Subject: [PATCH] simple roles --- app/controllers/application_controller.rb | 1 + app/helpers/access_helper.rb | 13 +++++++++++++ app/views/layouts/_navigation.html.haml | 5 +++-- 3 files changed, 17 insertions(+), 2 deletions(-) create mode 100644 app/helpers/access_helper.rb diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 708077e..f309041 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -4,6 +4,7 @@ class ApplicationController < ActionController::Base protect_from_forgery with: :exception before_filter :require_login respond_to :html, :json + helper :access private diff --git a/app/helpers/access_helper.rb b/app/helpers/access_helper.rb new file mode 100644 index 0000000..d87aba8 --- /dev/null +++ b/app/helpers/access_helper.rb @@ -0,0 +1,13 @@ +module AccessHelper + def can_create_user? user + user && user.admin? + end + + def can_edit_user? user + user && user.admin? + end + + def can_page? user + user && (user.admin? || user.staff?) + end +end diff --git a/app/views/layouts/_navigation.html.haml b/app/views/layouts/_navigation.html.haml index d9367b9..b333b9d 100644 --- a/app/views/layouts/_navigation.html.haml +++ b/app/views/layouts/_navigation.html.haml @@ -3,5 +3,6 @@ %li{ class: active_controller('parents') }= link_to 'Parents', list_parents_path %li{ class: active_controller('children') }= link_to 'Children', list_children_path %li{ class: active_controller('pages') }= link_to 'Pages', list_pages_path - %li{ class: active_controller('staff') }= link_to 'Staff', list_staff_path - %li{ class: active_controller('users') }= link_to 'Users', list_users_path + - if can_edit_user? current_user + %li{ class: active_controller('staff') }= link_to 'Staff', list_staff_path + %li{ class: active_controller('users') }= link_to 'Users', list_users_path