Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Data-Centric Security

Data-Centric Security

Avatar for Boris Staal

Boris Staal

October 13, 2013

Other Decks in Programming

Transcript

  1. Card Model Title Number Cardholder Admin Other read write read

    write read write read write read write read write
  2. class Card < ActiveRecord::Base protect do |user| if user.admin? can

    :view cannot :view, :number can :create can :update, %w(title number) can :destroy end end end
  3. class Card < ActiveRecord::Base protect do |user, card| if card.try(:user_id)

    == user.id can :view cannot :view, :number can :create can :update, %w(title number) can :destroy end end end
  4. { title: 'My Account', number: '1234567890', cards_attributes: [ { title:

    'My Card', number: '4242424242424242', transactions_attributes: [ { date: '2013-01-01 20:40:00', sum: 100.4 } ] } ] }
  5. class Card < ActiveRecord::Base protect do |user| if user.admin? scope

    { all } else scope { where(hidden: false) } end end end
  6. class CardsController def index @cards = Card.restrict!(current_user) .page(params[:page]) end def

    update Card.restrict!(current_user) .find(params[:id]) .update_attributes(params[:card]) end end ORM SAFE