jsonapi-authorization 1.0.0 → 3.0.2

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: 9964c80bda556e297a4e6fc123a35d213debefa7d418ab60d627f9eb3401f334
4
- data.tar.gz: 64e0146d4b454e7417b7e4afd2ee6c9b4d365a7c62d3a2993e44f2c006711542
3
+ metadata.gz: eca7bc758c4afda473090e94e6774b61bb708807817abb5961ca597a404605d6
4
+ data.tar.gz: 610d8c4508699047d991cf18c17a31dfd59938a5b63f9a8df741c16e28030c3c
5
5
  SHA512:
6
- metadata.gz: f729a9f5b558008f1baa2c7760f4f31ce59b06e86d2d9bf56894a0e3f648eb985e05e998f3d8718b39f6d3b0d913757ff48ace6ae399cbd2519fa0f72afccad6
7
- data.tar.gz: 68925bea3461cea96c3538b76c85b222e43bb8565e401a881f021d40a1a4c9ecc37021c0487d25efbdc66b339e17b2bb042d2c29da41a544a86416bc37c57b38
6
+ metadata.gz: 8a36bbf5c7685f976dab29924e6b736548c62058e965ae12287f747897fb2933dd9dbe842135d93ad03994ab6e3899ec6feeea57041944dff034b381c57fa8a4
7
+ data.tar.gz: cf13d084a0618608cb3f2af6bd9d43ba03c73bf217f33dd4ba12b7bfa10544d23d2d7bab51aab858460127d69758ac10f6ce890df4361188d25d9ddb62005066
data/.all-contributorsrc CHANGED
@@ -126,7 +126,30 @@
126
126
  "test",
127
127
  "infra"
128
128
  ]
129
+ },
130
+ {
131
+ "login": "Matthijsy",
132
+ "name": "Matthijsy",
133
+ "avatar_url": "https://avatars2.githubusercontent.com/u/5302372?v=4",
134
+ "profile": "https://github.com/Matthijsy",
135
+ "contributions": [
136
+ "bug",
137
+ "test",
138
+ "code"
139
+ ]
140
+ },
141
+ {
142
+ "login": "brianswko",
143
+ "name": "brianswko",
144
+ "avatar_url": "https://avatars0.githubusercontent.com/u/3952486?v=4",
145
+ "profile": "https://github.com/brianswko",
146
+ "contributions": [
147
+ "bug",
148
+ "test",
149
+ "code"
150
+ ]
129
151
  }
130
152
  ],
131
- "repoType": "github"
153
+ "repoType": "github",
154
+ "contributorsPerLine": 7
132
155
  }
data/.gitignore CHANGED
@@ -11,3 +11,4 @@
11
11
  *.orig
12
12
  .ruby-version
