rails_admin_authorized_fields 1.0.0 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 54165817f5a8bf34fa0b91f39688ae4c8db87eda
|
4
|
+
data.tar.gz: 15a7a8a485a62e132bfcf7ca816426321281c4de
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
|
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
|
|
@@ -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?(
|
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?(
|
72
|
+
@parent.plugin_included?(self)
|
68
73
|
end
|
69
74
|
|
70
75
|
def field_authorization_rules(name)
|
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.
|
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
|