<commit_before>== MAC -- [M]odel [A]ccess [C]ontrol
This plugin provides Model Security with the "Security in Depth" approach. It accomplishes
this task simply by allowing you to intercept method calls and activerecord callbacks
and run arbitrary code.

=== Installation
script/generate mac
      create  config/initializers/mac.rb

=== Usage
Using the config/initializers/mac.rb file declare your principals, interception points, and filters.

  Mac.configure do |config|
    config.principal User do
      User.current = @session.user
    end

    config.intercept Hauler, [:update, :create] do
      if User.current && User.current == User.first
        return true
      end
      return false
    end

    config.secured_filter [Hauler, Vendor] do
      if User.current && User.current == User.first
        {}
      else
        {:conditions => ["account_id = ?", user.current.account_id]}
      end
    end
  end

While configuring your principals: the block passed to the principal will be used to set an ApplicationController
before filter. It is expected to use this block to set the principal injected class variable current.

While configuring your filters for read activities: the block defined in the configuration will be injected as the 
body of a named_scope :secured within each model listed in the array. In many cases, the secured filters are useful
in defining the logic for your interception points.

For example:

  config.intercept Hauler, [:update, :destroy] do
    can_see = !Hauler.secured.find(:first, :conditions => ["haulers.account_id IN (?) AND haulers.id = ?", User.current.account_ids, self.id]).nil?<commit_msg>README update -- example secured_filter<commit_after>== MAC -- [M]odel [A]ccess [C]ontrol
This plugin provides Model Security with the "Security in Depth" approach. It accomplishes
this task simply by allowing you to intercept method calls and activerecord callbacks
and run arbitrary code.

=== Installation
script/generate mac
      create  config/initializers/mac.rb

=== Usage
Using the config/initializers/mac.rb file declare your principals, interception points, and filters.

  Mac.configure do |config|
    config.principal User do
      User.current = @session.user
    end

    config.intercept Hauler, [:update, :create] do
      if User.current && User.current == User.first
        return true
      end
      return false
    end

    config.secured_filter [Hauler, Vendor] do
      if User.current && User.current == User.first
        {:conditions => ["account_id = ?", User.current.account_id]}
      else
        {:conditions => ["1=0"] }
      end
    end
  end

While configuring your principals: the block passed to the principal will be used to set an ApplicationController
before filter. It is expected to use this block to set the principal injected class variable current.

While configuring your filters for read activities: the block defined in the configuration will be injected as the 
body of a named_scope :secured within each model listed in the array. In many cases, the secured filters are useful
in defining the logic for your interception points.

For example:

  config.intercept Hauler, [:update, :destroy] do
    can_see = !Hauler.secured.find(:first, :conditions => ["haulers.account_id IN (?) AND haulers.id = ?", User.current.account_ids, self.id]).nil?
{'fraction_non_alphanumeric': 0.07901825800658485, 'fraction_numerical': 0.000598623166716552, 'mean_word_length': 3.590659340659341, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 8, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1240906', 'n_tokens_mistral': 917, 'n_tokens_neox': 876, 'n_words': 378}