diff --git a/Gemfile b/Gemfile index 6e7d8fc..435d153 100644 --- a/Gemfile +++ b/Gemfile @@ -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' diff --git a/Gemfile.lock b/Gemfile.lock index 5b60a75..ae209a0 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -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 diff --git a/app/models/ability.rb b/app/models/ability.rb new file mode 100644 index 0000000..047c60f --- /dev/null +++ b/app/models/ability.rb @@ -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 diff --git a/app/views/layouts/_header.html.erb b/app/views/layouts/_header.html.erb index 805918d..6e55a32 100644 --- a/app/views/layouts/_header.html.erb +++ b/app/views/layouts/_header.html.erb @@ -7,45 +7,55 @@ - <%= link_to "Tab", root_path, class: "navbar-brand" %> + <%= link_to "TaĆ¾", root_path, class: "navbar-brand" %> diff --git a/db/migrate/20141209184030_add_admin_to_users.rb b/db/migrate/20141209184030_add_admin_to_users.rb new file mode 100644 index 0000000..2ddf290 --- /dev/null +++ b/db/migrate/20141209184030_add_admin_to_users.rb @@ -0,0 +1,5 @@ +class AddAdminToUsers < ActiveRecord::Migration + def change + add_column :users, :admin, :boolean + end +end diff --git a/db/schema.rb b/db/schema.rb index e52179a..d3d9759 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -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