bhm-admin 0.1.4 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/bhm-admin.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{bhm-admin}
8
- s.version = "0.1.4"
8
+ s.version = "0.2.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Darcy Laycock"]
12
- s.date = %q{2010-07-18}
12
+ s.date = %q{2010-07-27}
13
13
  s.description = %q{Provides a reasonably dynamic and simple to use admin area for Rails 3 application. Built on a bunch of open source libraries.}
14
14
  s.email = %q{sutto@sutto.net}
15
15
  s.extra_rdoc_files = [
@@ -8,7 +8,11 @@ module BHM
8
8
  attr_accessor :verbose
9
9
 
10
10
  def disabled?
11
- !!Thread.current[:attr_accessible_disabled]
11
+ !enabled?
12
+ end
13
+
14
+ def enabled?
15
+ !Thread.current[:attr_accessible_disabled]
12
16
  end
13
17
 
14
18
  def disable!
@@ -22,29 +26,40 @@ module BHM
22
26
  def disable
23
27
  disabled = disabled?
24
28
  disable! if !disabled
25
- begin
26
- yield if block_given?
27
- ensure
28
- enable! if disabled
29
- end
29
+ yield if block_given?
30
+ ensure
31
+ enable! if disabled
30
32
  end
31
33
 
32
34
  end
33
35
 
34
- module ARMixin
36
+ class Sanitizer < ActiveModel::MassAssignmentSecurity::WhiteList
35
37
 
36
- def self.included(parent)
37
- parent.alias_method_chain :remove_attributes_protected_from_mass_assignment, :global_disable
38
+ def deny?(attribute)
39
+ return false if BHM::Admin::AttrAccessibleScoping.disabled? || self.include?("all")
40
+ super
38
41
  end
39
42
 
40
- def remove_attributes_protected_from_mass_assignment_with_global_disable(attributes)
41
- unless AttrAccessibleScoping.disabled? || (self.class.accessible_attributes && self.class.accessible_attributes.include?("all"))
42
- trusted_attributes = Array(self.class.accessible_attributes)
43
- attributes.each_pair do |k, v|
44
- raise UnassignableAttribute, "The attribute #{k} can't be assigned on #{self.class.name}" unless trusted_attributes.include?(k.to_s.gsub(/\(\d+\w\)$/, ''))
43
+ protected
44
+
45
+ def warn!(attrs)
46
+ super
47
+ raise UnassignableAttribute.new("Unable to assign attributes: #{attrs.join(", ")}")
48
+ end
49
+
50
+ end
51
+
52
+ module ARMixin
53
+
54
+ def accessible_attributes
55
+ if _accessible_attributes.blank? || !_accessible_attributes.is_a?(BHM::Admin::AttrAccessibleScoping::Sanitizer)
56
+ existing = _accessible_attributes
57
+ self._accessible_attributes = BHM::Admin::AttrAccessibleScoping::Sanitizer.new.tap do |w|
58
+ w.logger = self.logger if self.respond_to?(:logger)
45
59
  end
60
+ self._accessible_attributes += existing if existing.present?
46
61
  end
47
- attributes
62
+ _accessible_attributes
48
63
  end
49
64
 
50
65
  end
@@ -1,16 +1,9 @@
1
1
  module BHM
2
2
  module Admin
3
3
  class Engine < Rails::Engine
4
-
5
- # paths.config.locales = BHM::Admin.root.join('config', 'locales')
6
- # paths.config.controllers = BHM::Admin.root.join('app', 'controller')
7
- # paths.config.views = BHM::Admin.root.join('app', 'views')
8
-
9
- initializer :configure_compass do
10
- end
11
4
 
12
5
  initializer :extend_activerecord do
13
- ActiveRecord::Base.send :include, BHM::Admin::AttrAccessibleScoping::ARMixin
6
+ ActiveRecord::Base.extend BHM::Admin::AttrAccessibleScoping::ARMixin
14
7
  end
15
8
 
16
9
  end
data/lib/bhm/admin.rb CHANGED
@@ -3,7 +3,7 @@ require 'active_support'
3
3
  module BHM
4
4
  module Admin
5
5
 
6
- VERSION = "0.1.4".freeze
6
+ VERSION = "0.2.0".freeze
7
7
 
8
8
  # Helpers for use in the admin area.
9
9
  autoload :SidebarHelper, 'bhm/admin/sidebar_helper'
@@ -30,6 +30,18 @@ module BHM
30
30
  [SidebarHelper, PresentationHelper, NestedFormHelper]
31
31
  end
32
32
 
33
+ def self.disable_attr_accessible(&blk)
34
+ AttrAccessibleScoping.disable(&blk)
35
+ end
36
+
37
+ def self.disable_attr_accessible!
38
+ AttrAccessibleScoping.disable!
39
+ end
40
+
41
+ def self.enable_attr_accessible!
42
+ AttrAccessibleScoping.enable!
43
+ end
44
+
33
45
  # Hook into rails.
34
46
  require 'bhm/admin/engine' if defined?(Rails::Engine)
35
47
  require 'bhm/admin/compass_framework' if defined?(Compass)
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bhm-admin
3
3
  version: !ruby/object:Gem::Version
4
- hash: 19
4
+ hash: 23
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
- - 1
9
- - 4
10
- version: 0.1.4
8
+ - 2
9
+ - 0
10
+ version: 0.2.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Darcy Laycock
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-07-18 00:00:00 +08:00
18
+ date: 2010-07-27 00:00:00 +08:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency