From 2ed2d986e1d097d3210730aeefdd850ebb941649 Mon Sep 17 00:00:00 2001 From: Larry Gebhardt Date: Sun, 5 Jan 2020 10:00:06 -0500 Subject: [PATCH 1/7] WIP Update for jsonapi-resources v0.10 Note this will break with earlier versions of JR --- Gemfile | 3 ++ jsonapi-authorization.gemspec | 2 +- .../authorization/authorizing_processor.rb | 12 +++++- .../authorization/pundit_scoped_resource.rb | 38 ++++++------------- 4 files changed, 25 insertions(+), 30 deletions(-) diff --git a/Gemfile b/Gemfile index fa75df15..76d74dd7 100644 --- a/Gemfile +++ b/Gemfile @@ -1,3 +1,6 @@ source 'https://rubygems.org' +# ToDo: This is only for testing purposes +gem 'jsonapi-resources', :git => 'https://github.com/cerebris/jsonapi-resources.git', :branch => 'track_join_options' + gemspec diff --git a/jsonapi-authorization.gemspec b/jsonapi-authorization.gemspec index d2a3c6d3..dd108d64 100644 --- a/jsonapi-authorization.gemspec +++ b/jsonapi-authorization.gemspec @@ -17,7 +17,7 @@ Gem::Specification.new do |spec| spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) } spec.require_paths = ["lib"] - spec.add_dependency "jsonapi-resources", "~> 0.9.0" + spec.add_dependency "jsonapi-resources", "~> 0.10.0" spec.add_dependency "pundit", ">= 1.0.0", "< 3.0.0" spec.add_development_dependency "appraisal" diff --git a/lib/jsonapi/authorization/authorizing_processor.rb b/lib/jsonapi/authorization/authorizing_processor.rb index 4728bb44..0854affc 100644 --- a/lib/jsonapi/authorization/authorizing_processor.rb +++ b/lib/jsonapi/authorization/authorizing_processor.rb @@ -72,7 +72,7 @@ def authorize_show_relationship related_resource = case relationship when JSONAPI::Relationship::ToOne - parent_resource.public_send(params[:relationship_type].to_sym) + resources_from_relationship(source_klass, source_id, relationship.type, context).first when JSONAPI::Relationship::ToMany # Do nothing — already covered by policy scopes else @@ -91,7 +91,7 @@ def authorize_show_related_resource source_resource = source_klass.find_by_key(source_id, context: context) - related_resource = source_resource.public_send(relationship_type) + related_resource = resources_from_relationship(source_klass, source_id, relationship_type, context).first source_record = source_resource._model related_record = related_resource._model unless related_resource.nil? @@ -282,6 +282,14 @@ def authorizer @authorizer ||= ::JSONAPI::Authorization.configuration.authorizer.new(context: context) end + def resources_from_relationship(source_klass, source_id, relationship_type, context) + rid = source_klass.find_related_fragments([JSONAPI::ResourceIdentity.new(source_klass, source_id)], + relationship_type, + context: context).keys.first + + rid.resource_klass.find_to_populate_by_keys(rid.id) + end + # TODO: Communicate with upstream to fix this nasty hack def operation_resource_id case operation_type diff --git a/lib/jsonapi/authorization/pundit_scoped_resource.rb b/lib/jsonapi/authorization/pundit_scoped_resource.rb index 5166eadd..516de626 100644 --- a/lib/jsonapi/authorization/pundit_scoped_resource.rb +++ b/lib/jsonapi/authorization/pundit_scoped_resource.rb @@ -8,35 +8,19 @@ module PunditScopedResource module ClassMethods def records(options = {}) user_context = JSONAPI::Authorization.configuration.user_context(options[:context]) - ::Pundit.policy_scope!(user_context, _model_class) + ::Pundit.policy_scope!(user_context, super) end - end - - def records_for(association_name) - record_or_records = @model.public_send(association_name) - relationship = fetch_relationship(association_name) - case relationship - when JSONAPI::Relationship::ToOne - record_or_records - when JSONAPI::Relationship::ToMany - user_context = JSONAPI::Authorization.configuration.user_context(context) - ::Pundit.policy_scope!(user_context, record_or_records) - else - raise "Unknown relationship type #{relationship.inspect}" - end - end - - private - - def fetch_relationship(association_name) - relationships = self.class._relationships.select do |_k, v| - v.relation_name(context: context) == association_name - end - if relationships.empty? - nil - else - relationships.values.first + def apply_joins(records, join_manager, options) + records = super + join_manager.join_details.each do |k, v| + next if k == '' || v[:join_type] == :root + v[:join_options][:relationship_details][:resource_klasses].each_key do |klass| + next unless klass.included_modules.include?(PunditScopedResource) + records = records.where(v[:alias] => { klass._primary_key => klass.records(options)}) + end + end + records end end end From 2851a77d315cc235e497e206b71806d145e60ec4 Mon Sep 17 00:00:00 2001 From: brianswko Date: Sun, 12 Jan 2020 00:47:58 -0800 Subject: [PATCH 2/7] Run CI against Rails 6 (#129) * Run CI against Rails 6 * Use ruby 2.5 * Dummy app updates for rails 6 * Run all but Rails 4.2 tests with Ruby 2.5 * Add empty asset manifest to appease Rails Co-authored-by: Vesa Laakso <482561+valscion@users.noreply.github.com> --- .travis.yml | 33 ++++++++++----- Appraisals | 42 +++++++++++++++++++ gemfiles/rails_4_2_pundit_1.gemfile | 4 ++ gemfiles/rails_4_2_pundit_2.gemfile | 4 ++ gemfiles/rails_5_0_pundit_1.gemfile | 4 ++ gemfiles/rails_5_0_pundit_2.gemfile | 4 ++ gemfiles/rails_5_1_pundit_1.gemfile | 4 ++ gemfiles/rails_5_1_pundit_2.gemfile | 4 ++ gemfiles/rails_5_2_pundit_1.gemfile | 4 ++ gemfiles/rails_5_2_pundit_2.gemfile | 4 ++ gemfiles/rails_6_0_pundit_1.gemfile | 13 ++++++ gemfiles/rails_6_0_pundit_2.gemfile | 13 ++++++ jsonapi-authorization.gemspec | 2 +- spec/dummy/app/assets/config/manifest.js | 0 .../app/controllers/application_controller.rb | 2 + .../app/controllers/articles_controller.rb | 2 +- .../app/controllers/comments_controller.rb | 2 +- spec/dummy/app/controllers/tags_controller.rb | 2 +- .../dummy/app/controllers/users_controller.rb | 2 +- 19 files changed, 129 insertions(+), 16 deletions(-) create mode 100644 gemfiles/rails_6_0_pundit_1.gemfile create mode 100644 gemfiles/rails_6_0_pundit_2.gemfile create mode 100644 spec/dummy/app/assets/config/manifest.js create mode 100644 spec/dummy/app/controllers/application_controller.rb diff --git a/.travis.yml b/.travis.yml index d3fc1c66..d763cc5e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,17 +2,28 @@ language: ruby branches: only: - master -rvm: - - 2.3 -gemfile: - - gemfiles/rails_4_2_pundit_1.gemfile - - gemfiles/rails_5_0_pundit_1.gemfile - - gemfiles/rails_5_1_pundit_1.gemfile - - gemfiles/rails_5_2_pundit_1.gemfile - - gemfiles/rails_4_2_pundit_2.gemfile - - gemfiles/rails_5_0_pundit_2.gemfile - - gemfiles/rails_5_1_pundit_2.gemfile - - gemfiles/rails_5_2_pundit_2.gemfile +jobs: + include: + - rvm: 2.3 + gemfile: gemfiles/rails_4_2_pundit_1.gemfile + - rvm: 2.3 + gemfile: gemfiles/rails_4_2_pundit_2.gemfile + - rvm: 2.5 + gemfile: gemfiles/rails_5_0_pundit_1.gemfile + - rvm: 2.5 + gemfile: gemfiles/rails_5_0_pundit_2.gemfile + - rvm: 2.5 + gemfile: gemfiles/rails_5_1_pundit_1.gemfile + - rvm: 2.5 + gemfile: gemfiles/rails_5_1_pundit_2.gemfile + - rvm: 2.5 + gemfile: gemfiles/rails_5_2_pundit_1.gemfile + - rvm: 2.5 + gemfile: gemfiles/rails_5_2_pundit_2.gemfile + - rvm: 2.5 + gemfile: gemfiles/rails_6_0_pundit_1.gemfile + - rvm: 2.5 + gemfile: gemfiles/rails_6_0_pundit_2.gemfile before_install: - gem install bundler -v '< 2' notifications: diff --git a/Appraisals b/Appraisals index 795a6f45..d390883f 100644 --- a/Appraisals +++ b/Appraisals @@ -2,46 +2,88 @@ appraise 'rails-4-2 pundit-1' do gem 'rails', '4.2.0' gem 'jsonapi-resources', '~> 0.9.0' gem 'pundit', '~> 1.0' + group :development, :test do + gem 'sqlite3', '~> 1.3.13' + end end appraise 'rails-5-0 pundit-1' do gem 'rails', '5.0.0' gem 'jsonapi-resources', '~> 0.9.0' gem 'pundit', '~> 1.0' + group :development, :test do + gem 'sqlite3', '~> 1.3.13' + end end appraise 'rails-5-1 pundit-1' do gem "rails", "5.1.0" gem 'jsonapi-resources', '~> 0.9.0' gem 'pundit', '~> 1.0' + group :development, :test do + gem 'sqlite3', '~> 1.3.13' + end end appraise 'rails-5-2 pundit-1' do gem 'rails', '5.2.0' gem 'jsonapi-resources', '~> 0.9.0' gem 'pundit', '~> 1.0' + group :development, :test do + gem 'sqlite3', '~> 1.3.13' + end +end + +appraise 'rails-6-0 pundit-1' do + gem 'rails', '~> 6.0.0' + gem 'jsonapi-resources', '~> 0.9.0' + gem 'pundit', '~> 1.0' + group :development, :test do + gem 'sqlite3', '~> 1.4.1' + end end appraise 'rails-4-2 pundit-2' do gem 'rails', '4.2.0' gem 'jsonapi-resources', '~> 0.9.0' gem 'pundit', '~> 2.0' + group :development, :test do + gem 'sqlite3', '~> 1.3.13' + end end appraise 'rails-5-0 pundit-2' do gem 'rails', '5.0.0' gem 'jsonapi-resources', '~> 0.9.0' gem 'pundit', '~> 2.0' + group :development, :test do + gem 'sqlite3', '~> 1.3.13' + end end appraise 'rails-5-1 pundit-2' do gem 'rails', '5.1.0' gem 'jsonapi-resources', '~> 0.9.0' gem 'pundit', '~> 2.0' + group :development, :test do + gem 'sqlite3', '~> 1.3.13' + end end appraise 'rails-5-2 pundit-2' do gem 'rails', '5.2.0' gem 'jsonapi-resources', '~> 0.9.0' gem 'pundit', '~> 2.0' + group :development, :test do + gem 'sqlite3', '~> 1.3.13' + end +end + +appraise 'rails-6-0 pundit-2' do + gem 'rails', '~> 6.0.0' + gem 'jsonapi-resources', '~> 0.9.0' + gem 'pundit', '~> 2.0' + group :development, :test do + gem 'sqlite3', '~> 1.4.1' + end end diff --git a/gemfiles/rails_4_2_pundit_1.gemfile b/gemfiles/rails_4_2_pundit_1.gemfile index ed81ddfa..4e55c678 100644 --- a/gemfiles/rails_4_2_pundit_1.gemfile +++ b/gemfiles/rails_4_2_pundit_1.gemfile @@ -6,4 +6,8 @@ gem "rails", "4.2.0" gem "jsonapi-resources", "~> 0.9.0" gem "pundit", "~> 1.0" +group :development, :test do + gem "sqlite3", "~> 1.3.13" +end + gemspec path: "../" diff --git a/gemfiles/rails_4_2_pundit_2.gemfile b/gemfiles/rails_4_2_pundit_2.gemfile index 9ce4476b..19a0fe0f 100644 --- a/gemfiles/rails_4_2_pundit_2.gemfile +++ b/gemfiles/rails_4_2_pundit_2.gemfile @@ -6,4 +6,8 @@ gem "rails", "4.2.0" gem "jsonapi-resources", "~> 0.9.0" gem "pundit", "~> 2.0" +group :development, :test do + gem "sqlite3", "~> 1.3.13" +end + gemspec path: "../" diff --git a/gemfiles/rails_5_0_pundit_1.gemfile b/gemfiles/rails_5_0_pundit_1.gemfile index c53a19d7..a661523a 100644 --- a/gemfiles/rails_5_0_pundit_1.gemfile +++ b/gemfiles/rails_5_0_pundit_1.gemfile @@ -6,4 +6,8 @@ gem "rails", "5.0.0" gem "jsonapi-resources", "~> 0.9.0" gem "pundit", "~> 1.0" +group :development, :test do + gem "sqlite3", "~> 1.3.13" +end + gemspec path: "../" diff --git a/gemfiles/rails_5_0_pundit_2.gemfile b/gemfiles/rails_5_0_pundit_2.gemfile index 253e51f7..fcd2538c 100644 --- a/gemfiles/rails_5_0_pundit_2.gemfile +++ b/gemfiles/rails_5_0_pundit_2.gemfile @@ -6,4 +6,8 @@ gem "rails", "5.0.0" gem "jsonapi-resources", "~> 0.9.0" gem "pundit", "~> 2.0" +group :development, :test do + gem "sqlite3", "~> 1.3.13" +end + gemspec path: "../" diff --git a/gemfiles/rails_5_1_pundit_1.gemfile b/gemfiles/rails_5_1_pundit_1.gemfile index 9e28ecea..2492ca88 100644 --- a/gemfiles/rails_5_1_pundit_1.gemfile +++ b/gemfiles/rails_5_1_pundit_1.gemfile @@ -6,4 +6,8 @@ gem "rails", "5.1.0" gem "jsonapi-resources", "~> 0.9.0" gem "pundit", "~> 1.0" +group :development, :test do + gem "sqlite3", "~> 1.3.13" +end + gemspec path: "../" diff --git a/gemfiles/rails_5_1_pundit_2.gemfile b/gemfiles/rails_5_1_pundit_2.gemfile index 3305a4bb..45d754b0 100644 --- a/gemfiles/rails_5_1_pundit_2.gemfile +++ b/gemfiles/rails_5_1_pundit_2.gemfile @@ -6,4 +6,8 @@ gem "rails", "5.1.0" gem "jsonapi-resources", "~> 0.9.0" gem "pundit", "~> 2.0" +group :development, :test do + gem "sqlite3", "~> 1.3.13" +end + gemspec path: "../" diff --git a/gemfiles/rails_5_2_pundit_1.gemfile b/gemfiles/rails_5_2_pundit_1.gemfile index 55f876dd..0610c610 100644 --- a/gemfiles/rails_5_2_pundit_1.gemfile +++ b/gemfiles/rails_5_2_pundit_1.gemfile @@ -6,4 +6,8 @@ gem "rails", "5.2.0" gem "jsonapi-resources", "~> 0.9.0" gem "pundit", "~> 1.0" +group :development, :test do + gem "sqlite3", "~> 1.3.13" +end + gemspec path: "../" diff --git a/gemfiles/rails_5_2_pundit_2.gemfile b/gemfiles/rails_5_2_pundit_2.gemfile index 5c948725..e0d0c740 100644 --- a/gemfiles/rails_5_2_pundit_2.gemfile +++ b/gemfiles/rails_5_2_pundit_2.gemfile @@ -6,4 +6,8 @@ gem "rails", "5.2.0" gem "jsonapi-resources", "~> 0.9.0" gem "pundit", "~> 2.0" +group :development, :test do + gem "sqlite3", "~> 1.3.13" +end + gemspec path: "../" diff --git a/gemfiles/rails_6_0_pundit_1.gemfile b/gemfiles/rails_6_0_pundit_1.gemfile new file mode 100644 index 00000000..57cd1a11 --- /dev/null +++ b/gemfiles/rails_6_0_pundit_1.gemfile @@ -0,0 +1,13 @@ +# This file was generated by Appraisal + +source "https://rubygems.org" + +gem "rails", "~> 6.0.0" +gem "jsonapi-resources", "~> 0.9.0" +gem "pundit", "~> 1.0" + +group :development, :test do + gem "sqlite3", "~> 1.4.1" +end + +gemspec path: "../" diff --git a/gemfiles/rails_6_0_pundit_2.gemfile b/gemfiles/rails_6_0_pundit_2.gemfile new file mode 100644 index 00000000..dcfd891e --- /dev/null +++ b/gemfiles/rails_6_0_pundit_2.gemfile @@ -0,0 +1,13 @@ +# This file was generated by Appraisal + +source "https://rubygems.org" + +gem "rails", "~> 6.0.0" +gem "jsonapi-resources", "~> 0.9.0" +gem "pundit", "~> 2.0" + +group :development, :test do + gem "sqlite3", "~> 1.4.1" +end + +gemspec path: "../" diff --git a/jsonapi-authorization.gemspec b/jsonapi-authorization.gemspec index dd108d64..17354a1e 100644 --- a/jsonapi-authorization.gemspec +++ b/jsonapi-authorization.gemspec @@ -31,5 +31,5 @@ Gem::Specification.new do |spec| spec.add_development_dependency "pry-rails" spec.add_development_dependency "rubocop", "~> 0.36.0" spec.add_development_dependency "phare", "~> 0.7.1" - spec.add_development_dependency "sqlite3", "~> 1.3.6" + spec.add_development_dependency "sqlite3", "~> 1.3" end diff --git a/spec/dummy/app/assets/config/manifest.js b/spec/dummy/app/assets/config/manifest.js new file mode 100644 index 00000000..e69de29b diff --git a/spec/dummy/app/controllers/application_controller.rb b/spec/dummy/app/controllers/application_controller.rb new file mode 100644 index 00000000..09705d12 --- /dev/null +++ b/spec/dummy/app/controllers/application_controller.rb @@ -0,0 +1,2 @@ +class ApplicationController < ActionController::Base +end diff --git a/spec/dummy/app/controllers/articles_controller.rb b/spec/dummy/app/controllers/articles_controller.rb index 5dc4da9d..00cc4c48 100644 --- a/spec/dummy/app/controllers/articles_controller.rb +++ b/spec/dummy/app/controllers/articles_controller.rb @@ -1,4 +1,4 @@ -class ArticlesController < ActionController::Base +class ArticlesController < ApplicationController include JSONAPI::ActsAsResourceController rescue_from Pundit::NotAuthorizedError, with: :user_not_authorized diff --git a/spec/dummy/app/controllers/comments_controller.rb b/spec/dummy/app/controllers/comments_controller.rb index 5f4fa27f..0f2d7b2e 100644 --- a/spec/dummy/app/controllers/comments_controller.rb +++ b/spec/dummy/app/controllers/comments_controller.rb @@ -1,4 +1,4 @@ -class CommentsController < ActionController::Base +class CommentsController < ApplicationController include JSONAPI::ActsAsResourceController rescue_from Pundit::NotAuthorizedError, with: :user_not_authorized diff --git a/spec/dummy/app/controllers/tags_controller.rb b/spec/dummy/app/controllers/tags_controller.rb index 4b6a4312..388079b9 100644 --- a/spec/dummy/app/controllers/tags_controller.rb +++ b/spec/dummy/app/controllers/tags_controller.rb @@ -1,4 +1,4 @@ -class TagsController < ActionController::Base +class TagsController < ApplicationController include JSONAPI::ActsAsResourceController rescue_from Pundit::NotAuthorizedError, with: :user_not_authorized diff --git a/spec/dummy/app/controllers/users_controller.rb b/spec/dummy/app/controllers/users_controller.rb index 9ad91d46..f81ae390 100644 --- a/spec/dummy/app/controllers/users_controller.rb +++ b/spec/dummy/app/controllers/users_controller.rb @@ -1,4 +1,4 @@ -class UsersController < ActionController::Base +class UsersController < ApplicationController include JSONAPI::ActsAsResourceController rescue_from Pundit::NotAuthorizedError, with: :user_not_authorized From 85ced68544864610eb4ec13a79c4339a0a160bba Mon Sep 17 00:00:00 2001 From: Vesa Laakso <482561+valscion@users.noreply.github.com> Date: Sun, 12 Jan 2020 11:05:54 +0200 Subject: [PATCH 3/7] Update build badge to point to travis-ci.com (#133) --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index c2d7b8b3..ea608f5a 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # JSONAPI::Authorization -[![Build Status](https://img.shields.io/travis/venuu/jsonapi-authorization/master.svg?style=flat&maxAge=3600)](https://travis-ci.org/venuu/jsonapi-authorization) [![Gem Version](https://img.shields.io/gem/v/jsonapi-authorization.svg?style=flat&maxAge=3600)](https://rubygems.org/gems/jsonapi-authorization) +[![Build Status](https://img.shields.io/travis/com/venuu/jsonapi-authorization/master.svg?style=flat&maxAge=3600)](https://travis-ci.com/venuu/jsonapi-authorization) [![Gem Version](https://img.shields.io/gem/v/jsonapi-authorization.svg?style=flat&maxAge=3600)](https://rubygems.org/gems/jsonapi-authorization) **NOTE:** This README is the documentation for `JSONAPI::Authorization`. If you are viewing this at the [project page on Github](https://github.com/venuu/jsonapi-authorization) you are viewing the documentation for the `master` From b361f92a96f415ea2a97f6d018d87b68c1285148 Mon Sep 17 00:00:00 2001 From: Vesa Laakso Date: Sun, 12 Jan 2020 11:15:52 +0200 Subject: [PATCH 4/7] Update Appraisals and gemfiles to use JR from git branch --- Appraisals | 28 ++++++++++++++++++---------- gemfiles/rails_4_2_pundit_1.gemfile | 2 +- gemfiles/rails_4_2_pundit_2.gemfile | 2 +- gemfiles/rails_5_0_pundit_1.gemfile | 2 +- gemfiles/rails_5_0_pundit_2.gemfile | 2 +- gemfiles/rails_5_1_pundit_1.gemfile | 2 +- gemfiles/rails_5_1_pundit_2.gemfile | 2 +- gemfiles/rails_5_2_pundit_1.gemfile | 2 +- gemfiles/rails_5_2_pundit_2.gemfile | 2 +- gemfiles/rails_6_0_pundit_1.gemfile | 2 +- gemfiles/rails_6_0_pundit_2.gemfile | 2 +- 11 files changed, 28 insertions(+), 20 deletions(-) diff --git a/Appraisals b/Appraisals index d390883f..5a63b06c 100644 --- a/Appraisals +++ b/Appraisals @@ -1,6 +1,7 @@ appraise 'rails-4-2 pundit-1' do gem 'rails', '4.2.0' - gem 'jsonapi-resources', '~> 0.9.0' + # ToDo: This is only for testing purposes + gem 'jsonapi-resources', :git => 'https://github.com/cerebris/jsonapi-resources.git', :branch => 'track_join_options' gem 'pundit', '~> 1.0' group :development, :test do gem 'sqlite3', '~> 1.3.13' @@ -9,7 +10,8 @@ end appraise 'rails-5-0 pundit-1' do gem 'rails', '5.0.0' - gem 'jsonapi-resources', '~> 0.9.0' + # ToDo: This is only for testing purposes + gem 'jsonapi-resources', :git => 'https://github.com/cerebris/jsonapi-resources.git', :branch => 'track_join_options' gem 'pundit', '~> 1.0' group :development, :test do gem 'sqlite3', '~> 1.3.13' @@ -18,7 +20,8 @@ end appraise 'rails-5-1 pundit-1' do gem "rails", "5.1.0" - gem 'jsonapi-resources', '~> 0.9.0' + # ToDo: This is only for testing purposes + gem 'jsonapi-resources', :git => 'https://github.com/cerebris/jsonapi-resources.git', :branch => 'track_join_options' gem 'pundit', '~> 1.0' group :development, :test do gem 'sqlite3', '~> 1.3.13' @@ -27,7 +30,8 @@ end appraise 'rails-5-2 pundit-1' do gem 'rails', '5.2.0' - gem 'jsonapi-resources', '~> 0.9.0' + # ToDo: This is only for testing purposes + gem 'jsonapi-resources', :git => 'https://github.com/cerebris/jsonapi-resources.git', :branch => 'track_join_options' gem 'pundit', '~> 1.0' group :development, :test do gem 'sqlite3', '~> 1.3.13' @@ -36,7 +40,7 @@ end appraise 'rails-6-0 pundit-1' do gem 'rails', '~> 6.0.0' - gem 'jsonapi-resources', '~> 0.9.0' + gem 'jsonapi-resources', :git => 'https://github.com/cerebris/jsonapi-resources.git', :branch => 'track_join_options' gem 'pundit', '~> 1.0' group :development, :test do gem 'sqlite3', '~> 1.4.1' @@ -45,7 +49,8 @@ end appraise 'rails-4-2 pundit-2' do gem 'rails', '4.2.0' - gem 'jsonapi-resources', '~> 0.9.0' + # ToDo: This is only for testing purposes + gem 'jsonapi-resources', :git => 'https://github.com/cerebris/jsonapi-resources.git', :branch => 'track_join_options' gem 'pundit', '~> 2.0' group :development, :test do gem 'sqlite3', '~> 1.3.13' @@ -54,7 +59,8 @@ end appraise 'rails-5-0 pundit-2' do gem 'rails', '5.0.0' - gem 'jsonapi-resources', '~> 0.9.0' + # ToDo: This is only for testing purposes + gem 'jsonapi-resources', :git => 'https://github.com/cerebris/jsonapi-resources.git', :branch => 'track_join_options' gem 'pundit', '~> 2.0' group :development, :test do gem 'sqlite3', '~> 1.3.13' @@ -63,7 +69,8 @@ end appraise 'rails-5-1 pundit-2' do gem 'rails', '5.1.0' - gem 'jsonapi-resources', '~> 0.9.0' + # ToDo: This is only for testing purposes + gem 'jsonapi-resources', :git => 'https://github.com/cerebris/jsonapi-resources.git', :branch => 'track_join_options' gem 'pundit', '~> 2.0' group :development, :test do gem 'sqlite3', '~> 1.3.13' @@ -72,7 +79,8 @@ end appraise 'rails-5-2 pundit-2' do gem 'rails', '5.2.0' - gem 'jsonapi-resources', '~> 0.9.0' + # ToDo: This is only for testing purposes + gem 'jsonapi-resources', :git => 'https://github.com/cerebris/jsonapi-resources.git', :branch => 'track_join_options' gem 'pundit', '~> 2.0' group :development, :test do gem 'sqlite3', '~> 1.3.13' @@ -81,7 +89,7 @@ end appraise 'rails-6-0 pundit-2' do gem 'rails', '~> 6.0.0' - gem 'jsonapi-resources', '~> 0.9.0' + gem 'jsonapi-resources', :git => 'https://github.com/cerebris/jsonapi-resources.git', :branch => 'track_join_options' gem 'pundit', '~> 2.0' group :development, :test do gem 'sqlite3', '~> 1.4.1' diff --git a/gemfiles/rails_4_2_pundit_1.gemfile b/gemfiles/rails_4_2_pundit_1.gemfile index 4e55c678..2be4ea6f 100644 --- a/gemfiles/rails_4_2_pundit_1.gemfile +++ b/gemfiles/rails_4_2_pundit_1.gemfile @@ -2,8 +2,8 @@ source "https://rubygems.org" +gem "jsonapi-resources", git: "https://github.com/cerebris/jsonapi-resources.git", branch: "track_join_options" gem "rails", "4.2.0" -gem "jsonapi-resources", "~> 0.9.0" gem "pundit", "~> 1.0" group :development, :test do diff --git a/gemfiles/rails_4_2_pundit_2.gemfile b/gemfiles/rails_4_2_pundit_2.gemfile index 19a0fe0f..e2908ff4 100644 --- a/gemfiles/rails_4_2_pundit_2.gemfile +++ b/gemfiles/rails_4_2_pundit_2.gemfile @@ -2,8 +2,8 @@ source "https://rubygems.org" +gem "jsonapi-resources", git: "https://github.com/cerebris/jsonapi-resources.git", branch: "track_join_options" gem "rails", "4.2.0" -gem "jsonapi-resources", "~> 0.9.0" gem "pundit", "~> 2.0" group :development, :test do diff --git a/gemfiles/rails_5_0_pundit_1.gemfile b/gemfiles/rails_5_0_pundit_1.gemfile index a661523a..ce45623c 100644 --- a/gemfiles/rails_5_0_pundit_1.gemfile +++ b/gemfiles/rails_5_0_pundit_1.gemfile @@ -2,8 +2,8 @@ source "https://rubygems.org" +gem "jsonapi-resources", git: "https://github.com/cerebris/jsonapi-resources.git", branch: "track_join_options" gem "rails", "5.0.0" -gem "jsonapi-resources", "~> 0.9.0" gem "pundit", "~> 1.0" group :development, :test do diff --git a/gemfiles/rails_5_0_pundit_2.gemfile b/gemfiles/rails_5_0_pundit_2.gemfile index fcd2538c..7e0e140d 100644 --- a/gemfiles/rails_5_0_pundit_2.gemfile +++ b/gemfiles/rails_5_0_pundit_2.gemfile @@ -2,8 +2,8 @@ source "https://rubygems.org" +gem "jsonapi-resources", git: "https://github.com/cerebris/jsonapi-resources.git", branch: "track_join_options" gem "rails", "5.0.0" -gem "jsonapi-resources", "~> 0.9.0" gem "pundit", "~> 2.0" group :development, :test do diff --git a/gemfiles/rails_5_1_pundit_1.gemfile b/gemfiles/rails_5_1_pundit_1.gemfile index 2492ca88..2ef6308d 100644 --- a/gemfiles/rails_5_1_pundit_1.gemfile +++ b/gemfiles/rails_5_1_pundit_1.gemfile @@ -2,8 +2,8 @@ source "https://rubygems.org" +gem "jsonapi-resources", git: "https://github.com/cerebris/jsonapi-resources.git", branch: "track_join_options" gem "rails", "5.1.0" -gem "jsonapi-resources", "~> 0.9.0" gem "pundit", "~> 1.0" group :development, :test do diff --git a/gemfiles/rails_5_1_pundit_2.gemfile b/gemfiles/rails_5_1_pundit_2.gemfile index 45d754b0..da9943ed 100644 --- a/gemfiles/rails_5_1_pundit_2.gemfile +++ b/gemfiles/rails_5_1_pundit_2.gemfile @@ -2,8 +2,8 @@ source "https://rubygems.org" +gem "jsonapi-resources", git: "https://github.com/cerebris/jsonapi-resources.git", branch: "track_join_options" gem "rails", "5.1.0" -gem "jsonapi-resources", "~> 0.9.0" gem "pundit", "~> 2.0" group :development, :test do diff --git a/gemfiles/rails_5_2_pundit_1.gemfile b/gemfiles/rails_5_2_pundit_1.gemfile index 0610c610..fe1f0c4e 100644 --- a/gemfiles/rails_5_2_pundit_1.gemfile +++ b/gemfiles/rails_5_2_pundit_1.gemfile @@ -2,8 +2,8 @@ source "https://rubygems.org" +gem "jsonapi-resources", git: "https://github.com/cerebris/jsonapi-resources.git", branch: "track_join_options" gem "rails", "5.2.0" -gem "jsonapi-resources", "~> 0.9.0" gem "pundit", "~> 1.0" group :development, :test do diff --git a/gemfiles/rails_5_2_pundit_2.gemfile b/gemfiles/rails_5_2_pundit_2.gemfile index e0d0c740..6ac0ea5b 100644 --- a/gemfiles/rails_5_2_pundit_2.gemfile +++ b/gemfiles/rails_5_2_pundit_2.gemfile @@ -2,8 +2,8 @@ source "https://rubygems.org" +gem "jsonapi-resources", git: "https://github.com/cerebris/jsonapi-resources.git", branch: "track_join_options" gem "rails", "5.2.0" -gem "jsonapi-resources", "~> 0.9.0" gem "pundit", "~> 2.0" group :development, :test do diff --git a/gemfiles/rails_6_0_pundit_1.gemfile b/gemfiles/rails_6_0_pundit_1.gemfile index 57cd1a11..1f5d78e2 100644 --- a/gemfiles/rails_6_0_pundit_1.gemfile +++ b/gemfiles/rails_6_0_pundit_1.gemfile @@ -2,8 +2,8 @@ source "https://rubygems.org" +gem "jsonapi-resources", git: "https://github.com/cerebris/jsonapi-resources.git", branch: "track_join_options" gem "rails", "~> 6.0.0" -gem "jsonapi-resources", "~> 0.9.0" gem "pundit", "~> 1.0" group :development, :test do diff --git a/gemfiles/rails_6_0_pundit_2.gemfile b/gemfiles/rails_6_0_pundit_2.gemfile index dcfd891e..2149f677 100644 --- a/gemfiles/rails_6_0_pundit_2.gemfile +++ b/gemfiles/rails_6_0_pundit_2.gemfile @@ -2,8 +2,8 @@ source "https://rubygems.org" +gem "jsonapi-resources", git: "https://github.com/cerebris/jsonapi-resources.git", branch: "track_join_options" gem "rails", "~> 6.0.0" -gem "jsonapi-resources", "~> 0.9.0" gem "pundit", "~> 2.0" group :development, :test do From c26b13a93f51e584ea0596ae0439067d9dd327ed Mon Sep 17 00:00:00 2001 From: Vesa Laakso Date: Sun, 12 Jan 2020 11:23:41 +0200 Subject: [PATCH 5/7] Appease bin/phare (rubocop) --- Gemfile | 8 ++++++-- lib/jsonapi/authorization/authorizing_processor.rb | 12 ++++++++---- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/Gemfile b/Gemfile index 76d74dd7..04d4f9fb 100644 --- a/Gemfile +++ b/Gemfile @@ -1,6 +1,10 @@ source 'https://rubygems.org' -# ToDo: This is only for testing purposes -gem 'jsonapi-resources', :git => 'https://github.com/cerebris/jsonapi-resources.git', :branch => 'track_join_options' +# TODO: This is only for testing purposes +gem( + 'jsonapi-resources', + git: 'https://github.com/cerebris/jsonapi-resources.git', + branch: 'track_join_options' +) gemspec diff --git a/lib/jsonapi/authorization/authorizing_processor.rb b/lib/jsonapi/authorization/authorizing_processor.rb index 0854affc..0b102751 100644 --- a/lib/jsonapi/authorization/authorizing_processor.rb +++ b/lib/jsonapi/authorization/authorizing_processor.rb @@ -91,7 +91,9 @@ def authorize_show_related_resource source_resource = source_klass.find_by_key(source_id, context: context) - related_resource = resources_from_relationship(source_klass, source_id, relationship_type, context).first + related_resource = resources_from_relationship( + source_klass, source_id, relationship_type, context + ).first source_record = source_resource._model related_record = related_resource._model unless related_resource.nil? @@ -283,9 +285,11 @@ def authorizer end def resources_from_relationship(source_klass, source_id, relationship_type, context) - rid = source_klass.find_related_fragments([JSONAPI::ResourceIdentity.new(source_klass, source_id)], - relationship_type, - context: context).keys.first + rid = source_klass.find_related_fragments( + [JSONAPI::ResourceIdentity.new(source_klass, source_id)], + relationship_type, + context: context + ).keys.first rid.resource_klass.find_to_populate_by_keys(rid.id) end From fba3a64be258811976970adc2f4d54fe9ffe1ac7 Mon Sep 17 00:00:00 2001 From: Vesa Laakso <482561+valscion@users.noreply.github.com> Date: Sun, 12 Jan 2020 12:07:45 +0200 Subject: [PATCH 6/7] Add better debuggability to be_X test failures (#134) * Add better debuggability to be_X test failures This way test failures will show what the HTTP status code actually was when test fails as well as output the entire response body. The response body will most likely contain vital debugging information to help figure out why the test failed * Output last request information on spec failures --- spec/support/custom_matchers.rb | 54 +++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 spec/support/custom_matchers.rb diff --git a/spec/support/custom_matchers.rb b/spec/support/custom_matchers.rb new file mode 100644 index 00000000..8a2f9681 --- /dev/null +++ b/spec/support/custom_matchers.rb @@ -0,0 +1,54 @@ +# Add better debuggability to be_forbidden failures +RSpec::Matchers.define :be_forbidden do + match(&:forbidden?) + + failure_message do |actual| + debug_text_for_failure('forbidden', response: actual, last_request: last_request) + end +end + +# Add better debuggability to be_not_found failures +RSpec::Matchers.define :be_not_found do + match(&:not_found?) + + failure_message do |actual| + debug_text_for_failure('not_found', response: actual, last_request: last_request) + end +end + +# Add better debuggability to be_unprocessable failures +RSpec::Matchers.define :be_unprocessable do + match(&:unprocessable?) + + failure_message do |actual| + debug_text_for_failure('unprocessable', response: actual, last_request: last_request) + end +end + +# Add better debuggability to be_successful failures +RSpec::Matchers.define :be_successful do + match(&:successful?) + + failure_message do |actual| + debug_text_for_failure('successful', response: actual, last_request: last_request) + end +end + +# Add better debuggability to be_ok failures +RSpec::Matchers.define :be_ok do + match(&:ok?) + + failure_message do |actual| + debug_text_for_failure('ok', response: actual, last_request: last_request) + end +end + +def debug_text_for_failure(expected, response:, last_request:) + debug_text = "expected response to be #{expected} but HTTP code was #{response.status}." + debug_text += " Last request was #{last_request.request_method} to #{last_request.fullpath}" + unless last_request.get? + debug_text += " with body:\n" + last_request.body.read + end + debug_text += "\nResponse body was:\n" + response.body + debug_text +end From 762718244b8076f1c949d03659df85753d351b51 Mon Sep 17 00:00:00 2001 From: Larry Gebhardt Date: Sat, 8 Feb 2020 12:03:26 -0500 Subject: [PATCH 7/7] Use updated JR branch which merges records on joins --- Appraisals | 20 +++++++++---------- Gemfile | 2 +- gemfiles/rails_4_2_pundit_1.gemfile | 2 +- gemfiles/rails_4_2_pundit_2.gemfile | 2 +- gemfiles/rails_5_0_pundit_1.gemfile | 2 +- gemfiles/rails_5_0_pundit_2.gemfile | 2 +- gemfiles/rails_5_1_pundit_1.gemfile | 2 +- gemfiles/rails_5_1_pundit_2.gemfile | 2 +- gemfiles/rails_5_2_pundit_1.gemfile | 2 +- gemfiles/rails_5_2_pundit_2.gemfile | 2 +- gemfiles/rails_6_0_pundit_1.gemfile | 2 +- gemfiles/rails_6_0_pundit_2.gemfile | 2 +- .../authorization/pundit_scoped_resource.rb | 12 ----------- 13 files changed, 21 insertions(+), 33 deletions(-) diff --git a/Appraisals b/Appraisals index 5a63b06c..4d583e12 100644 --- a/Appraisals +++ b/Appraisals @@ -1,7 +1,7 @@ appraise 'rails-4-2 pundit-1' do gem 'rails', '4.2.0' # ToDo: This is only for testing purposes - gem 'jsonapi-resources', :git => 'https://github.com/cerebris/jsonapi-resources.git', :branch => 'track_join_options' + gem 'jsonapi-resources', :git => 'https://github.com/cerebris/jsonapi-resources.git', :branch => 'use_records_for_joined_resources' gem 'pundit', '~> 1.0' group :development, :test do gem 'sqlite3', '~> 1.3.13' @@ -11,7 +11,7 @@ end appraise 'rails-5-0 pundit-1' do gem 'rails', '5.0.0' # ToDo: This is only for testing purposes - gem 'jsonapi-resources', :git => 'https://github.com/cerebris/jsonapi-resources.git', :branch => 'track_join_options' + gem 'jsonapi-resources', :git => 'https://github.com/cerebris/jsonapi-resources.git', :branch => 'use_records_for_joined_resources' gem 'pundit', '~> 1.0' group :development, :test do gem 'sqlite3', '~> 1.3.13' @@ -21,7 +21,7 @@ end appraise 'rails-5-1 pundit-1' do gem "rails", "5.1.0" # ToDo: This is only for testing purposes - gem 'jsonapi-resources', :git => 'https://github.com/cerebris/jsonapi-resources.git', :branch => 'track_join_options' + gem 'jsonapi-resources', :git => 'https://github.com/cerebris/jsonapi-resources.git', :branch => 'use_records_for_joined_resources' gem 'pundit', '~> 1.0' group :development, :test do gem 'sqlite3', '~> 1.3.13' @@ -31,7 +31,7 @@ end appraise 'rails-5-2 pundit-1' do gem 'rails', '5.2.0' # ToDo: This is only for testing purposes - gem 'jsonapi-resources', :git => 'https://github.com/cerebris/jsonapi-resources.git', :branch => 'track_join_options' + gem 'jsonapi-resources', :git => 'https://github.com/cerebris/jsonapi-resources.git', :branch => 'use_records_for_joined_resources' gem 'pundit', '~> 1.0' group :development, :test do gem 'sqlite3', '~> 1.3.13' @@ -40,7 +40,7 @@ end appraise 'rails-6-0 pundit-1' do gem 'rails', '~> 6.0.0' - gem 'jsonapi-resources', :git => 'https://github.com/cerebris/jsonapi-resources.git', :branch => 'track_join_options' + gem 'jsonapi-resources', :git => 'https://github.com/cerebris/jsonapi-resources.git', :branch => 'use_records_for_joined_resources' gem 'pundit', '~> 1.0' group :development, :test do gem 'sqlite3', '~> 1.4.1' @@ -50,7 +50,7 @@ end appraise 'rails-4-2 pundit-2' do gem 'rails', '4.2.0' # ToDo: This is only for testing purposes - gem 'jsonapi-resources', :git => 'https://github.com/cerebris/jsonapi-resources.git', :branch => 'track_join_options' + gem 'jsonapi-resources', :git => 'https://github.com/cerebris/jsonapi-resources.git', :branch => 'use_records_for_joined_resources' gem 'pundit', '~> 2.0' group :development, :test do gem 'sqlite3', '~> 1.3.13' @@ -60,7 +60,7 @@ end appraise 'rails-5-0 pundit-2' do gem 'rails', '5.0.0' # ToDo: This is only for testing purposes - gem 'jsonapi-resources', :git => 'https://github.com/cerebris/jsonapi-resources.git', :branch => 'track_join_options' + gem 'jsonapi-resources', :git => 'https://github.com/cerebris/jsonapi-resources.git', :branch => 'use_records_for_joined_resources' gem 'pundit', '~> 2.0' group :development, :test do gem 'sqlite3', '~> 1.3.13' @@ -70,7 +70,7 @@ end appraise 'rails-5-1 pundit-2' do gem 'rails', '5.1.0' # ToDo: This is only for testing purposes - gem 'jsonapi-resources', :git => 'https://github.com/cerebris/jsonapi-resources.git', :branch => 'track_join_options' + gem 'jsonapi-resources', :git => 'https://github.com/cerebris/jsonapi-resources.git', :branch => 'use_records_for_joined_resources' gem 'pundit', '~> 2.0' group :development, :test do gem 'sqlite3', '~> 1.3.13' @@ -80,7 +80,7 @@ end appraise 'rails-5-2 pundit-2' do gem 'rails', '5.2.0' # ToDo: This is only for testing purposes - gem 'jsonapi-resources', :git => 'https://github.com/cerebris/jsonapi-resources.git', :branch => 'track_join_options' + gem 'jsonapi-resources', :git => 'https://github.com/cerebris/jsonapi-resources.git', :branch => 'use_records_for_joined_resources' gem 'pundit', '~> 2.0' group :development, :test do gem 'sqlite3', '~> 1.3.13' @@ -89,7 +89,7 @@ end appraise 'rails-6-0 pundit-2' do gem 'rails', '~> 6.0.0' - gem 'jsonapi-resources', :git => 'https://github.com/cerebris/jsonapi-resources.git', :branch => 'track_join_options' + gem 'jsonapi-resources', :git => 'https://github.com/cerebris/jsonapi-resources.git', :branch => 'use_records_for_joined_resources' gem 'pundit', '~> 2.0' group :development, :test do gem 'sqlite3', '~> 1.4.1' diff --git a/Gemfile b/Gemfile index 04d4f9fb..580f8e18 100644 --- a/Gemfile +++ b/Gemfile @@ -4,7 +4,7 @@ source 'https://rubygems.org' gem( 'jsonapi-resources', git: 'https://github.com/cerebris/jsonapi-resources.git', - branch: 'track_join_options' + branch: 'use_records_for_joined_resources' ) gemspec diff --git a/gemfiles/rails_4_2_pundit_1.gemfile b/gemfiles/rails_4_2_pundit_1.gemfile index 2be4ea6f..781d65d9 100644 --- a/gemfiles/rails_4_2_pundit_1.gemfile +++ b/gemfiles/rails_4_2_pundit_1.gemfile @@ -2,7 +2,7 @@ source "https://rubygems.org" -gem "jsonapi-resources", git: "https://github.com/cerebris/jsonapi-resources.git", branch: "track_join_options" +gem "jsonapi-resources", git: "https://github.com/cerebris/jsonapi-resources.git", branch: "use_records_for_joined_resources" gem "rails", "4.2.0" gem "pundit", "~> 1.0" diff --git a/gemfiles/rails_4_2_pundit_2.gemfile b/gemfiles/rails_4_2_pundit_2.gemfile index e2908ff4..bde79232 100644 --- a/gemfiles/rails_4_2_pundit_2.gemfile +++ b/gemfiles/rails_4_2_pundit_2.gemfile @@ -2,7 +2,7 @@ source "https://rubygems.org" -gem "jsonapi-resources", git: "https://github.com/cerebris/jsonapi-resources.git", branch: "track_join_options" +gem "jsonapi-resources", git: "https://github.com/cerebris/jsonapi-resources.git", branch: "use_records_for_joined_resources" gem "rails", "4.2.0" gem "pundit", "~> 2.0" diff --git a/gemfiles/rails_5_0_pundit_1.gemfile b/gemfiles/rails_5_0_pundit_1.gemfile index ce45623c..9f042671 100644 --- a/gemfiles/rails_5_0_pundit_1.gemfile +++ b/gemfiles/rails_5_0_pundit_1.gemfile @@ -2,7 +2,7 @@ source "https://rubygems.org" -gem "jsonapi-resources", git: "https://github.com/cerebris/jsonapi-resources.git", branch: "track_join_options" +gem "jsonapi-resources", git: "https://github.com/cerebris/jsonapi-resources.git", branch: "use_records_for_joined_resources" gem "rails", "5.0.0" gem "pundit", "~> 1.0" diff --git a/gemfiles/rails_5_0_pundit_2.gemfile b/gemfiles/rails_5_0_pundit_2.gemfile index 7e0e140d..b2c632f5 100644 --- a/gemfiles/rails_5_0_pundit_2.gemfile +++ b/gemfiles/rails_5_0_pundit_2.gemfile @@ -2,7 +2,7 @@ source "https://rubygems.org" -gem "jsonapi-resources", git: "https://github.com/cerebris/jsonapi-resources.git", branch: "track_join_options" +gem "jsonapi-resources", git: "https://github.com/cerebris/jsonapi-resources.git", branch: "use_records_for_joined_resources" gem "rails", "5.0.0" gem "pundit", "~> 2.0" diff --git a/gemfiles/rails_5_1_pundit_1.gemfile b/gemfiles/rails_5_1_pundit_1.gemfile index 2ef6308d..8e753452 100644 --- a/gemfiles/rails_5_1_pundit_1.gemfile +++ b/gemfiles/rails_5_1_pundit_1.gemfile @@ -2,7 +2,7 @@ source "https://rubygems.org" -gem "jsonapi-resources", git: "https://github.com/cerebris/jsonapi-resources.git", branch: "track_join_options" +gem "jsonapi-resources", git: "https://github.com/cerebris/jsonapi-resources.git", branch: "use_records_for_joined_resources" gem "rails", "5.1.0" gem "pundit", "~> 1.0" diff --git a/gemfiles/rails_5_1_pundit_2.gemfile b/gemfiles/rails_5_1_pundit_2.gemfile index da9943ed..f106ebc1 100644 --- a/gemfiles/rails_5_1_pundit_2.gemfile +++ b/gemfiles/rails_5_1_pundit_2.gemfile @@ -2,7 +2,7 @@ source "https://rubygems.org" -gem "jsonapi-resources", git: "https://github.com/cerebris/jsonapi-resources.git", branch: "track_join_options" +gem "jsonapi-resources", git: "https://github.com/cerebris/jsonapi-resources.git", branch: "use_records_for_joined_resources" gem "rails", "5.1.0" gem "pundit", "~> 2.0" diff --git a/gemfiles/rails_5_2_pundit_1.gemfile b/gemfiles/rails_5_2_pundit_1.gemfile index fe1f0c4e..081b9e38 100644 --- a/gemfiles/rails_5_2_pundit_1.gemfile +++ b/gemfiles/rails_5_2_pundit_1.gemfile @@ -2,7 +2,7 @@ source "https://rubygems.org" -gem "jsonapi-resources", git: "https://github.com/cerebris/jsonapi-resources.git", branch: "track_join_options" +gem "jsonapi-resources", git: "https://github.com/cerebris/jsonapi-resources.git", branch: "use_records_for_joined_resources" gem "rails", "5.2.0" gem "pundit", "~> 1.0" diff --git a/gemfiles/rails_5_2_pundit_2.gemfile b/gemfiles/rails_5_2_pundit_2.gemfile index 6ac0ea5b..a3f0db0c 100644 --- a/gemfiles/rails_5_2_pundit_2.gemfile +++ b/gemfiles/rails_5_2_pundit_2.gemfile @@ -2,7 +2,7 @@ source "https://rubygems.org" -gem "jsonapi-resources", git: "https://github.com/cerebris/jsonapi-resources.git", branch: "track_join_options" +gem "jsonapi-resources", git: "https://github.com/cerebris/jsonapi-resources.git", branch: "use_records_for_joined_resources" gem "rails", "5.2.0" gem "pundit", "~> 2.0" diff --git a/gemfiles/rails_6_0_pundit_1.gemfile b/gemfiles/rails_6_0_pundit_1.gemfile index 1f5d78e2..4d9e6f31 100644 --- a/gemfiles/rails_6_0_pundit_1.gemfile +++ b/gemfiles/rails_6_0_pundit_1.gemfile @@ -2,7 +2,7 @@ source "https://rubygems.org" -gem "jsonapi-resources", git: "https://github.com/cerebris/jsonapi-resources.git", branch: "track_join_options" +gem "jsonapi-resources", git: "https://github.com/cerebris/jsonapi-resources.git", branch: "use_records_for_joined_resources" gem "rails", "~> 6.0.0" gem "pundit", "~> 1.0" diff --git a/gemfiles/rails_6_0_pundit_2.gemfile b/gemfiles/rails_6_0_pundit_2.gemfile index 2149f677..2c4989b6 100644 --- a/gemfiles/rails_6_0_pundit_2.gemfile +++ b/gemfiles/rails_6_0_pundit_2.gemfile @@ -2,7 +2,7 @@ source "https://rubygems.org" -gem "jsonapi-resources", git: "https://github.com/cerebris/jsonapi-resources.git", branch: "track_join_options" +gem "jsonapi-resources", git: "https://github.com/cerebris/jsonapi-resources.git", branch: "use_records_for_joined_resources" gem "rails", "~> 6.0.0" gem "pundit", "~> 2.0" diff --git a/lib/jsonapi/authorization/pundit_scoped_resource.rb b/lib/jsonapi/authorization/pundit_scoped_resource.rb index 516de626..611e390b 100644 --- a/lib/jsonapi/authorization/pundit_scoped_resource.rb +++ b/lib/jsonapi/authorization/pundit_scoped_resource.rb @@ -10,18 +10,6 @@ def records(options = {}) user_context = JSONAPI::Authorization.configuration.user_context(options[:context]) ::Pundit.policy_scope!(user_context, super) end - - def apply_joins(records, join_manager, options) - records = super - join_manager.join_details.each do |k, v| - next if k == '' || v[:join_type] == :root - v[:join_options][:relationship_details][:resource_klasses].each_key do |klass| - next unless klass.included_modules.include?(PunditScopedResource) - records = records.where(v[:alias] => { klass._primary_key => klass.records(options)}) - end - end - records - end end end end