action_policy-graphql 0.3.1 → 0.3.2
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 +4 -4
- data/.travis.yml +10 -4
- data/CHANGELOG.md +5 -0
- data/Gemfile +1 -1
- data/README.md +2 -0
- data/gemfiles/action_policy/0.3.gemfile +5 -0
- data/gemfiles/action_policy/master.gemfile +5 -0
- data/gemfiles/{graphqlmaster.gemfile → graphql/master.gemfile} +1 -1
- data/lib/action_policy/graphql/authorized_field.rb +26 -17
- data/lib/action_policy/graphql/version.rb +1 -1
- metadata +6 -4
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA256:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: 4af0cfd306d4128f52758c4336988f29bfa8628f5839aa18e1a54b366c07a9b9
         | 
| 4 | 
            +
              data.tar.gz: 69098890e8c59b44dd2af5a902639dbc407ce190a73e55c1d84b6c9ce464bad0
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: 2ee55992d03aa2cd350c2c29e9c632c84dff85288a55ef3608e5f277d407f182a98a1bafd820e18caffe4571b1f896cc5608f72979958da0336e6afef0d7f7ef
         | 
| 7 | 
            +
              data.tar.gz: a99cac79463311fecb84d459b537555b9cefe88e0b268b07412d5a0b053ce603c8cea3a426e92cd58033b789d474f008bd3f22b7296270f66e0409f37c0ac6bf
         | 
    
        data/.travis.yml
    CHANGED
    
    | @@ -15,9 +15,13 @@ matrix: | |
| 15 15 | 
             
              fast_finish: true
         | 
| 16 16 | 
             
              include:
         | 
| 17 17 | 
             
                - rvm: ruby-head
         | 
| 18 | 
            -
                  gemfile: gemfiles/ | 
| 18 | 
            +
                  gemfile: gemfiles/graphql/master.gemfile
         | 
| 19 19 | 
             
                - rvm: 2.6
         | 
| 20 | 
            -
                  gemfile: gemfiles/ | 
| 20 | 
            +
                  gemfile: gemfiles/graphql/master.gemfile
         | 
| 21 | 
            +
                - rvm: 2.6
         | 
| 22 | 
            +
                  gemfile: gemfiles/action_policy/master.gemfile
         | 
| 23 | 
            +
                - rvm: 2.6
         | 
| 24 | 
            +
                  gemfile: gemfiles/action_policy/0.3.gemfile
         | 
| 21 25 | 
             
                - rvm: jruby-9.2.5.0
         | 
| 22 26 | 
             
                  gemfile: gemfiles/jruby.gemfile
         | 
| 23 27 | 
             
                - rvm: 2.6
         | 
| @@ -28,6 +32,8 @@ matrix: | |
| 28 32 | 
             
                  gemfile: Gemfile
         | 
| 29 33 | 
             
              allow_failures:
         | 
| 30 34 | 
             
                - rvm: ruby-head
         | 
| 31 | 
            -
                  gemfile: gemfiles/ | 
| 35 | 
            +
                  gemfile: gemfiles/graphql/master.gemfile
         | 
| 36 | 
            +
                - rvm: 2.6
         | 
| 37 | 
            +
                  gemfile: gemfiles/graphql/master.gemfile
         | 
| 32 38 | 
             
                - rvm: 2.6
         | 
| 33 | 
            -
                  gemfile: gemfiles/ | 
| 39 | 
            +
                  gemfile: gemfiles/action_policy/master.gemfile
         | 
    
        data/CHANGELOG.md
    CHANGED
    
    | @@ -2,6 +2,10 @@ | |
| 2 2 |  | 
| 3 3 | 
             
            ## master (unreleased)
         | 
| 4 4 |  | 
| 5 | 
            +
            ## 0.3.2 (2019-12-12)
         | 
| 6 | 
            +
             | 
| 7 | 
            +
            - Fix compatibility with Action Policy 0.4.0 ([@haines][])
         | 
| 8 | 
            +
             | 
| 5 9 | 
             
            ## 0.3.1 (2019-10-23)
         | 
| 6 10 |  | 
| 7 11 | 
             
            - Add support for using Action Policy methods in `self.authorized?`. ([@palkan][])
         | 
| @@ -30,3 +34,4 @@ Action Policy helpers there. | |
| 30 34 | 
             
            - Initial version. ([@palkan][])
         | 
