action_policy-graphiti 0.1.0 → 0.2.1

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: 3b5fda608ae008fec873744642e5ccadf99e72077910cfb3fb848ed05eceb425
4
- data.tar.gz: f77d094525fe60663701cb6df57b8e7a74a64ad0e2316bc18cc7a5fba511bb6d
3
+ metadata.gz: e9ef7ebb5a2a2586e809f9580e6d7eb7f01dc61db0d9f142743e047c3e749efc
4
+ data.tar.gz: 6531c722163597d7257f16aea9b67be101bd2d27de478b33eafd069798ad1db6
5
5
  SHA512:
6
- metadata.gz: 15d75dac6c2dc71a20e70783668395fc99480c32b5c95c65fbe29637fdb3a36d71dc62ef2f18e675854dfa70ecb02f56bd5d0e327f4f3f34fa413683351f6bbc
7
- data.tar.gz: 0234f15a2aea33a1464a1d5dd5b9b9ec330775ff63af4357dc62408b0ab3d8ecc73d0768946799afc94c4570e9e518e6f33fe71a60ac8c0b90c6ddb260963f5d
6
+ metadata.gz: 65f8fde558045c31d5f414e621c1e87d1cb109c8518a64b223211a8b941c9814a2b2c01190bc18264fced4ff3663f47d56cc4d6dfdd0af5d763ac33f37b50f6b
7
+ data.tar.gz: 165cbd931cea33c75c3b1400995c8d5e4763dcd710eb671dbce1d235ae51ed24c98e633231bcacd4af4c391fda7a66d0b658590e37340cc1eb9a9bb139017dcf
data/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # Change Log
2
2
 
3
+ ## [0.2.0] - 2023-06-28
4
+
5
+ - Enable authorization shortcuts
6
+
3
7
  ## [0.1.0] - 2023-06-23
4
8
 
5
9
  - Enable explicit policies and actions
data/README.md CHANGED
@@ -64,7 +64,18 @@ class TestResource < ApplicationResource
64
64
  # or just plain authorize_scope
65
65
  end
66
66
  ```
67
- **Note:** current implementation requires you to place `authorize_scope` call **after** the explicit `base_scope` method (scoping is performed by base scope results modification).
67
+
68
+ You can also use a handy shortcut (you can also use an explicit `with` argument just as with other `authorize_` class methods) to authorize `create`, `update`, `destroy` methods and also apply scoping:
69
+ ```ruby
70
+ class TestResource < ApplicationResource
71
+ include ActionPolicy::Graphiti::Behaviour
72
+
73
+ authorize_and_scope_all with: 'TestExplicitPolicy'
74
+ # or just plain authorize_and_scope_all if you want to deduce the policy class
75
+ end
76
+ ```
77
+
78
+ **Note:** current implementation requires you to place `authorize_scope` (and `authorize_and_scope_all` too) call **after** the explicit `base_scope` method (scoping is performed by base scope results modification).
68
79
 
69
80
  You can also use authorization context building inside Graphiti resources (just like with Action Policy in controllers):
70
81
  ```ruby
@@ -80,6 +80,14 @@ module ActionPolicy
80
80
  )
81
81
  end
82
82
  end
83
+
84
+ def authorize_and_scope_all(**arguments)
85
+ authorize_scope(**arguments)
86
+
87
+ authorize_create(**arguments)
88
+ authorize_update(**arguments)
89
+ authorize_destroy(**arguments)
90
+ end
83
91
  end
84
92
 
85
93
  def self.included(base)
@@ -15,7 +15,7 @@ module ActionPolicy
15
15
  def self.base_resource_class(polymorphic_resource)
16
16
  return unless ResourceValidator.polymorphic_graphiti_resource?(polymorphic_resource)
17
17
 
18
- resource_class = resource.is_a?(Class) ? resource : resource.class
18
+ resource_class = polymorphic_resource.is_a?(Class) ? polymorphic_resource : polymorphic_resource.class
19
19
 
20
20
  polymorphic_marker_index = resource_class.ancestors.find_index(::Graphiti::Resource::Polymorphism)
21
21
 
@@ -2,6 +2,6 @@
2
2
 
3
3
  module ActionPolicy
4
4
  module Graphiti
5
- VERSION = "0.1.0"
5
+ VERSION = "0.2.1"
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: action_policy-graphiti
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrei Mochalov
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-06-23 00:00:00.000000000 Z
11
+ date: 2023-06-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: action_policy