13
13
  /gemfiles/*.gemfile.lock
14
+ /gemfiles/.bundle/
data/.travis.yml CHANGED
@@ -1,4 +1,7 @@
1
1
  language: ruby
2
+ branches:
3
+ only:
4
+ - master
2
5
  rvm:
3
6
  - 2.3
4
7
  gemfile:
@@ -11,7 +14,6 @@ gemfile:
11
14
  - gemfiles/rails_5_1_pundit_2.gemfile
12
15
  - gemfiles/rails_5_2_pundit_2.gemfile
13
16
  before_install:
14
- - rvm @global do gem uninstall bundler -a -x
15
17
  - gem install bundler -v '< 2'
16
18
  notifications:
17
19
  email: false
data/Appraisals CHANGED
@@ -1,47 +1,47 @@
1
1
  appraise 'rails-4-2 pundit-1' do
2
2
  gem 'rails', '4.2.0'
3
- gem 'jsonapi-resources', '~> 0.9'
3
+ gem 'jsonapi-resources', '~> 0.9.0'
4
4
  gem 'pundit', '~> 1.0'
5
5
  end
6
6
 
7
7
  appraise 'rails-5-0 pundit-1' do
8
8
  gem 'rails', '5.0.0'
9
- gem 'jsonapi-resources', '~> 0.9'
9
+ gem 'jsonapi-resources', '~> 0.9.0'
10
10
  gem 'pundit', '~> 1.0'
11
11
  end
12
12
 
13
13
  appraise 'rails-5-1 pundit-1' do
14
14
  gem "rails", "5.1.0"
15
- gem 'jsonapi-resources', '~> 0.9'
15
+ gem 'jsonapi-resources', '~> 0.9.0'
16
16
  gem 'pundit', '~> 1.0'
17
17
  end
18
18
 
19
19
  appraise 'rails-5-2 pundit-1' do
20
20
  gem 'rails', '5.2.0'
21
- gem 'jsonapi-resources', '~> 0.9'
21
+ gem 'jsonapi-resources', '~> 0.9.0'
22
22
  gem 'pundit', '~> 1.0'
23
23
  end
24
24
 
25
25
  appraise 'rails-4-2 pundit-2' do
26
26
  gem 'rails', '4.2.0'
27
- gem 'jsonapi-resources', '~> 0.9'
27
+ gem 'jsonapi-resources', '~> 0.9.0'
28
28
  gem 'pundit', '~> 2.0'
29
29
  end
30
30
 
31
31
  appraise 'rails-5-0 pundit-2' do
32
32
  gem 'rails', '5.0.0'
33
- gem 'jsonapi-resources', '~> 0.9'
33
+ gem 'jsonapi-resources', '~> 0.9.0'
34
34
  gem 'pundit', '~> 2.0'
35
35
  end
36
36
 
37
37
  appraise 'rails-5-1 pundit-2' do
38
38
  gem 'rails', '5.1.0'
39
- gem 'jsonapi-resources', '~> 0.9'
39
+ gem 'jsonapi-resources', '~> 0.9.0'
40
40
  gem 'pundit', '~> 2.0'
41
41
  end
42
42
 
43
43
  appraise 'rails-5-2 pundit-2' do
44
44
  gem 'rails', '5.2.0'
45
- gem 'jsonapi-resources', '~> 0.9'
45
+ gem 'jsonapi-resources', '~> 0.9.0'
46
46
  gem 'pundit', '~> 2.0'
47
47
  end
data/README.md CHANGED
@@ -33,8 +33,6 @@ This gem should work out-of-the box for simple cases. The default authorizer mig
33
33
 
34
34
  **If you are modifying relationships**, you should read the [relationship authorization documentation](docs/relationship-authorization.md).
35
35
 
36
- The API is subject to change between minor version bumps until we reach v1.0.0.
37
-
38
36
  ## Installation
39
37
 
40
38
  Add this line to your application's Gemfile:
@@ -55,10 +53,19 @@ Or install it yourself as:
55
53
 
56
54
  * `v0.6.x` supports JR `v0.7.x`
57
55
  * `v0.8.x` supports JR `v0.8.x`
58
- * `v1.0.0` alpha and beta releases support JR `v0.9.x`
56
+ * Later releases support JR `v0.9.x`
57
+ * **JR `v0.10.x` is NOT SUPPORTED.** See https://github.com/venuu/jsonapi-authorization/issues/64 for more details and to offer help.
59
58
 
60
59
  We aim to support the same Ruby and Ruby on Rails versions as `jsonapi-resources` does. If that's not the case, please [open an issue][issues].
61
60
 
61
+ ## Versioning and changelog
62
+
63
+ `jsonapi-authorization` follows [Semantic Versioning](https://semver.org/). We prefer to make more major version bumps when we do changes that are likely to be backwards incompatible. That holds true even when it's likely the changes would be backwards compatible for a majority of our users.
64
+
65
+ Given the nature of an authorization library, it is likely that most changes are major version bumps.
66
+
67
+ Whenever we do changes, we strive to write good changelogs in the [GitHub releases page](https://github.com/venuu/jsonapi-authorization/releases).
68
+
62
69
  ## Usage
63
70
 
64
71
  First make sure you have a Pundit policy specified for every backing model that your JR resources use.
@@ -185,9 +192,8 @@ Thanks goes to these wonderful people ([emoji key](https://github.com/kentcdodds
185
192
 
186
193
  <!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section -->
187
194
  <!-- prettier-ignore -->
188
- | [<img src="https://avatars.githubusercontent.com/u/482561?v=3" width="100px;"/><br /><sub><b>Vesa Laakso</b></sub>](http://vesalaakso.com)<br />[💻](https://github.com/Venuu/jsonapi-authorization/commits?author=valscion "Code") [📖](https://github.com/Venuu/jsonapi-authorization/commits?author=valscion "Documentation") [🚇](#infra-valscion "Infrastructure (Hosting, Build-Tools, etc)") [⚠️](https://github.com/Venuu/jsonapi-authorization/commits?author=valscion "Tests") [🐛](https://github.com/Venuu/jsonapi-authorization/issues?q=author%3Avalscion "Bug reports") [💬](#question-valscion "Answering Questions") [👀](#review-valscion "Reviewed Pull Requests") | [<img src="https://avatars.githubusercontent.com/u/562204?v=3" width="100px;"/><br /><sub><b>Emil Sågfors</b></sub>](https://github.com/lime)<br />[💻](https://github.com/Venuu/jsonapi-authorization/commits?author=lime "Code") [📖](https://github.com/Venuu/jsonapi-authorization/commits?author=lime "Documentation") [🚇](#infra-lime "Infrastructure (Hosting, Build-Tools, etc)") [⚠️](https://github.com/Venuu/jsonapi-authorization/commits?author=lime "Tests") [🐛](https://github.com/Venuu/jsonapi-authorization/issues?q=author%3Alime "Bug reports") [💬](#question-lime "Answering Questions") [👀](#review-lime "Reviewed Pull Requests") | [<img src="https://avatars.githubusercontent.com/u/1591161?v=3" width="100px;"/><br /><sub><b>Matthias Grundmann</b></sub>](https://github.com/matthias-g)<br />[💻](https://github.com/Venuu/jsonapi-authorization/commits?author=matthias-g "Code") [📖](https://github.com/Venuu/jsonapi-authorization/commits?author=matthias-g "Documentation") [⚠️](https://github.com/Venuu/jsonapi-authorization/commits?author=matthias-g "Tests") [💬](#question-matthias-g "Answering Questions") | [<img src="https://avatars.githubusercontent.com/u/1322?v=3" width="100px;"/><br /><sub><b>Thibaud Guillaume-Gentil</b></sub>](http://thibaud.gg)<br />[💻](https://github.com/Venuu/jsonapi-authorization/commits?author=thibaudgg "Code") | [<img src="https://avatars.githubusercontent.com/u/71660?v=3" width="100px;"/><br /><sub><b>Daniel Schweighöfer</b></sub>](http://netsteward.net)<br />[💻](https://github.com/Venuu/jsonapi-authorization/commits?author=acid "Code") | [<img src="https://avatars.githubusercontent.com/u/5076967?v=3" width="100px;"/><br /><sub><b>Bruno Sofiato</b></sub>](https://github.com/bsofiato)<br />[💻](https://github.com/Venuu/jsonapi-authorization/commits?author=bsofiato "Code") | [<img src="https://avatars.githubusercontent.com/u/1896026?v=3" width="100px;"/><br /><sub><b>Adam Robertson</b></sub>](https://github.com/arcreative)<br />[📖](https://github.com/Venuu/jsonapi-authorization/commits?author=arcreative "Documentation") |
189
- | :---: | :---: | :---: | :---: | :---: | :---: | :---: |
190
- | [<img src="https://avatars3.githubusercontent.com/u/4742306?v=3" width="100px;"/><br /><sub><b>Greg Fisher</b></sub>](https://github.com/gnfisher)<br />[💻](https://github.com/Venuu/jsonapi-authorization/commits?author=gnfisher "Code") [⚠️](https://github.com/Venuu/jsonapi-authorization/commits?author=gnfisher "Tests") | [<img src="https://avatars3.githubusercontent.com/u/370182?v=3" width="100px;"/><br /><sub><b>Sam</b></sub>](http://samlh.com)<br />[💻](https://github.com/Venuu/jsonapi-authorization/commits?author=handlers "Code") [⚠️](https://github.com/Venuu/jsonapi-authorization/commits?author=handlers "Tests") | [<img src="https://avatars0.githubusercontent.com/u/2738630?v=3" width="100px;"/><br /><sub><b>Justas Palumickas</b></sub>](https://jpalumickas.com)<br />[🐛](https://github.com/Venuu/jsonapi-authorization/issues?q=author%3Ajpalumickas "Bug reports") [💻](https://github.com/Venuu/jsonapi-authorization/commits?author=jpalumickas "Code") [⚠️](https://github.com/Venuu/jsonapi-authorization/commits?author=jpalumickas "Tests") | [<img src="https://avatars1.githubusercontent.com/u/26158?v=4" width="100px;"/><br /><sub><b>Nicholas Rutherford</b></sub>](http://www.google.co.uk/profiles/nick.rutherford)<br />[💻](https://github.com/Venuu/jsonapi-authorization/commits?author=nruth "Code") [⚠️](https://github.com/Venuu/jsonapi-authorization/commits?author=nruth "Tests") [🚇](#infra-nruth "Infrastructure (Hosting, Build-Tools, etc)") |
195
+ <table><tr><td align="center"><a href="http://vesalaakso.com"><img src="https://avatars.githubusercontent.com/u/482561?v=3" width="100px;" alt="Vesa Laakso"/><br /><sub><b>Vesa Laakso</b></sub></a><br /><a href="https://github.com/Venuu/jsonapi-authorization/commits?author=valscion" title="Code">💻</a> <a href="https://github.com/Venuu/jsonapi-authorization/commits?author=valscion" title="Documentation">📖</a> <a href="#infra-valscion" title="Infrastructure (Hosting, Build-Tools, etc)">🚇</a> <a href="https://github.com/Venuu/jsonapi-authorization/commits?author=valscion" title="Tests">⚠️</a> <a href="https://github.com/Venuu/jsonapi-authorization/issues?q=author%3Avalscion" title="Bug reports">🐛</a> <a href="#question-valscion" title="Answering Questions">💬</a> <a href="#review-valscion" title="Reviewed Pull Requests">👀</a></td><td align="center"><a href="https://github.com/lime"><img src="https://avatars.githubusercontent.com/u/562204?v=3" width="100px;" alt="Emil Sågfors"/><br /><sub><b>Emil Sågfors</b></sub></a><br /><a href="https://github.com/Venuu/jsonapi-authorization/commits?author=lime" title="Code">💻</a> <a href="https://github.com/Venuu/jsonapi-authorization/commits?author=lime" title="Documentation">📖</a> <a href="#infra-lime" title="Infrastructure (Hosting, Build-Tools, etc)">🚇</a> <a href="https://github.com/Venuu/jsonapi-authorization/commits?author=lime" title="Tests">⚠️</a> <a href="https://github.com/Venuu/jsonapi-authorization/issues?q=author%3Alime" title="Bug reports">🐛</a> <a href="#question-lime" title="Answering Questions">💬</a> <a href="#review-lime" title="Reviewed Pull Requests">👀</a></td><td align="center"><a href="https://github.com/matthias-g"><img src="https://avatars.githubusercontent.com/u/1591161?v=3" width="100px;" alt="Matthias Grundmann"/><br /><sub><b>Matthias Grundmann</b></sub></a><br /><a href="https://github.com/Venuu/jsonapi-authorization/commits?author=matthias-g" title="Code">💻</a> <a href="https://github.com/Venuu/jsonapi-authorization/commits?author=matthias-g" title="Documentation">📖</a> <a href="https://github.com/Venuu/jsonapi-authorization/commits?author=matthias-g" title="Tests">⚠️</a> <a href="#question-matthias-g" title="Answering Questions">💬</a></td><td align="center"><a href="http://thibaud.gg"><img src="https://avatars.githubusercontent.com/u/1322?v=3" width="100px;" alt="Thibaud Guillaume-Gentil"/><br /><sub><b>Thibaud Guillaume-Gentil</b></sub></a><br /><a href="https://github.com/Venuu/jsonapi-authorization/commits?author=thibaudgg" title="Code">💻</a></td><td align="center"><a href="http://netsteward.net"><img src="https://avatars.githubusercontent.com/u/71660?v=3" width="100px;" alt="Daniel Schweighöfer"/><br /><sub><b>Daniel Schweighöfer</b></sub></a><br /><a href="https://github.com/Venuu/jsonapi-authorization/commits?author=acid" title="Code">💻</a></td><td align="center"><a href="https://github.com/bsofiato"><img src="https://avatars.githubusercontent.com/u/5076967?v=3" width="100px;" alt="Bruno Sofiato"/><br /><sub><b>Bruno Sofiato</b></sub></a><br /><a href="https://github.com/Venuu/jsonapi-authorization/commits?author=bsofiato" title="Code">💻</a></td><td align="center"><a href="https://github.com/arcreative"><img src="https://avatars.githubusercontent.com/u/1896026?v=3" width="100px;" alt="Adam Robertson"/><br /><sub><b>Adam Robertson</b></sub></a><br /><a href="https://github.com/Venuu/jsonapi-authorization/commits?author=arcreative" title="Documentation">📖</a></td></tr><tr><td align="center"><a href="https://github.com/gnfisher"><img src="https://avatars3.githubusercontent.com/u/4742306?v=3" width="100px;" alt="Greg Fisher"/><br /><sub><b>Greg Fisher</b></sub></a><br /><a href="https://github.com/Venuu/jsonapi-authorization/commits?author=gnfisher" title="Code">💻</a> <a href="https://github.com/Venuu/jsonapi-authorization/commits?author=gnfisher" title="Tests">⚠️</a></td><td align="center"><a href="http://samlh.com"><img src="https://avatars3.githubusercontent.com/u/370182?v=3" width="100px;" alt="Sam"/><br /><sub><b>Sam</b></sub></a><br /><a href="https://github.com/Venuu/jsonapi-authorization/commits?author=handlers" title="Code">💻</a> <a href="https://github.com/Venuu/jsonapi-authorization/commits?author=handlers" title="Tests">⚠️</a></td><td align="center"><a href="https://jpalumickas.com"><img src="https://avatars0.githubusercontent.com/u/2738630?v=3" width="100px;" alt="Justas Palumickas"/><br /><sub><b>Justas Palumickas</b></sub></a><br /><a href="https://github.com/Venuu/jsonapi-authorization/issues?q=author%3Ajpalumickas" title="Bug reports">🐛</a> <a href="https://github.com/Venuu/jsonapi-authorization/commits?author=jpalumickas" title="Code">💻</a> <a href="https://github.com/Venuu/jsonapi-authorization/commits?author=jpalumickas" title="Tests">⚠️</a></td><td align="center"><a href="http://www.google.co.uk/profiles/nick.rutherford"><img src="https://avatars1.githubusercontent.com/u/26158?v=4" width="100px;" alt="Nicholas Rutherford"/><br /><sub><b>Nicholas Rutherford</b></sub></a><br /><a href="https://github.com/Venuu/jsonapi-authorization/commits?author=nruth" title="Code">💻</a> <a href="https://github.com/Venuu/jsonapi-authorization/commits?author=nruth" title="Tests">⚠️</a> <a href="#infra-nruth" title="Infrastructure (Hosting, Build-Tools, etc)">🚇</a></td><td align="center"><a href="https://github.com/Matthijsy"><img src="https://avatars2.githubusercontent.com/u/5302372?v=4" width="100px;" alt="Matthijsy"/><br /><sub><b>Matthijsy</b></sub></a><br /><a href="https://github.com/Venuu/jsonapi-authorization/issues?q=author%3AMatthijsy" title="Bug reports">🐛</a> <a href="https://github.com/Venuu/jsonapi-authorization/commits?author=Matthijsy" title="Tests">⚠️</a> <a href="https://github.com/Venuu/jsonapi-authorization/commits?author=Matthijsy" title="Code">💻</a></td><td align="center"><a href="https://github.com/brianswko"><img src="https://avatars0.githubusercontent.com/u/3952486?v=4" width="100px;" alt="brianswko"/><br /><sub><b>brianswko</b></sub></a><br /><a href="https://github.com/Venuu/jsonapi-authorization/issues?q=author%3Abrianswko" title="Bug reports">🐛</a> <a href="https://github.com/Venuu/jsonapi-authorization/commits?author=brianswko" title="Tests">⚠️</a> <a href="https://github.com/Venuu/jsonapi-authorization/commits?author=brianswko" title="Code">💻</a></td></tr></table>
196
+
191
197
  <!-- ALL-CONTRIBUTORS-LIST:END -->
192
198
 
193
199
  This project follows the [all-contributors](https://github.com/kentcdodds/all-contributors) specification. Contributions of any kind welcome!
@@ -3,7 +3,7 @@
3
3
  source "https://rubygems.org"
4
4
 
5
5
  gem "rails", "4.2.0"
6
- gem "jsonapi-resources", "~> 0.9"
6
+ gem "jsonapi-resources", "~> 0.9.0"
7
7
  gem "pundit", "~> 1.0"
8
8
 
9
9
  gemspec path: "../"
@@ -3,7 +3,7 @@
3
3
  source "https://rubygems.org"
4
4
 
5
5
  gem "rails", "4.2.0"
6
- gem "jsonapi-resources", "~> 0.9"
6
+ gem "jsonapi-resources", "~> 0.9.0"
7
7
  gem "pundit", "~> 2.0"
8
8
 
9
9
  gemspec path: "../"
@@ -3,7 +3,7 @@
3
3
  source "https://rubygems.org"
4
4
 
5
5
  gem "rails", "5.0.0"
6
- gem "jsonapi-resources", "~> 0.9"
6
+ gem "jsonapi-resources", "~> 0.9.0"
7
7
  gem "pundit", "~> 1.0"
8
8
 
9
9
  gemspec path: "../"
@@ -3,7 +3,7 @@
3
3
  source "https://rubygems.org"
4
4
 
5
5
  gem "rails", "5.0.0"
6
- gem "jsonapi-resources", "~> 0.9"
6
+ gem "jsonapi-resources", "~> 0.9.0"
7
7
  gem "pundit", "~> 2.0"
8
8
 
9
9
  gemspec path: "../"
@@ -3,7 +3,7 @@
3
3
  source "https://rubygems.org"
4
4
 
5
5
  gem "rails", "5.1.0"
6
- gem "jsonapi-resources", "~> 0.9"
6
+ gem "jsonapi-resources", "~> 0.9.0"
7
7
  gem "pundit", "~> 1.0"
8
8
 
9
9
  gemspec path: "../"
@@ -3,7 +3,7 @@
3
3
  source "https://rubygems.org"
4
4
 
5
5
  gem "rails", "5.1.0"
6
- gem "jsonapi-resources", "~> 0.9"
6
+ gem "jsonapi-resources", "~> 0.9.0"
7
7
  gem "pundit", "~> 2.0"
8
8
 
9
9
  gemspec path: "../"
@@ -3,7 +3,7 @@
3
3
  source "https://rubygems.org"
4
4
 
5
5
  gem "rails", "5.2.0"
6
- gem "jsonapi-resources", "~> 0.9"
6
+ gem "jsonapi-resources", "~> 0.9.0"
7
7
  gem "pundit", "~> 1.0"
8
8
 
9
9
  gemspec path: "../"
@@ -3,7 +3,7 @@
3
3
  source "https://rubygems.org"
4
4
 
5
5
  gem "rails", "5.2.0"
6
- gem "jsonapi-resources", "~> 0.9"
6
+ gem "jsonapi-resources", "~> 0.9.0"
7
7
  gem "pundit", "~> 2.0"
8
8
 
9
9
  gemspec path: "../"
@@ -17,7 +17,7 @@ Gem::Specification.new do |spec|
17
17
  spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
18
  spec.require_paths = ["lib"]
19
19
 
20
- spec.add_dependency "jsonapi-resources", "~> 0.9"
20
+ spec.add_dependency "jsonapi-resources", "~> 0.9.0"
21
21
  spec.add_dependency "pundit", ">= 1.0.0", "< 3.0.0"
22
22
 
23
23
  spec.add_development_dependency "appraisal"
@@ -31,5 +31,5 @@ Gem::Specification.new do |spec|
31
31
  spec.add_development_dependency "pry-rails"
32
32
  spec.add_development_dependency "rubocop", "~> 0.36.0"
33
33
  spec.add_development_dependency "phare", "~> 0.7.1"
34
- spec.add_development_dependency "sqlite3"
34
+ spec.add_development_dependency "sqlite3", "~> 1.3.6"
35
35
  end
@@ -101,12 +101,16 @@ module JSONAPI
101
101
  end
102
102
 
103
103
  def authorize_show_related_resources
104
- source_record = params[:source_klass].find_by_key(
104
+ source_resource = params[:source_klass].find_by_key(
105
105
  params[:source_id],
106
106
  context: context
107
- )._model
107
+ )
108
+
109
+ source_record = source_resource._model
108
110
 
109
- authorizer.show_related_resources(source_record: source_record)
111
+ authorizer.show_related_resources(
112
+ source_record: source_record, related_record_class: @resource_klass._model_class
113
+ )
110
114
  end
111
115
 
112
116
  def authorize_replace_fields
@@ -215,6 +219,10 @@ module JSONAPI
215
219
 
216
220
  related_records = related_resources.map(&:_model)
217
221
 
222
+ if related_records.size != params[:associated_keys].uniq.size
223
+ fail JSONAPI::Exceptions::RecordNotFound, params[:associated_keys]
224
+ end
225
+
218
226
  authorizer.remove_to_many_relationship(
219
227
  source_record: source_record,
220
228
  related_records: related_records,
@@ -294,25 +302,6 @@ module JSONAPI
294
302
  resource_class_for_relationship(assoc_name)._model_class
295
303
  end
296
304
 
297
- def related_models
298
- data = params[:data]
299
- return [] if data.nil?
300
-
301
- [:to_one, :to_many].flat_map do |rel_type|
302
- data[rel_type].flat_map do |assoc_name, assoc_value|
303
- case assoc_value
304
- when Hash # polymorphic relationship
305
- resource_class = @resource_klass.resource_for(assoc_value[:type].to_s)
306
- resource_class.find_by_key(assoc_value[:id], context: context)._model
307
- else
308
- resource_class = resource_class_for_relationship(assoc_name)
309
- primary_key = resource_class._primary_key
310
- resource_class._model_class.where(primary_key => assoc_value)
311
- end
312
- end
313
- end
314
- end
315
-
316
305
  def related_models_with_context
317
306
  data = params[:data]
318
307
  return { relationship: nil, relation_name: nil, records: nil } if data.nil?
@@ -328,7 +317,13 @@ module JSONAPI
328
317
  resource_class.find_by_key(assoc_value[:id], context: context)._model
329
318
  when Array
330
319
  resource_class = resource_class_for_relationship(assoc_name)
331
- resource_class.find_by_keys(assoc_value, context: context).map(&:_model)
320
+ resources = resource_class.find_by_keys(assoc_value, context: context)
321
+ resources.map(&:_model).tap do |scoped_records|
322
+ related_ids = Array.wrap(assoc_value).uniq
323
+ if scoped_records.count != related_ids.count
324
+ fail JSONAPI::Exceptions::RecordNotFound, related_ids
325
+ end
326
+ end
332
327
  else
333
328
  resource_class = resource_class_for_relationship(assoc_name)
334
329
  resource_class.find_by_key(assoc_value, context: context)._model
@@ -3,10 +3,9 @@ module JSONAPI
3
3
  # An authorizer is a class responsible for linking JSONAPI operations to
4
4
  # your choice of authorization mechanism.
5
5
  #
6
- # This class uses Pundit for authorization. It does not yet support all
7
- # the available operations you can use your own authorizer class instead
8
- # if you have different needs. See the README.md for configuration
9
- # information.
6
+ # This class uses Pundit for authorization. You can use your own authorizer
7
+ # class instead if you have different needs. See the README.md for
8
+ # configuration information.
10
9
  #
11
10
  # Fetching records is the concern of +PunditScopedResource+ which in turn
12
11
  # affects which records end up being passed here.
@@ -77,8 +76,10 @@ module JSONAPI
77
76
  # ==== Parameters
78
77
  #
79
78
  # * +source_record+ - The record whose relationship is queried
80
- def show_related_resources(source_record:)
79
+ # * +related_record_class+ - The associated record class to show
80
+ def show_related_resources(source_record:, related_record_class:)
81
81
  ::Pundit.authorize(user, source_record, 'show?')
82
+ ::Pundit.authorize(user, related_record_class, 'index?')
82
83
  end
83
84
 
84
85
  # <tt>PATCH /resources/:id</tt>
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
  module JSONAPI
3
3
  module Authorization
4
- VERSION = "1.0.0".freeze
4
+ VERSION = "3.0.2".freeze
5
5
  end
6
6
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jsonapi-authorization
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 3.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Vesa Laakso
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2019-01-22 00:00:00.000000000 Z
12
+ date: 2019-10-02 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: jsonapi-resources
@@ -17,14 +17,14 @@ dependencies:
17
17
  requirements:
18
18
  - - "~>"
19
19
  - !ruby/object:Gem::Version
20
- version: '0.9'
20
+ version: 0.9.0
21
21
  type: :runtime
22
22
  prerelease: false
23
23
  version_requirements: !ruby/object:Gem::Requirement
24
24
  requirements:
25
25
  - - "~>"
26
26
  - !ruby/object:Gem::Version
27
- version: '0.9'
27
+ version: 0.9.0
28
28
  - !ruby/object:Gem::Dependency
29
29
  name: pundit
30
30
  requirement: !ruby/object:Gem::Requirement
@@ -203,16 +203,16 @@ dependencies:
203
203
  name: sqlite3
204
204
  requirement: !ruby/object:Gem::Requirement
205
205
  requirements:
206
- - - ">="
206
+ - - "~>"
207
207
  - !ruby/object:Gem::Version
208
- version: '0'
208
+ version: 1.3.6
209
209
  type: :development
210
210
  prerelease: false
211
211
  version_requirements: !ruby/object:Gem::Requirement
212
212
  requirements:
213
- - - ">="
213
+ - - "~>"
214
214
  - !ruby/object:Gem::Version
215
- version: '0'
215
+ version: 1.3.6
216
216
  description: Adds generic authorization to the jsonapi-resources gem using Pundit.
217
217
  email:
218
218
  - laakso.vesa@gmail.com