rails_admin_authorized_fields 1.0.0 → 1.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: cfc10142f5dda9f9ea86cf24a2e53ce73ffbcb8a
4
- data.tar.gz: c76f3e89d0a435f250d48d97d92d82c9767c34e6
3
+ metadata.gz: 54165817f5a8bf34fa0b91f39688ae4c8db87eda
4
+ data.tar.gz: 15a7a8a485a62e132bfcf7ca816426321281c4de
5
5
  SHA512:
6
- metadata.gz: ccab6dc93d869fd9f355aa21da604c2799e75568211992cef35cb9180cf1f4d0aae24311b9a5438857796a68143b659f07804221dcb657ae6fa4c42d32c79ab4
7
- data.tar.gz: 3d260de5a2ab2a616480fa20675d49a3f3382b56ab9572d1588079d00caba4e1f75f73de91c4e2537c49b7e1f41973c969685ef4988dfb45dda9f565a7305845
6
+ metadata.gz: 74a82a9ce63032d6e4f26a263b64661f8511b9973a975aa2e1ef8e0bfe952e125fa4455ceda13d607fd211840c8c29dc31ecc9272709c2a6faed1ba790e43530
7
+ data.tar.gz: 1692282c0fbd656727549a47209efee155eee679e5725ca59d48f9c83d810df8d6fef338ec058684e912f12321008037e7fa8f16c1cf39ec2768fb601ade2b06
data/README.md CHANGED
@@ -16,6 +16,16 @@ Or install it yourself as:
16
16
 
17
17
  $ gem install rails_admin_authorized_fields
18
18
 
19
+ ## Configuration
20
+
21
+ Create ```initilializers/rails_admin_authorized_fields.rb```:
22
+
23
+ RailsAdminAuthorizedFields.configure do |config|
24
+ config.default_rule = proc { bindings[:view]._current_user.has_role?( :admin ) }
25
+ end
26
+
27
+ ```default_rule``` used when either ```authorized_fields``` or ```unauthorized_fields``` section included but rules for some fields are not specified.
28
+
19
29
  ## Usage
20
30
 
21
31
  Just add ```authorized_fields``` section to your model with specified rules:
@@ -53,7 +63,9 @@ TODO: just a small changes needed to make ```authorized_fields``` section overri
53
63
 
54
64
  ## Changelog
55
65
 
56
- 0.1.0 - changed default authorized logic. In 0.0.3 all fields were authorized by default. In 0.1.0 fields unauthorized when authorized_fields or unauthorized_fields sections are present.
66
+ 1.2.0 - added default authorization rule
67
+
68
+ 1.0.0 - changed default authorized logic. In 0.0.3 all fields were authorized by default. In 1.0.0 fields unauthorized when either ```authorized_fields``` or ```unauthorized_fields``` sections are present.
57
69
 
58
70
  ## Contributing
59
71
 
@@ -1,4 +1,5 @@
1
1
  require "rails_admin_authorized_fields/version"
2
2
 
3
3
  require 'rails_admin/config/sections'
4
+ require 'rails_admin_authorized_fields/configuration'
4
5
  require 'rails_admin_authorized_fields/section'
@@ -0,0 +1,17 @@
1
+ module RailsAdminAuthorizedFields
2
+ class << self
3
+ def configuration
4
+ @configuration ||= Configuration.new
5
+ end
6
+ def config
7
+ configuration
8
+ end
9
+ def configure
10
+ yield configuration
11
+ end
12
+ end
13
+
14
+ class Configuration
15
+ attr_accessor :default_rule
16
+ end
17
+ end
@@ -39,6 +39,11 @@ module RailsAdminAuthorizedFields
39
39
  if field.section.plugin_included?
40
40
  authorized = rules[:allow].any? || rules[:deny].any?
41
41
 
42
+ unless authorized
43
+ default_rule = RailsAdminAuthorizedFields.config.default_rule
44
+ authorized = instance_eval(&default_rule) if default_rule.is_a?( Proc )
45
+ end
46
+
42
47
  rules[:allow].each do |rule|
43
48
  authorized &= instance_eval(&rule)
44
49
  end
@@ -57,14 +62,14 @@ module RailsAdminAuthorizedFields
57
62
 
58
63
  protected
59
64
 
60
- def plugin_included?( descendant = nil )
65
+ def plugin_included?(descendant = nil)
61
66
  result = @allow_rules.any? || @deny_rules.any?
62
67
 
63
68
  return result if result
64
69
  return false if @parent.nil?
65
70
  return false if self == descendant
66
71
 
67
- @parent.plugin_included?( self )
72
+ @parent.plugin_included?(self)
68
73
  end
69
74
 
70
75
  def field_authorization_rules(name)
@@ -1,3 +1,3 @@
1
1
  module RailsAdminAuthorizedFields
2
- VERSION = "1.0.0"
2
+ VERSION = "1.2.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails_admin_authorized_fields
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sergey Malykh
@@ -68,6 +68,7 @@ files:
68
68
  - README.md
69
69
  - Rakefile
70
70
  - lib/rails_admin_authorized_fields.rb
71
+ - lib/rails_admin_authorized_fields/configuration.rb
71
72
  - lib/rails_admin_authorized_fields/section.rb
72
73
  - lib/rails_admin_authorized_fields/version.rb
73
74
  - rails_admin_authorized_fields.gemspec