From 0a2468869f4b6439f22182f6e7db5bb134842b56 Mon Sep 17 00:00:00 2001 From: Ryan Bigg Date: Sun, 16 Nov 2014 22:12:10 +1100 Subject: [PATCH] Section 7.2.2: Lock down specific projects controller actions for admins only --- ticketee/app/helpers/application_helper.rb | 4 ++ ticketee/app/views/projects/index.html.erb | 4 +- ticketee/app/views/projects/show.html.erb | 22 ++++---- ticketee/spec/features/hidden_links_spec.rb | 60 +++++++++++++++++++++ ticketee/spec/rails_helper.rb | 2 +- ticketee/spec/support/capybara_helpers.rb | 15 ++++++ 6 files changed, 95 insertions(+), 12 deletions(-) create mode 100644 ticketee/spec/features/hidden_links_spec.rb create mode 100644 ticketee/spec/support/capybara_helpers.rb diff --git a/ticketee/app/helpers/application_helper.rb b/ticketee/app/helpers/application_helper.rb index 1f1fea7..4457356 100644 --- a/ticketee/app/helpers/application_helper.rb +++ b/ticketee/app/helpers/application_helper.rb @@ -6,4 +6,8 @@ def title(*parts) end end end + + def admins_only(&block) + block.call if current_user.try(:admin?) + end end diff --git a/ticketee/app/views/projects/index.html.erb b/ticketee/app/views/projects/index.html.erb index ebb5bc6..5175af5 100644 --- a/ticketee/app/views/projects/index.html.erb +++ b/ticketee/app/views/projects/index.html.erb @@ -1,4 +1,6 @@ -<%= link_to "New Project", new_project_path, class: "new" %> +<% admins_only do %> + <%= link_to "New Project", new_project_path, class: "new" %> +<% end %>

Projects