Skip to content

Commit

Permalink
habilidad de admin a user #48
Browse files Browse the repository at this point in the history
  • Loading branch information
juanjcsr committed Jun 5, 2014
1 parent 2ab6cdc commit 7f68609
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 8 deletions.
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ group :development, :test do
gem "binding_of_caller"
end

gem "cancan"
gem "cancancan"
gem 'rails_admin'


Expand Down
4 changes: 2 additions & 2 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ GEM
binding_of_caller (0.7.2)
debug_inspector (>= 0.0.1)
builder (3.1.4)
cancan (1.6.10)
cancancan (1.8.1)
capybara (2.3.0)
mime-types (>= 1.16)
nokogiri (>= 1.3.3)
Expand Down Expand Up @@ -315,7 +315,7 @@ PLATFORMS
DEPENDENCIES
better_errors
binding_of_caller
cancan
cancancan
capybara
childprocess
coffee-rails (= 4.0.0)
Expand Down
3 changes: 2 additions & 1 deletion app/models/ability.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ def initialize(user)
# See the wiki for details:
# https://github.com/ryanb/cancan/wiki/Defining-Abilities
can :read, :all
if user
user ||= User.new
if user && user.is_admin?
can :access, :rails_admin
can :dashboard
can :manage, :all
Expand Down
4 changes: 4 additions & 0 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ def complete_action!(accion)
end
end

def is_admin?
admin
end


def following?(other_user)
friend_relationships.find_by(followed_id: other_user.id)
Expand Down
5 changes: 5 additions & 0 deletions db/migrate/20140605160019_add_admin_to_users.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddAdminToUsers < ActiveRecord::Migration
def change
add_column :users, :admin, :boolean, default: false
end
end
9 changes: 5 additions & 4 deletions db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 20140506164203) do
ActiveRecord::Schema.define(version: 20140605160019) do

create_table "acciones", force: true do |t|
t.string "name"
Expand Down Expand Up @@ -73,12 +73,12 @@
add_index "relationships", ["user_id"], name: "index_relationships_on_user_id"

create_table "users", force: true do |t|
t.string "email", default: "", null: false
t.string "encrypted_password", default: "", null: false
t.string "email", default: "", null: false
t.string "encrypted_password", default: "", null: false
t.string "reset_password_token"
t.datetime "reset_password_sent_at"
t.datetime "remember_created_at"
t.integer "sign_in_count", default: 0, null: false
t.integer "sign_in_count", default: 0, null: false
t.datetime "current_sign_in_at"
t.datetime "last_sign_in_at"
t.string "current_sign_in_ip"
Expand All @@ -94,6 +94,7 @@
t.string "access_token_fb"
t.string "access_token_tw"
t.string "access_token_gp"
t.boolean "admin", default: false
end

add_index "users", ["email"], name: "index_users_on_email", unique: true
Expand Down
2 changes: 2 additions & 0 deletions spec/models/user_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
it { should respond_to(:follow!) }
it { should respond_to(:reverse_friend_relationships) }
it { should respond_to(:followers) }
it { should respond_to(:admin) }
it { should respond_to(:is_admin?) }

describe "seguir accion" do
let(:accion) { FactoryGirl.create(:accion) }
Expand Down

0 comments on commit 7f68609

Please sign in to comment.