authorized_transaction 0.2.0 → 0.3.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 +4 -4
- data/CHANGELOG.md +12 -1
- data/Gemfile.lock +1 -9
- data/README.md +25 -4
- data/authorized_transaction.gemspec +0 -2
- data/lib/authorized_transaction.rb +17 -9
- data/lib/authorized_transaction/version.rb +1 -1
- metadata +2 -16
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a0bdbd2a2fc11dfa9e747b42ac807700f0c4656e9bdd328dfdb0bf3877c04bda
|
4
|
+
data.tar.gz: 7379aed3cf7449614cdbaca94eb60ae61b00c40134cab9213097d7d1c970d9b7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fa48ac71bcaf57ce84bb5e50bcbd9ca5fbc44458332f68c2e04311e0ffad69b2d8be9fea55c884816037b7fc42c238e2bbcfc118f0cb8193b694ab9f4c5b002c
|
7
|
+
data.tar.gz: 2373918ea349d71d68c13405b06ec890166fd89538a521a821f951e9d303433bbb2c2e5372dc55c53748e1641c3156b68bdecffd8ecb6b327868494b2ada5170
|
data/CHANGELOG.md
CHANGED
@@ -1,8 +1,19 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
+
## 0.3.0
|
4
|
+
|
5
|
+
- Change `AuthorizedTransaction.configure` to return self if there is no block
|
6
|
+
- Change `AuthorizedTransaction.configure` execution in context of the controller
|
7
|
+
- Change all settings `*_proc` execution in context of the controller
|
8
|
+
- Add `transaction_proc` to change how a transaction is created via configuration
|
9
|
+
- Add tests
|
10
|
+
- Add examples and configuration to README.md
|
11
|
+
- Add explicit notion of _not_ depending on `cancan(can)` to README.md
|
12
|
+
- Remove dependency on `activerecord`
|
13
|
+
|
3
14
|
## 0.2.0
|
4
15
|
|
5
|
-
-
|
16
|
+
- Allow for configuration via `AuthorizedTransaction.configure`
|
6
17
|
|
7
18
|
## 0.1.0
|
8
19
|
|
data/Gemfile.lock
CHANGED
@@ -1,25 +1,17 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
authorized_transaction (0.
|
5
|
-
activerecord (>= 4.0.0)
|
4
|
+
authorized_transaction (0.3.0)
|
6
5
|
activesupport (>= 4.0.0)
|
7
6
|
|
8
7
|
GEM
|
9
8
|
remote: https://rubygems.org/
|
10
9
|
specs:
|
11
|
-
activemodel (5.2.2)
|
12
|
-
activesupport (= 5.2.2)
|
13
|
-
activerecord (5.2.2)
|
14
|
-
activemodel (= 5.2.2)
|
15
|
-
activesupport (= 5.2.2)
|
16
|
-
arel (>= 9.0)
|
17
10
|
activesupport (5.2.2)
|
18
11
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
19
12
|
i18n (>= 0.7, < 2)
|
20
13
|
minitest (~> 5.1)
|
21
14
|
tzinfo (~> 1.1)
|
22
|
-
arel (9.0.0)
|
23
15
|
concurrent-ruby (1.1.4)
|
24
16
|
i18n (1.5.3)
|
25
17
|
concurrent-ruby (~> 1.0)
|
data/README.md
CHANGED
@@ -4,7 +4,7 @@
|
|
4
4
|
[](https://badge.fury.io/rb/authorized_transaction)
|
5
5
|
[](http://opensource.org/licenses/MIT)
|
6
6
|
|
7
|
-
Authorize a certain block with cancan
|
7
|
+
Authorize a certain block with cancan(can), or any other authorization framework that exposes a method `can?`.
|
8
8
|
|
9
9
|
## Installation
|
10
10
|
|
@@ -66,17 +66,38 @@ class Book::SignatureController < ApiController
|
|
66
66
|
end
|
67
67
|
```
|
68
68
|
|
69
|
+
By default it will use `ActiveRecord::Base.transaction` to start the transaction, but you may override this:
|
70
|
+
```ruby
|
71
|
+
AuthorizedTransaction.configure do
|
72
|
+
self.transaction_proc = proc { || CreateDatabaseTransaction.call { yield } }
|
73
|
+
end
|
74
|
+
|
75
|
+
:authorize_proc, :implicit_action_proc,
|
76
|
+
```
|
77
|
+
|
78
|
+
The action passed to `authorize_proc` or `can?` is configured by `implicit_action_key` and defaults to `action`:
|
79
|
+
```ruby
|
80
|
+
AuthorizedTransaction.configure.implicit_action_key = :authorized_action
|
81
|
+
```
|
82
|
+
|
69
83
|
### Configuration
|
70
84
|
|
85
|
+
- By default it uses `can?` as defined on your controller, but you can configure this via `authorize_proc`.
|
86
|
+
- By default it uses the `implicit_action` as defined by `implicit_action_key`, as written above, to determine the
|
87
|
+
implicit action when it's not given. You can also configure these via `implicit_action_key` (fetching from `params`)
|
88
|
+
or `implicit_action_proc` to change completely.
|
89
|
+
|
71
90
|
In an initializer you can set procs in order to change the default behaviour:
|
72
91
|
|
73
92
|
```ruby
|
74
|
-
AuthorizedTransaction.configure do
|
75
|
-
|
76
|
-
|
93
|
+
AuthorizedTransaction.configure do
|
94
|
+
self.implicit_action_proc = proc { |controller| controller.action_name.to_sym }
|
95
|
+
self.authorize_proc = proc { |action, resource, controller| action == :whatever || controller.can?(action, resource) }
|
77
96
|
end
|
78
97
|
```
|
79
98
|
|
99
|
+
Other configuration options are listed above.
|
100
|
+
|
80
101
|
## Development
|
81
102
|
|
82
103
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can
|
@@ -36,8 +36,6 @@ Gem::Specification.new do |spec|
|
|
36
36
|
spec.require_paths = ["lib"]
|
37
37
|
|
38
38
|
spec.add_dependency 'activesupport', '>= 4.0.0'
|
39
|
-
spec.add_dependency 'activerecord', '>= 4.0.0'
|
40
|
-
|
41
39
|
spec.add_development_dependency "bundler", "~> 2.0"
|
42
40
|
spec.add_development_dependency "rake", "~> 10.0"
|
43
41
|
spec.add_development_dependency "minitest", "~> 5.0"
|
@@ -1,20 +1,19 @@
|
|
1
1
|
require "authorized_transaction/version"
|
2
2
|
|
3
|
-
require 'active_record'
|
4
3
|
require 'active_support/concern'
|
5
4
|
require 'active_support/core_ext/module/attribute_accessors'
|
6
5
|
|
7
6
|
module AuthorizedTransaction
|
8
7
|
extend ActiveSupport::Concern
|
9
|
-
class Error <
|
8
|
+
class Error < RuntimeError; end
|
10
9
|
|
11
|
-
mattr_accessor :authorize_proc, :implicit_action_proc, :implicit_action_key
|
10
|
+
mattr_accessor :authorize_proc, :implicit_action_proc, :implicit_action_key, :transaction_proc
|
12
11
|
|
13
|
-
def self.configure
|
14
|
-
|
12
|
+
def self.configure(&block)
|
13
|
+
block_given? ? instance_exec(self, &block) : self
|
15
14
|
end
|
16
15
|
|
17
|
-
class TransactionUnauthorized <
|
16
|
+
class TransactionUnauthorized < Error
|
18
17
|
attr_reader :action, :resource
|
19
18
|
|
20
19
|
def initialize(action, resource)
|
@@ -49,7 +48,7 @@ module AuthorizedTransaction
|
|
49
48
|
# end
|
50
49
|
#
|
51
50
|
def authorized_transaction(action: implicit_action)
|
52
|
-
|
51
|
+
create_transaction do
|
53
52
|
resource = yield
|
54
53
|
authorize! action, resource
|
55
54
|
resource
|
@@ -68,15 +67,24 @@ module AuthorizedTransaction
|
|
68
67
|
|
69
68
|
def implicit_action
|
70
69
|
if implicit_action_proc.respond_to?(:call)
|
71
|
-
return
|
70
|
+
return instance_exec(self, &implicit_action_proc)
|
72
71
|
end
|
73
72
|
|
74
73
|
params[implicit_action_key || :action]
|
75
74
|
end
|
76
75
|
|
76
|
+
def create_transaction(&block)
|
77
|
+
if transaction_proc.respond_to?(:call)
|
78
|
+
transaction_proc.call(&block)
|
79
|
+
else
|
80
|
+
# Expect active record to be loaded by now
|
81
|
+
ActiveRecord::Base.transaction(&block)
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
77
85
|
def authorized?(action, resource)
|
78
86
|
if authorize_proc.respond_to?(:call)
|
79
|
-
return
|
87
|
+
return instance_exec(action, resource, self, &authorize_proc)
|
80
88
|
end
|
81
89
|
|
82
90
|
can?(action, resource)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: authorized_transaction
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Derk-Jan Karrenbeld
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-02-
|
11
|
+
date: 2019-02-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -24,20 +24,6 @@ dependencies:
|
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: 4.0.0
|
27
|
-
- !ruby/object:Gem::Dependency
|
28
|
-
name: activerecord
|
29
|
-
requirement: !ruby/object:Gem::Requirement
|
30
|
-
requirements:
|
31
|
-
- - ">="
|
32
|
-
- !ruby/object:Gem::Version
|
33
|
-
version: 4.0.0
|
34
|
-
type: :runtime
|
35
|
-
prerelease: false
|
36
|
-
version_requirements: !ruby/object:Gem::Requirement
|
37
|
-
requirements:
|
38
|
-
- - ">="
|
39
|
-
- !ruby/object:Gem::Version
|
40
|
-
version: 4.0.0
|
41
27
|
- !ruby/object:Gem::Dependency
|
42
28
|
name: bundler
|
43
29
|
requirement: !ruby/object:Gem::Requirement
|