protected_attributes_continued 1.7.0 → 1.8.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
  SHA256:
3
- metadata.gz: 4cc976fa47e5942c610f0ba64d976c46e83797255c60fd504f79e30677164632
4
- data.tar.gz: 3127f37fc4fb6222ed6fbef07fedbe449a65fd5caa919d3a43bc65c17f86c2c2
3
+ metadata.gz: 3a53af38e43c5d8fee4bf8cb3f199422844d27b7104ac13e3c31b7bdc7af192a
4
+ data.tar.gz: 318cd88bd28f923e8ba90c5dc9e8e837cab4427501adde30b1797ab24234c96d
5
5
  SHA512:
6
- metadata.gz: f7776d77b1898ee1b0b9713102a1be01c9de945f7cb23160a00a3af4f205f15f05ca9e6f58bc5510e4cb68606174fe1d6a835a9a2756ff866cd7849a54fcadaf
7
- data.tar.gz: c821bb84db6db202e524a535c7b098e2976cd423946e95325fc421f88d35077e645e166ae10f9f01f82de0e52d2decdb1781690806392a661ea9d8fecd8444de
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://travis-ci.com/westonganger/protected_attributes_continued' target='_blank'><img height='21' style='border:0px;height:21px;' src='https://api.travis-ci.org/westonganger/protected_attributes_continued.svg?branch=master' border='0' alt='Build Status' /></a>
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+. I recommend you only use it to support legacy portions of your application that you do not want to upgrade. The Rails team dropped this feature and switched to `strong_parameters` because of security issues. However some applications simply cannot be upgraded or security like this is a non-issue. To continue supporting this feature going forward lets continue the work here.
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`](https://github.com/westonganger/protected_attributes_continued/blob/master/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(:name, :content, :published_at)
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
- if ActiveRecord::VERSION::MAJOR >= 6
1
+ module ActiveRecord
2
+ class AssociationRelation
3
+ undef :new
4
+ undef :create
5
+ undef :create!
2
6
 
3
- module ActiveRecord
4
- class AssociationRelation
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
- alias new build
13
+ end
14
+ alias new build
14
15
 
15
- def create(attributes = nil, options = {}, &block)
16
- block = _deprecated_scope_block("create", &block)
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
- def create!(attributes = nil, options = {}, &block)
21
- block = _deprecated_scope_block("create!", &block)
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
- default = [ primary_key, inheritance_column ]
16
- default << 'id' unless primary_key.eql? 'id'
17
- default
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
 
@@ -1,3 +1,3 @@
1
1
  module ProtectedAttributes
2
- VERSION = "1.7.0".freeze
2
+ VERSION = "1.8.0".freeze
3
3
  end
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.7.0
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: 2020-10-25 00:00:00.000000000 Z
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