protected_attributes_continued 1.7.0 → 1.8.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
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3a53af38e43c5d8fee4bf8cb3f199422844d27b7104ac13e3c31b7bdc7af192a
|
4
|
+
data.tar.gz: 318cd88bd28f923e8ba90c5dc9e8e837cab4427501adde30b1797ab24234c96d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d9dcf4759ad7112b4b8d3191c28458ae8aa36503ae945fc481ca798e1c3e4f86bc815fc63da6d0dee616f88b70563c30e8d5a19da6ac26c05eecdf99172a2540
|
7
|
+
data.tar.gz: d3ffa567d9ce6896bb1ddd398a796eef5bedbf090dc08e8b00db56cdc4b132cc9776ed42b48a637382b1027dff2f40a419a8f7f4e965132ac996b21b00043e90
|
data/README.md
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
# Protected Attributes Continued
|
2
2
|
<a href="https://badge.fury.io/rb/protected_attributes_continued" target="_blank"><img height="21" style='border:0px;height:21px;' border='0' src="https://badge.fury.io/rb/protected_attributes_continued.svg" alt="Gem Version"></a>
|
3
|
-
<a href='https://
|
3
|
+
<a href='https://github.com/westonganger/protected_attributes_continued/actions' target='_blank'><img src="https://github.com/westonganger/protected_attributes_continued/workflows/Tests/badge.svg" style="max-width:100%;" height='21' style='border:0px;height:21px;' border='0' alt="CI Status"></a>
|
4
4
|
<a href='https://rubygems.org/gems/protected_attributes_continued' target='_blank'><img height='21' style='border:0px;height:21px;' src='https://ruby-gem-downloads-badge.herokuapp.com/protected_attributes_continued?label=rubygems&type=total&total_label=downloads&color=brightgreen' border='0' alt='RubyGems Downloads' /></a>
|
5
5
|
|
6
|
-
> This is the community continued version of [`protected_attributes`](https://github.com/rails/protected_attributes) for Rails 5+.
|
6
|
+
> This is the community continued version of [`protected_attributes`](https://github.com/rails/protected_attributes) for Rails 5+. The Rails team dropped this feature and switched to `strong_parameters`. However some applications simply cannot be upgraded or the reduced granularity in params management is a non-issue. To continue supporting this feature going forward we continue the work here.
|
7
7
|
|
8
8
|
Protect attributes from mass-assignment in Active Record models. This gem adds the class methods `attr_accessible` and `attr_protected` to declare white or black lists of attributes.
|
9
9
|
|
@@ -98,7 +98,7 @@ Any protected attributes violation raises `ActiveModel::MassAssignmentSecurity::
|
|
98
98
|
|
99
99
|
## Contributing
|
100
100
|
|
101
|
-
For quicker feedback during gem development or debugging feel free to use the provided `rake console` task. It is defined within the [`Rakefile`](
|
101
|
+
For quicker feedback during gem development or debugging feel free to use the provided `rake console` task. It is defined within the [`Rakefile`](./Rakefile).
|
102
102
|
|
103
103
|
We test multiple versions of `Rails` using the `appraisal` gem. Please use the following steps to test using `appraisal`.
|
104
104
|
|
@@ -118,9 +118,24 @@ While I do utilize this gem in some legacy projects. The latest approach I have
|
|
118
118
|
```ruby
|
119
119
|
### Model
|
120
120
|
class Post < ActiveRecord::Base
|
121
|
+
has_many :comments
|
122
|
+
|
123
|
+
accepts_nested_attributes_for :comments, allow_destroy: true
|
124
|
+
|
121
125
|
def self.strong_params(params)
|
122
|
-
params.permit(:post).permit(
|
126
|
+
params.permit(:post).permit(*PERMITTED_ATTRIBUTES)
|
123
127
|
end
|
128
|
+
|
129
|
+
PERMITTED_PARAMETERS = [
|
130
|
+
:id,
|
131
|
+
:name,
|
132
|
+
:content,
|
133
|
+
:published_at,
|
134
|
+
{
|
135
|
+
comments_attributes: Comment::PERMITTED_PARAMETERS,
|
136
|
+
}
|
137
|
+
].freeze
|
138
|
+
|
124
139
|
end
|
125
140
|
|
126
141
|
### Controller
|
@@ -1,27 +1,33 @@
|
|
1
|
-
|
1
|
+
module ActiveRecord
|
2
|
+
class AssociationRelation
|
3
|
+
undef :new
|
4
|
+
undef :create
|
5
|
+
undef :create!
|
2
6
|
|
3
|
-
|
4
|
-
|
5
|
-
undef :new
|
6
|
-
undef :create
|
7
|
-
undef :create!
|
8
|
-
|
9
|
-
def build(attributes = nil, options = {}, &block)
|
10
|
-
block = _deprecated_scope_block("new", &block)
|
7
|
+
def build(attributes = nil, options = {}, &block)
|
8
|
+
if ActiveRecord::VERSION::STRING.to_f < 5.2
|
11
9
|
scoping { @association.build(attributes, options, &block) }
|
10
|
+
else
|
11
|
+
@association.build(attributes, options, &block)
|
12
12
|
end
|
13
|
-
|
13
|
+
end
|
14
|
+
alias new build
|
14
15
|
|
15
|
-
|
16
|
-
|
16
|
+
def create(attributes = nil, options = {}, &block)
|
17
|
+
if ActiveRecord::VERSION::STRING.to_f < 5.2
|
17
18
|
scoping { @association.create(attributes, options, &block) }
|
19
|
+
else
|
20
|
+
@association.create(attributes, options, &block)
|
18
21
|
end
|
22
|
+
end
|
19
23
|
|
20
|
-
|
21
|
-
|
24
|
+
def create!(attributes = nil, options = {}, &block)
|
25
|
+
if ActiveRecord::VERSION::STRING.to_f < 5.2
|
22
26
|
scoping { @association.create!(attributes, options, &block) }
|
27
|
+
else
|
28
|
+
@association.create!(attributes, options, &block)
|
23
29
|
end
|
24
30
|
end
|
25
|
-
end
|
26
31
|
|
32
|
+
end
|
27
33
|
end
|
@@ -12,9 +12,17 @@ module ActiveRecord
|
|
12
12
|
|
13
13
|
# The primary key and inheritance column can never be set by mass-assignment for security reasons.
|
14
14
|
def attributes_protected_by_default
|
15
|
-
|
16
|
-
|
17
|
-
|
15
|
+
begin
|
16
|
+
default = [primary_key, inheritance_column]
|
17
|
+
|
18
|
+
if !primary_key.eql?('id')
|
19
|
+
default << 'id'
|
20
|
+
end
|
21
|
+
rescue ActiveRecord::NoDatabaseError
|
22
|
+
default = []
|
23
|
+
end
|
24
|
+
|
25
|
+
return default
|
18
26
|
end
|
19
27
|
end
|
20
28
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: protected_attributes_continued
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.8.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Weston Ganger
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-03-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activemodel
|
@@ -66,20 +66,6 @@ dependencies:
|
|
66
66
|
- - ">="
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '5.0'
|
69
|
-
- !ruby/object:Gem::Dependency
|
70
|
-
name: sqlite3
|
71
|
-
requirement: !ruby/object:Gem::Requirement
|
72
|
-
requirements:
|
73
|
-
- - ">="
|
74
|
-
- !ruby/object:Gem::Version
|
75
|
-
version: '0'
|
76
|
-
type: :development
|
77
|
-
prerelease: false
|
78
|
-
version_requirements: !ruby/object:Gem::Requirement
|
79
|
-
requirements:
|
80
|
-
- - ">="
|
81
|
-
- !ruby/object:Gem::Version
|
82
|
-
version: '0'
|
83
69
|
- !ruby/object:Gem::Dependency
|
84
70
|
name: mocha
|
85
71
|
requirement: !ruby/object:Gem::Requirement
|