| 31 35 |  | 
| 32 36 | 
             
            [@palkan]: https://github.com/palkan
         | 
| 37 | 
            +
            [@haines]: https://github.com/haines
         | 
    
        data/Gemfile
    CHANGED
    
    | @@ -11,6 +11,6 @@ if File.exist?(local_gemfile) | |
| 11 11 | 
             
              # Specify custom action_policy/graphql-ruby version in Gemfile.local
         | 
| 12 12 | 
             
              eval(File.read(local_gemfile)) # rubocop:disable Security/Eval
         | 
| 13 13 | 
             
            else
         | 
| 14 | 
            -
              gem "action_policy", "~> 0. | 
| 14 | 
            +
              gem "action_policy", "~> 0.4.0"
         | 
| 15 15 | 
             
              gem "graphql", "~> 1.9.3"
         | 
| 16 16 | 
             
            end
         | 
    
        data/README.md
    CHANGED
    
    | @@ -80,6 +80,8 @@ end | |
| 80 80 |  | 
| 81 81 | 
             
            You can customize the authorization options, e.g. `authorize: {to: :preview?, with: CustomPolicy}`.
         | 
| 82 82 |  | 
| 83 | 
            +
            If you don't want to raise an exception but return a null instead, you should set a `raise: false` option.
         | 
| 84 | 
            +
             | 
| 83 85 | 
             
            ### `authorized_scope: *`
         | 
| 84 86 |  | 
| 85 87 | 
             
            You can add `authorized_scope: true` option to the field (list or _connection_ field) to
         | 
| @@ -13,52 +13,61 @@ module ActionPolicy | |
| 13 13 | 
             
                #     field :comments, null: false, authorized: { type: :relation, with: MyPostPolicy }
         | 
| 14 14 | 
             
                #   end
         | 
| 15 15 | 
             
                module AuthorizedField
         | 
| 16 | 
            -
                  class  | 
| 17 | 
            -
                    def  | 
| 18 | 
            -
                       | 
| 19 | 
            -
                      options | 
| 20 | 
            -
                       | 
| 16 | 
            +
                  class Extension < ::GraphQL::Schema::FieldExtension
         | 
| 17 | 
            +
                    def extract_option(key, &default)
         | 
| 18 | 
            +
                      value = options.fetch(key, &default)
         | 
| 19 | 
            +
                      options.delete key
         | 
| 20 | 
            +
                      value
         | 
| 21 | 
            +
                    end
         | 
| 22 | 
            +
                  end
         | 
| 23 | 
            +
             | 
| 24 | 
            +
                  class AuthorizeExtension < Extension
         | 
| 25 | 
            +
                    def apply
         | 
| 26 | 
            +
                      @to = extract_option(:to) { ::ActionPolicy::GraphQL.default_authorize_rule }
         | 
| 27 | 
            +
                      @raise = extract_option(:raise) { ::ActionPolicy::GraphQL.authorize_raise_exception }
         | 
| 21 28 | 
             
                    end
         | 
| 22 29 |  | 
| 23 30 | 
             
                    def after_resolve(value:, context:, object:, **_rest)
         | 
| 24 31 | 
             
                      return value if value.nil?
         | 
| 25 32 |  | 
| 26 | 
            -
                      if  | 
| 27 | 
            -
                        object.authorize! value, **options
         | 
| 33 | 
            +
                      if @raise
         | 
| 34 | 
            +
                        object.authorize! value, to: @to, **options
         | 
| 28 35 | 
             
                        value
         | 
| 29 36 | 
             
                      else
         | 
