Add cancan, fix header, add admins

This commit is contained in:
Tom Naessens 2014-12-09 19:44:58 +01:00
parent 465b9198ab
commit bdf4b6771f
6 changed files with 53 additions and 25 deletions

View file

@ -69,8 +69,8 @@ gem 'paperclip'
# Use devise for Admins
gem 'devise'
# Use cancan for authorization
gem 'cancan'
# Use cancancan for authorization
gem 'cancancan'
#ik wil test data maken dus dit
gem 'faker', '1.4.2'

View file

@ -41,7 +41,7 @@ GEM
columnize (~> 0.8)
debugger-linecache (~> 1.2)
slop (~> 3.6)
cancan (1.6.10)
cancancan (1.9.2)
capistrano (3.2.1)
i18n
rake (>= 10.0.0)
@ -175,7 +175,7 @@ DEPENDENCIES
bootstrap-sass (= 3.2.0.0)
bootstrap-will_paginate (= 0.0.10)
byebug
cancan
cancancan
capistrano (~> 3.1)
capistrano-rails (~> 1.1)
capistrano-rvm

12
app/models/ability.rb Normal file
View file

@ -0,0 +1,12 @@
class Ability
include CanCan::Ability
def initialize(user)
user ||= User.new # guest user (not logged in)
if user.admin?
can :manage, :all
else
can :read, :all
end
end
end

View file

@ -7,45 +7,55 @@
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<%= link_to "Tab", root_path, class: "navbar-brand" %>
<%= link_to "Taþ", root_path, class: "navbar-brand" %>
</div>
<!-- Collect the nav links, forms, and other content for toggling -->
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav">
<div class="hidden-xs navbar-form navbar-right">
<div class="form-group">
<% if user_signed_in? %>
<%= button_to "Logout", destroy_user_session_path(current_user), class: "btn btn-default form-control", method: :delete %>
<% else %>
<%= button_to "Login", new_user_session_path, class: "btn btn-success form-control" %>
<% end %>
</div>
</div>
<ul class="nav navbar-nav navbar-right">
<li><%= mail_to "tab@zeus.ugent.be", "Send feedback" %></li>
<% if can? :manage, :all %>
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false">Products <span class="caret"></span></a>
<ul class="dropdown-menu" role="menu">
<li><%= link_to "All products", products_path %></li>
<li><%= link_to "New product" , new_product_path %></li>
<li><%= link_to "Index", products_path %></li>
</ul>
</li>
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false">Users <span class="caret"></span></a>
<ul class="dropdown-menu" role="menu">
<li><%= link_to "New User", new_user_registration_path %></li>
<li><%= link_to "index" , users_path %></li>
</ul>
</li>
</ul>
<ul class="nav navbar-nav navbar-center">
<li class="navbar-text">
ADMIN NAVBAR
<% end %>
<% if user_signed_in? %>
<li>
<a>Logged in as <%= current_user.display_name %></a>
</li>
<% end %>
</ul>
<ul class="nav navbar-nav navbar-right">
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false">Account <span class="caret"></span></a>
<ul class="dropdown-menu" role="menu">
<li><a href="#">Profile</a></li>
<li><a href="#">Update</a></li>
<li><%= link_to "Sign out", destroy_user_session_path, method: :delete unless current_user.nil? %></li>
</ul>
</li>
</ul>
<div class="visible-xs navbar-form">
<div class="form-group">
<% if user_signed_in? %>
<%= button_to "Logout", destroy_user_session_path(current_user), class: "btn btn-default form-control", method: :delete %>
<% else %>
<%= button_to "Login", new_user_session_path, class: "btn btn-success form-control" %>
<% end %>
</div>
</div>
</div><!-- /.navbar-collapse -->
</div><!-- /.container-fluid -->
</nav>

View file

@ -0,0 +1,5 @@
class AddAdminToUsers < ActiveRecord::Migration
def change
add_column :users, :admin, :boolean
end
end

View file

@ -11,7 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20141209172818) do
ActiveRecord::Schema.define(version: 20141209184030) do
create_table "order_products", force: true do |t|
t.integer "order_id"
@ -54,6 +54,7 @@ ActiveRecord::Schema.define(version: 20141209172818) do
t.datetime "last_sign_in_at"
t.string "current_sign_in_ip"
t.string "last_sign_in_ip"
t.boolean "admin"
end
end