| 30 | 
            -
                        object.allowed_to?( | 
| 37 | 
            +
                        object.allowed_to?(@to, value, **options) ? value : nil
         | 
| 31 38 | 
             
                      end
         | 
| 32 39 | 
             
                    end
         | 
| 33 40 | 
             
                  end
         | 
| 34 41 |  | 
| 35 | 
            -
                  class PreauthorizeExtension <  | 
| 36 | 
            -
                    def  | 
| 37 | 
            -
                      super
         | 
| 42 | 
            +
                  class PreauthorizeExtension < Extension
         | 
| 43 | 
            +
                    def apply
         | 
| 38 44 | 
             
                      if options[:with].nil?
         | 
| 39 45 | 
             
                        raise ArgumentError, "You must specify the policy for preauthorization: " \
         | 
| 40 46 | 
             
                                             "`field :#{field.name}, preauthorize: {with: SomePolicy}`"
         | 
| 41 47 | 
             
                      end
         | 
| 42 | 
            -
             | 
| 48 | 
            +
             | 
| 49 | 
            +
                      @to = extract_option(:to) do
         | 
| 43 50 | 
             
                        if field.type.list?
         | 
| 44 51 | 
             
                          ::ActionPolicy::GraphQL.default_preauthorize_list_rule
         | 
| 45 52 | 
             
                        else
         | 
| 46 53 | 
             
                          ::ActionPolicy::GraphQL.default_preauthorize_node_rule
         | 
| 47 54 | 
             
                        end
         | 
| 48 | 
            -
                       | 
| 55 | 
            +
                      end
         | 
| 56 | 
            +
             | 
| 57 | 
            +
                      @raise = extract_option(:raise) { ::ActionPolicy::GraphQL.authorize_raise_exception }
         | 
| 49 58 | 
             
                    end
         | 
| 50 59 |  | 
| 51 60 | 
             
                    def resolve(context:, object:, arguments:, **_rest)
         | 
| 52 | 
            -
                      if  | 
| 53 | 
            -
                        object.authorize! field.name, **options
         | 
| 61 | 
            +
                      if @raise
         | 
| 62 | 
            +
                        object.authorize! field.name, to: @to, **options
         | 
| 54 63 | 
             
                        yield object, arguments
         | 
| 55 | 
            -
                      elsif object.allowed_to?( | 
| 64 | 
            +
                      elsif object.allowed_to?(@to, field.name, **options)
         | 
| 56 65 | 
             
                        yield object, arguments
         | 
| 57 66 | 
             
                      end
         | 
| 58 67 | 
             
                    end
         | 
| 59 68 | 
             
                  end
         | 
| 60 69 |  | 
| 61 | 
            -
                  class ScopeExtension <  | 
| 70 | 
            +
                  class ScopeExtension < Extension
         | 
| 62 71 | 
             
                    def after_resolve(value:, context:, object:, **_rest)
         | 
| 63 72 | 
             
                      return value if value.nil?
         | 
| 64 73 |  | 
    
        metadata
    CHANGED
    
    | @@ -1,14 +1,14 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: action_policy-graphql
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 0.3. | 
| 4 | 
            +
              version: 0.3.2
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors:
         | 
| 7 7 | 
             
            - Vladimir Dementyev
         | 
| 8 8 | 
             
            autorequire: 
         | 
| 9 9 | 
             
            bindir: bin
         | 
| 10 10 | 
             
            cert_chain: []
         | 
| 11 | 
            -
            date: 2019- | 
| 11 | 
            +
            date: 2019-12-12 00:00:00.000000000 Z
         | 
| 12 12 | 
             
            dependencies:
         | 
| 13 13 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 14 14 | 
             
              name: action_policy
         | 
| @@ -154,7 +154,9 @@ files: | |
| 154 154 | 
             
            - action_policy-graphql.gemspec
         | 
| 155 155 | 
             
            - bin/console
         | 
| 156 156 | 
             
            - bin/setup
         | 
| 157 | 
            -
            - gemfiles/ | 
| 157 | 
            +
            - gemfiles/action_policy/0.3.gemfile
         | 
| 158 | 
            +
            - gemfiles/action_policy/master.gemfile
         | 
| 159 | 
            +
            - gemfiles/graphql/master.gemfile
         | 
| 158 160 | 
             
            - gemfiles/jruby.gemfile
         | 
| 159 161 | 
             
            - lib/action_policy-graphql.rb
         | 
| 160 162 | 
             
            - lib/action_policy/graphql.rb
         | 
| @@ -188,7 +190,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement | |
| 188 190 | 
             
                - !ruby/object:Gem::Version
         | 
| 189 191 | 
             
                  version: '0'
         | 
| 190 192 | 
             
            requirements: []
         | 
| 191 | 
            -
            rubygems_version: 3.0. | 
| 193 | 
            +
            rubygems_version: 3.0.6
         | 
| 192 194 | 
             
            signing_key: 
         | 
| 193 195 | 
             
            specification_version: 4
         | 
| 194 196 | 
             
            summary: Action Policy integration for GraphQL-Ruby
         |