rails_ops 1.1.18 → 1.1.22
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/.github/workflows/ruby.yml +27 -0
- data/CHANGELOG.md +16 -0
- data/README.md +27 -14
- data/Rakefile +1 -0
- data/VERSION +1 -1
- data/lib/rails_ops/authorization_backend/can_can_can.rb +1 -1
- data/lib/rails_ops/controller_mixin.rb +1 -1
- data/lib/rails_ops/mixins/model/authorization.rb +3 -1
- data/lib/rails_ops/mixins/model/nesting.rb +6 -1
- data/lib/rails_ops/model_mixins/virtual_model_name.rb +9 -0
- data/lib/rails_ops/operation/model/create.rb +1 -1
- data/lib/rails_ops/operation/model/update.rb +17 -2
- data/lib/rails_ops/operation/model.rb +6 -4
- data/rails_ops.gemspec +8 -6
- data/test/dummy/app/models/user.rb +3 -0
- data/test/unit/rails_ops/operation/update_auth_test.rb +62 -0
- data/test/unit/rails_ops/operation/update_lazy_auth_test.rb +63 -0
- metadata +24 -4
- data/.travis.yml +0 -7
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 31751dfbdb75a4da21a438d5ebb92ef9bbd66dd6e459b273c41e5e4f9d6a737c
|
|
4
|
+
data.tar.gz: 3caca2b5c09ac40c8715e2e89554e0aaaf9c8b1c1aa9c57b2c73a9e23bafcb18
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 38ed4b42bbb20810c0e01fc82087ff5b9729f77bb820f26b5c7b34c033c49afe486b9b921141f59a438118678d6aa7a360dc781fa3329c55253901574d3099be
|
|
7
|
+
data.tar.gz: a61c2739ea1daff6e313e943873389d38f2506e647cb29b0edfa12cb054b94befb8e8a67721decba8d753a3e3c291527a0e313413e5722910907c27425e22e15
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
name: Build
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches: [ master ]
|
|
6
|
+
pull_request:
|
|
7
|
+
branches: [ master ]
|
|
8
|
+
|
|
9
|
+
jobs:
|
|
10
|
+
test:
|
|
11
|
+
runs-on: ubuntu-latest
|
|
12
|
+
strategy:
|
|
13
|
+
fail-fast: false
|
|
14
|
+
matrix:
|
|
15
|
+
ruby-version: ['2.3.0', '2.5.1', '2.6.2', '2.7.1', '3.0.1']
|
|
16
|
+
|
|
17
|
+
steps:
|
|
18
|
+
- uses: actions/checkout@v2
|
|
19
|
+
- name: Set up Ruby
|
|
20
|
+
uses: ruby/setup-ruby@v1
|
|
21
|
+
with:
|
|
22
|
+
ruby-version: ${{ matrix.ruby-version }}
|
|
23
|
+
bundler-cache: true
|
|
24
|
+
- name: Run rake tests
|
|
25
|
+
run: bundle exec rake test
|
|
26
|
+
- name: Run rubocop
|
|
27
|
+
run: bundle exec rubocop
|
data/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,21 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 1.1.21 (2021-11-01)
|
|
4
|
+
|
|
5
|
+
* Add support for lazy model authorization
|
|
6
|
+
|
|
7
|
+
## 1.1.21 (2021-06-23)
|
|
8
|
+
|
|
9
|
+
* Fix using model operations in conjunction with Single Table Inheritance (STI)
|
|
10
|
+
|
|
11
|
+
## 1.1.20 (2021-02-18)
|
|
12
|
+
|
|
13
|
+
* Fix warnings with Ruby 2.7
|
|
14
|
+
|
|
15
|
+
## 1.1.19 (2021-02-16)
|
|
16
|
+
|
|
17
|
+
* Fix warnings with Ruby 2.7
|
|
18
|
+
|
|
3
19
|
## 1.1.18 (2021-02-16)
|
|
4
20
|
|
|
5
21
|
* Adapt signature of `schema3` method to support other types than hashes
|
data/README.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
[](https://github.com/sitrox/rails_ops/actions/workflows/ruby.yml)
|
|
2
2
|
[](https://badge.fury.io/rb/rails_ops)
|
|
3
3
|
|
|
4
4
|
rails_ops
|
|
@@ -988,24 +988,18 @@ class Operations::User::Load < RailsOps::Operation::Model::Load
|
|
|
988
988
|
model User
|
|
989
989
|
end
|
|
990
990
|
|
|
991
|
-
op = Operations::User::Load.run!(id: 5)
|
|
992
|
-
op.model.id # => 5
|
|
993
|
-
```
|
|
994
|
-
|
|
995
|
-
Note that this base class is a bit of a special case: It does not provide a
|
|
996
|
-
`perform` method and does not need to be run at all in order to load a model.
|
|
997
|
-
This is very useful when, for example, displaying a form based on a model
|
|
998
|
-
instance without actually performing any particular action such as updating a
|
|
999
|
-
model.
|
|
1000
|
-
|
|
1001
|
-
Therefore, the above example would also work as follows:
|
|
1002
|
-
|
|
1003
|
-
```ruby
|
|
1004
991
|
# The operation does not have to be performed to access the model instance.
|
|
1005
992
|
op = Operations::User::Load.new(id: 5)
|
|
1006
993
|
op.model.id # => 5
|
|
1007
994
|
```
|
|
1008
995
|
|
|
996
|
+
Note that this base class is a bit of a special case: It does not provide an
|
|
997
|
+
implementation of the `perform` method and does not need to be run at all in
|
|
998
|
+
order to load a model (in fact, it cannot be run unless you override the
|
|
999
|
+
`perform` method). This is very useful when, for example, displaying a form
|
|
1000
|
+
based on a model instance without actually performing any particular action such
|
|
1001
|
+
as updating a model.
|
|
1002
|
+
|
|
1009
1003
|
#### Specifying ID field
|
|
1010
1004
|
|
|
1011
1005
|
Per default, the model instance is looked up using the field `id` and the ID
|
|
@@ -1195,6 +1189,25 @@ end
|
|
|
1195
1189
|
Note that using the different model base classes, this is already set to a
|
|
1196
1190
|
sensible default. See the respective class' source code for details.
|
|
1197
1191
|
|
|
1192
|
+
#### Lazy model update authorization
|
|
1193
|
+
|
|
1194
|
+
In case of operations inheriting from `RailsOps::Operation::Model::Update`, you
|
|
1195
|
+
can specify the `model_authorization_action` to be `lazy`, meaning that it will
|
|
1196
|
+
only be checked when *performing* the operation, but not on initialization. This
|
|
1197
|
+
can be useful for displaying readonly forms to users which do not have
|
|
1198
|
+
read-permissions only:
|
|
1199
|
+
|
|
1200
|
+
```ruby
|
|
1201
|
+
class Operations::User::Update < RailsOps::Operation::Model::Update
|
|
1202
|
+
model User
|
|
1203
|
+
|
|
1204
|
+
# This automatically calls `authorize_model! :read`. Because it is set to be
|
|
1205
|
+
# `lazy`, the authorization will only run when the operation is actually
|
|
1206
|
+
# *performed*, and not already at instantiation.
|
|
1207
|
+
model_authorization_action :read, lazy: true
|
|
1208
|
+
end
|
|
1209
|
+
```
|
|
1210
|
+
|
|
1198
1211
|
### Model nesting
|
|
1199
1212
|
|
|
1200
1213
|
Using active record, multiple nested models can be saved at once by using
|
data/Rakefile
CHANGED
|
@@ -18,6 +18,7 @@ task :gemspec do
|
|
|
18
18
|
spec.add_development_dependency 'bundler'
|
|
19
19
|
spec.add_development_dependency 'rake'
|
|
20
20
|
spec.add_development_dependency 'sqlite3'
|
|
21
|
+
spec.add_development_dependency 'cancancan'
|
|
21
22
|
spec.add_development_dependency 'rubocop', '0.47.1'
|
|
22
23
|
spec.add_dependency 'active_type', '>= 1.3.0'
|
|
23
24
|
spec.add_dependency 'minitest'
|
data/VERSION
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
1.1.
|
|
1
|
+
1.1.22
|
|
@@ -6,13 +6,15 @@ module RailsOps::Mixins::Model::Authorization
|
|
|
6
6
|
|
|
7
7
|
included do
|
|
8
8
|
class_attribute :_model_authorization_action
|
|
9
|
+
class_attribute :_model_authorization_lazy
|
|
9
10
|
end
|
|
10
11
|
|
|
11
12
|
module ClassMethods
|
|
12
13
|
# Gets or sets the action verb used for authorizing models.
|
|
13
|
-
def model_authorization_action(*action)
|
|
14
|
+
def model_authorization_action(*action, lazy: false)
|
|
14
15
|
if action.size == 1
|
|
15
16
|
self._model_authorization_action = action.first
|
|
17
|
+
self._model_authorization_lazy = lazy
|
|
16
18
|
elsif action.size > 1
|
|
17
19
|
fail ArgumentError, 'Too many arguments'
|
|
18
20
|
end
|
|
@@ -6,6 +6,11 @@ module RailsOps::Mixins::Model::Nesting
|
|
|
6
6
|
self._nested_model_ops = {}.freeze
|
|
7
7
|
|
|
8
8
|
attr_reader :nested_model_ops
|
|
9
|
+
|
|
10
|
+
policy :on_init do
|
|
11
|
+
@nested_model_ops_performed = false
|
|
12
|
+
@nested_model_ops = nil
|
|
13
|
+
end
|
|
9
14
|
end
|
|
10
15
|
|
|
11
16
|
module ClassMethods
|
|
@@ -85,7 +90,7 @@ module RailsOps::Mixins::Model::Nesting
|
|
|
85
90
|
end
|
|
86
91
|
|
|
87
92
|
def nested_model_ops_performed?
|
|
88
|
-
@nested_model_ops_performed
|
|
93
|
+
@nested_model_ops_performed
|
|
89
94
|
end
|
|
90
95
|
|
|
91
96
|
protected
|
|
@@ -5,12 +5,21 @@ module RailsOps
|
|
|
5
5
|
|
|
6
6
|
included do
|
|
7
7
|
class_attribute :virtual_model_name
|
|
8
|
+
class_attribute :virtual_sti_name
|
|
8
9
|
end
|
|
9
10
|
|
|
10
11
|
module ClassMethods
|
|
11
12
|
def model_name
|
|
12
13
|
virtual_model_name || super
|
|
13
14
|
end
|
|
15
|
+
|
|
16
|
+
def sti_name
|
|
17
|
+
virtual_sti_name || super
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def find_sti_class(_type_name)
|
|
21
|
+
self
|
|
22
|
+
end
|
|
14
23
|
end
|
|
15
24
|
end
|
|
16
25
|
end
|
|
@@ -20,7 +20,7 @@ class RailsOps::Operation::Model::Create < RailsOps::Operation::Model
|
|
|
20
20
|
end
|
|
21
21
|
|
|
22
22
|
def build_model
|
|
23
|
-
fail 'Model can only be built once.' if @model
|
|
23
|
+
fail 'Model can only be built once.' if defined?(@model) && @model
|
|
24
24
|
@model = self.class.model.new
|
|
25
25
|
if @model.respond_to?(:parent_op=)
|
|
26
26
|
@model.parent_op = self
|
|
@@ -7,14 +7,29 @@ class RailsOps::Operation::Model::Update < RailsOps::Operation::Model::Load
|
|
|
7
7
|
true
|
|
8
8
|
end
|
|
9
9
|
|
|
10
|
+
policy :before_perform do
|
|
11
|
+
if model_authorization_action && self.class._model_authorization_lazy
|
|
12
|
+
authorize_model! model_authorization_action, model
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
|
|
10
16
|
def model_authorization
|
|
11
17
|
return unless authorization_enabled?
|
|
12
18
|
|
|
13
|
-
|
|
19
|
+
if self.class._model_authorization_lazy
|
|
20
|
+
if load_model_authorization_action.nil?
|
|
21
|
+
fail RailsOps::Exceptions::NoAuthorizationPerformed,
|
|
22
|
+
"Operation #{self.class.name} must specify a "\
|
|
23
|
+
'load_model_authorization_action because model '\
|
|
24
|
+
'authorization is configured to be lazy.'
|
|
25
|
+
else
|
|
26
|
+
authorize_model! load_model_authorization_action, model
|
|
27
|
+
end
|
|
28
|
+
elsif !load_model_authorization_action.nil?
|
|
14
29
|
authorize_model_with_authorize_only! load_model_authorization_action, model
|
|
15
30
|
end
|
|
16
31
|
|
|
17
|
-
unless model_authorization_action.nil?
|
|
32
|
+
unless model_authorization_action.nil? || self.class._model_authorization_lazy
|
|
18
33
|
authorize_model! model_authorization_action, model
|
|
19
34
|
end
|
|
20
35
|
end
|
|
@@ -69,6 +69,11 @@ class RailsOps::Operation::Model < RailsOps::Operation
|
|
|
69
69
|
_model_class.virtual_model_name = ActiveModel::Name.new(_model_class, nil, name.to_s)
|
|
70
70
|
end
|
|
71
71
|
|
|
72
|
+
# Set virtual STI name if given.
|
|
73
|
+
if model_class && model_class.name
|
|
74
|
+
_model_class.virtual_sti_name = model_class.name
|
|
75
|
+
end
|
|
76
|
+
|
|
72
77
|
# ---------------------------------------------------------------
|
|
73
78
|
# We just use the given model class without any adaptions
|
|
74
79
|
# ---------------------------------------------------------------
|
|
@@ -100,10 +105,7 @@ class RailsOps::Operation::Model < RailsOps::Operation
|
|
|
100
105
|
# Returns an instance of the operation model class. The instance is obtained
|
|
101
106
|
# using {build_model} and cached for the lifespan of the operation instance.
|
|
102
107
|
def model
|
|
103
|
-
unless @model
|
|
104
|
-
build_model
|
|
105
|
-
end
|
|
106
|
-
|
|
108
|
+
build_model unless defined?(@model) && @model
|
|
107
109
|
return @model
|
|
108
110
|
end
|
|
109
111
|
|
data/rails_ops.gemspec
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
|
2
|
-
# stub: rails_ops 1.1.
|
|
2
|
+
# stub: rails_ops 1.1.22 ruby lib
|
|
3
3
|
|
|
4
4
|
Gem::Specification.new do |s|
|
|
5
5
|
s.name = "rails_ops".freeze
|
|
6
|
-
s.version = "1.1.
|
|
6
|
+
s.version = "1.1.22"
|
|
7
7
|
|
|
8
8
|
s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version=
|
|
9
9
|
s.require_paths = ["lib".freeze]
|
|
10
10
|
s.authors = ["Sitrox".freeze]
|
|
11
|
-
s.date = "2021-
|
|
12
|
-
s.files = [".
|
|
13
|
-
s.rubygems_version = "3.
|
|
11
|
+
s.date = "2021-11-01"
|
|
12
|
+
s.files = [".github/workflows/ruby.yml".freeze, ".gitignore".freeze, ".releaser_config".freeze, ".rubocop.yml".freeze, "CHANGELOG.md".freeze, "Gemfile".freeze, "LICENSE".freeze, "README.md".freeze, "Rakefile".freeze, "VERSION".freeze, "lib/rails_ops.rb".freeze, "lib/rails_ops/authorization_backend/abstract.rb".freeze, "lib/rails_ops/authorization_backend/can_can_can.rb".freeze, "lib/rails_ops/configuration.rb".freeze, "lib/rails_ops/context.rb".freeze, "lib/rails_ops/controller_mixin.rb".freeze, "lib/rails_ops/exceptions.rb".freeze, "lib/rails_ops/hooked_job.rb".freeze, "lib/rails_ops/hookup.rb".freeze, "lib/rails_ops/hookup/dsl.rb".freeze, "lib/rails_ops/hookup/dsl_validator.rb".freeze, "lib/rails_ops/hookup/hook.rb".freeze, "lib/rails_ops/log_subscriber.rb".freeze, "lib/rails_ops/mixins.rb".freeze, "lib/rails_ops/mixins/authorization.rb".freeze, "lib/rails_ops/mixins/log_settings.rb".freeze, "lib/rails_ops/mixins/model.rb".freeze, "lib/rails_ops/mixins/model/authorization.rb".freeze, "lib/rails_ops/mixins/model/nesting.rb".freeze, "lib/rails_ops/mixins/param_authorization.rb".freeze, "lib/rails_ops/mixins/policies.rb".freeze, "lib/rails_ops/mixins/require_context.rb".freeze, "lib/rails_ops/mixins/routes.rb".freeze, "lib/rails_ops/mixins/schema_validation.rb".freeze, "lib/rails_ops/mixins/sub_ops.rb".freeze, "lib/rails_ops/model_casting.rb".freeze, "lib/rails_ops/model_mixins.rb".freeze, "lib/rails_ops/model_mixins/ar_extension.rb".freeze, "lib/rails_ops/model_mixins/parent_op.rb".freeze, "lib/rails_ops/model_mixins/virtual_attributes.rb".freeze, "lib/rails_ops/model_mixins/virtual_attributes/virtual_column_wrapper.rb".freeze, "lib/rails_ops/model_mixins/virtual_has_one.rb".freeze, "lib/rails_ops/model_mixins/virtual_model_name.rb".freeze, "lib/rails_ops/operation.rb".freeze, "lib/rails_ops/operation/model.rb".freeze, "lib/rails_ops/operation/model/create.rb".freeze, "lib/rails_ops/operation/model/destroy.rb".freeze, "lib/rails_ops/operation/model/load.rb".freeze, "lib/rails_ops/operation/model/update.rb".freeze, "lib/rails_ops/patches/active_type_patch.rb".freeze, "lib/rails_ops/profiler.rb".freeze, "lib/rails_ops/profiler/node.rb".freeze, "lib/rails_ops/railtie.rb".freeze, "lib/rails_ops/scoped_env.rb".freeze, "lib/rails_ops/virtual_model.rb".freeze, "rails_ops.gemspec".freeze, "test/db/models.rb".freeze, "test/db/schema.rb".freeze, "test/dummy/Rakefile".freeze, "test/dummy/app/assets/config/manifest.js".freeze, "test/dummy/app/assets/images/.keep".freeze, "test/dummy/app/assets/javascripts/application.js".freeze, "test/dummy/app/assets/javascripts/cable.js".freeze, "test/dummy/app/assets/javascripts/channels/.keep".freeze, "test/dummy/app/assets/stylesheets/application.css".freeze, "test/dummy/app/channels/application_cable/channel.rb".freeze, "test/dummy/app/channels/application_cable/connection.rb".freeze, "test/dummy/app/controllers/application_controller.rb".freeze, "test/dummy/app/controllers/concerns/.keep".freeze, "test/dummy/app/helpers/application_helper.rb".freeze, "test/dummy/app/jobs/application_job.rb".freeze, "test/dummy/app/mailers/application_mailer.rb".freeze, "test/dummy/app/models/application_record.rb".freeze, "test/dummy/app/models/concerns/.keep".freeze, "test/dummy/app/models/group.rb".freeze, "test/dummy/app/models/user.rb".freeze, "test/dummy/app/views/layouts/application.html.erb".freeze, "test/dummy/app/views/layouts/mailer.html.erb".freeze, "test/dummy/app/views/layouts/mailer.text.erb".freeze, "test/dummy/bin/bundle".freeze, "test/dummy/bin/rails".freeze, "test/dummy/bin/rake".freeze, "test/dummy/bin/setup".freeze, "test/dummy/bin/update".freeze, "test/dummy/bin/yarn".freeze, "test/dummy/config.ru".freeze, "test/dummy/config/application.rb".freeze, "test/dummy/config/boot.rb".freeze, "test/dummy/config/cable.yml".freeze, "test/dummy/config/database.yml".freeze, "test/dummy/config/environment.rb".freeze, "test/dummy/config/environments/development.rb".freeze, "test/dummy/config/environments/production.rb".freeze, "test/dummy/config/environments/test.rb".freeze, "test/dummy/config/initializers/application_controller_renderer.rb".freeze, "test/dummy/config/initializers/assets.rb".freeze, "test/dummy/config/initializers/backtrace_silencers.rb".freeze, "test/dummy/config/initializers/cookies_serializer.rb".freeze, "test/dummy/config/initializers/filter_parameter_logging.rb".freeze, "test/dummy/config/initializers/inflections.rb".freeze, "test/dummy/config/initializers/mime_types.rb".freeze, "test/dummy/config/initializers/rails_ops.rb".freeze, "test/dummy/config/initializers/wrap_parameters.rb".freeze, "test/dummy/config/locales/en.yml".freeze, "test/dummy/config/puma.rb".freeze, "test/dummy/config/routes.rb".freeze, "test/dummy/config/secrets.yml".freeze, "test/dummy/config/spring.rb".freeze, "test/dummy/db/schema.rb".freeze, "test/dummy/lib/assets/.keep".freeze, "test/dummy/log/.keep".freeze, "test/dummy/package.json".freeze, "test/dummy/public/404.html".freeze, "test/dummy/public/422.html".freeze, "test/dummy/public/500.html".freeze, "test/dummy/public/apple-touch-icon-precomposed.png".freeze, "test/dummy/public/apple-touch-icon.png".freeze, "test/dummy/public/favicon.ico".freeze, "test/dummy/tmp/.keep".freeze, "test/test_helper.rb".freeze, "test/unit/rails_ops/mixins/model/nesting.rb".freeze, "test/unit/rails_ops/mixins/policies_test.rb".freeze, "test/unit/rails_ops/operation/model/create_test.rb".freeze, "test/unit/rails_ops/operation/model/load_test.rb".freeze, "test/unit/rails_ops/operation/model/update_test.rb".freeze, "test/unit/rails_ops/operation/model_test.rb".freeze, "test/unit/rails_ops/operation/update_auth_test.rb".freeze, "test/unit/rails_ops/operation/update_lazy_auth_test.rb".freeze, "test/unit/rails_ops/operation_test.rb".freeze]
|
|
13
|
+
s.rubygems_version = "3.2.22".freeze
|
|
14
14
|
s.summary = "An operations service layer for rails projects.".freeze
|
|
15
|
-
s.test_files = ["test/db/models.rb".freeze, "test/db/schema.rb".freeze, "test/dummy/Rakefile".freeze, "test/dummy/app/assets/config/manifest.js".freeze, "test/dummy/app/assets/images/.keep".freeze, "test/dummy/app/assets/javascripts/application.js".freeze, "test/dummy/app/assets/javascripts/cable.js".freeze, "test/dummy/app/assets/javascripts/channels/.keep".freeze, "test/dummy/app/assets/stylesheets/application.css".freeze, "test/dummy/app/channels/application_cable/channel.rb".freeze, "test/dummy/app/channels/application_cable/connection.rb".freeze, "test/dummy/app/controllers/application_controller.rb".freeze, "test/dummy/app/controllers/concerns/.keep".freeze, "test/dummy/app/helpers/application_helper.rb".freeze, "test/dummy/app/jobs/application_job.rb".freeze, "test/dummy/app/mailers/application_mailer.rb".freeze, "test/dummy/app/models/application_record.rb".freeze, "test/dummy/app/models/concerns/.keep".freeze, "test/dummy/app/models/group.rb".freeze, "test/dummy/app/views/layouts/application.html.erb".freeze, "test/dummy/app/views/layouts/mailer.html.erb".freeze, "test/dummy/app/views/layouts/mailer.text.erb".freeze, "test/dummy/bin/bundle".freeze, "test/dummy/bin/rails".freeze, "test/dummy/bin/rake".freeze, "test/dummy/bin/setup".freeze, "test/dummy/bin/update".freeze, "test/dummy/bin/yarn".freeze, "test/dummy/config.ru".freeze, "test/dummy/config/application.rb".freeze, "test/dummy/config/boot.rb".freeze, "test/dummy/config/cable.yml".freeze, "test/dummy/config/database.yml".freeze, "test/dummy/config/environment.rb".freeze, "test/dummy/config/environments/development.rb".freeze, "test/dummy/config/environments/production.rb".freeze, "test/dummy/config/environments/test.rb".freeze, "test/dummy/config/initializers/application_controller_renderer.rb".freeze, "test/dummy/config/initializers/assets.rb".freeze, "test/dummy/config/initializers/backtrace_silencers.rb".freeze, "test/dummy/config/initializers/cookies_serializer.rb".freeze, "test/dummy/config/initializers/filter_parameter_logging.rb".freeze, "test/dummy/config/initializers/inflections.rb".freeze, "test/dummy/config/initializers/mime_types.rb".freeze, "test/dummy/config/initializers/rails_ops.rb".freeze, "test/dummy/config/initializers/wrap_parameters.rb".freeze, "test/dummy/config/locales/en.yml".freeze, "test/dummy/config/puma.rb".freeze, "test/dummy/config/routes.rb".freeze, "test/dummy/config/secrets.yml".freeze, "test/dummy/config/spring.rb".freeze, "test/dummy/db/schema.rb".freeze, "test/dummy/lib/assets/.keep".freeze, "test/dummy/log/.keep".freeze, "test/dummy/package.json".freeze, "test/dummy/public/404.html".freeze, "test/dummy/public/422.html".freeze, "test/dummy/public/500.html".freeze, "test/dummy/public/apple-touch-icon-precomposed.png".freeze, "test/dummy/public/apple-touch-icon.png".freeze, "test/dummy/public/favicon.ico".freeze, "test/dummy/tmp/.keep".freeze, "test/test_helper.rb".freeze, "test/unit/rails_ops/mixins/model/nesting.rb".freeze, "test/unit/rails_ops/mixins/policies_test.rb".freeze, "test/unit/rails_ops/operation/model/create_test.rb".freeze, "test/unit/rails_ops/operation/model/load_test.rb".freeze, "test/unit/rails_ops/operation/model/update_test.rb".freeze, "test/unit/rails_ops/operation/model_test.rb".freeze, "test/unit/rails_ops/operation_test.rb".freeze]
|
|
15
|
+
s.test_files = ["test/db/models.rb".freeze, "test/db/schema.rb".freeze, "test/dummy/Rakefile".freeze, "test/dummy/app/assets/config/manifest.js".freeze, "test/dummy/app/assets/images/.keep".freeze, "test/dummy/app/assets/javascripts/application.js".freeze, "test/dummy/app/assets/javascripts/cable.js".freeze, "test/dummy/app/assets/javascripts/channels/.keep".freeze, "test/dummy/app/assets/stylesheets/application.css".freeze, "test/dummy/app/channels/application_cable/channel.rb".freeze, "test/dummy/app/channels/application_cable/connection.rb".freeze, "test/dummy/app/controllers/application_controller.rb".freeze, "test/dummy/app/controllers/concerns/.keep".freeze, "test/dummy/app/helpers/application_helper.rb".freeze, "test/dummy/app/jobs/application_job.rb".freeze, "test/dummy/app/mailers/application_mailer.rb".freeze, "test/dummy/app/models/application_record.rb".freeze, "test/dummy/app/models/concerns/.keep".freeze, "test/dummy/app/models/group.rb".freeze, "test/dummy/app/models/user.rb".freeze, "test/dummy/app/views/layouts/application.html.erb".freeze, "test/dummy/app/views/layouts/mailer.html.erb".freeze, "test/dummy/app/views/layouts/mailer.text.erb".freeze, "test/dummy/bin/bundle".freeze, "test/dummy/bin/rails".freeze, "test/dummy/bin/rake".freeze, "test/dummy/bin/setup".freeze, "test/dummy/bin/update".freeze, "test/dummy/bin/yarn".freeze, "test/dummy/config.ru".freeze, "test/dummy/config/application.rb".freeze, "test/dummy/config/boot.rb".freeze, "test/dummy/config/cable.yml".freeze, "test/dummy/config/database.yml".freeze, "test/dummy/config/environment.rb".freeze, "test/dummy/config/environments/development.rb".freeze, "test/dummy/config/environments/production.rb".freeze, "test/dummy/config/environments/test.rb".freeze, "test/dummy/config/initializers/application_controller_renderer.rb".freeze, "test/dummy/config/initializers/assets.rb".freeze, "test/dummy/config/initializers/backtrace_silencers.rb".freeze, "test/dummy/config/initializers/cookies_serializer.rb".freeze, "test/dummy/config/initializers/filter_parameter_logging.rb".freeze, "test/dummy/config/initializers/inflections.rb".freeze, "test/dummy/config/initializers/mime_types.rb".freeze, "test/dummy/config/initializers/rails_ops.rb".freeze, "test/dummy/config/initializers/wrap_parameters.rb".freeze, "test/dummy/config/locales/en.yml".freeze, "test/dummy/config/puma.rb".freeze, "test/dummy/config/routes.rb".freeze, "test/dummy/config/secrets.yml".freeze, "test/dummy/config/spring.rb".freeze, "test/dummy/db/schema.rb".freeze, "test/dummy/lib/assets/.keep".freeze, "test/dummy/log/.keep".freeze, "test/dummy/package.json".freeze, "test/dummy/public/404.html".freeze, "test/dummy/public/422.html".freeze, "test/dummy/public/500.html".freeze, "test/dummy/public/apple-touch-icon-precomposed.png".freeze, "test/dummy/public/apple-touch-icon.png".freeze, "test/dummy/public/favicon.ico".freeze, "test/dummy/tmp/.keep".freeze, "test/test_helper.rb".freeze, "test/unit/rails_ops/mixins/model/nesting.rb".freeze, "test/unit/rails_ops/mixins/policies_test.rb".freeze, "test/unit/rails_ops/operation/model/create_test.rb".freeze, "test/unit/rails_ops/operation/model/load_test.rb".freeze, "test/unit/rails_ops/operation/model/update_test.rb".freeze, "test/unit/rails_ops/operation/model_test.rb".freeze, "test/unit/rails_ops/operation/update_auth_test.rb".freeze, "test/unit/rails_ops/operation/update_lazy_auth_test.rb".freeze, "test/unit/rails_ops/operation_test.rb".freeze]
|
|
16
16
|
|
|
17
17
|
if s.respond_to? :specification_version then
|
|
18
18
|
s.specification_version = 4
|
|
@@ -22,6 +22,7 @@ Gem::Specification.new do |s|
|
|
|
22
22
|
s.add_development_dependency(%q<bundler>.freeze, [">= 0"])
|
|
23
23
|
s.add_development_dependency(%q<rake>.freeze, [">= 0"])
|
|
24
24
|
s.add_development_dependency(%q<sqlite3>.freeze, [">= 0"])
|
|
25
|
+
s.add_development_dependency(%q<cancancan>.freeze, [">= 0"])
|
|
25
26
|
s.add_development_dependency(%q<rubocop>.freeze, ["= 0.47.1"])
|
|
26
27
|
s.add_runtime_dependency(%q<active_type>.freeze, [">= 1.3.0"])
|
|
27
28
|
s.add_runtime_dependency(%q<minitest>.freeze, [">= 0"])
|
|
@@ -32,6 +33,7 @@ Gem::Specification.new do |s|
|
|
|
32
33
|
s.add_dependency(%q<bundler>.freeze, [">= 0"])
|
|
33
34
|
s.add_dependency(%q<rake>.freeze, [">= 0"])
|
|
34
35
|
s.add_dependency(%q<sqlite3>.freeze, [">= 0"])
|
|
36
|
+
s.add_dependency(%q<cancancan>.freeze, [">= 0"])
|
|
35
37
|
s.add_dependency(%q<rubocop>.freeze, ["= 0.47.1"])
|
|
36
38
|
s.add_dependency(%q<active_type>.freeze, [">= 1.3.0"])
|
|
37
39
|
s.add_dependency(%q<minitest>.freeze, [">= 0"])
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
require 'test_helper'
|
|
2
|
+
require 'rails_ops/authorization_backend/can_can_can'
|
|
3
|
+
require 'cancancan'
|
|
4
|
+
|
|
5
|
+
class RailsOps::Operation::UpdateLazyAuthTest < ActiveSupport::TestCase
|
|
6
|
+
include TestHelper
|
|
7
|
+
|
|
8
|
+
BASIC_OP = Class.new(RailsOps::Operation::Model::Update) do
|
|
9
|
+
model ::Group
|
|
10
|
+
|
|
11
|
+
model_authorization_action :update
|
|
12
|
+
|
|
13
|
+
def perform
|
|
14
|
+
fail osparams.exception if osparams.exception
|
|
15
|
+
@done = true
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
ABILITY = Class.new do
|
|
20
|
+
include CanCan::Ability
|
|
21
|
+
|
|
22
|
+
def initialize(read: false, update: false)
|
|
23
|
+
can :read, Group if read
|
|
24
|
+
can :update, Group if update
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
setup do
|
|
29
|
+
Group.create!(id: 1, name: 'Group')
|
|
30
|
+
RailsOps.config.authorization_backend = 'RailsOps::AuthorizationBackend::CanCanCan'
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def test_unpermitted_read
|
|
34
|
+
ctx = RailsOps::Context.new(ability: ABILITY.new(read: true))
|
|
35
|
+
assert_raises CanCan::AccessDenied do
|
|
36
|
+
BASIC_OP.new(ctx, id: 1)
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def test_permitted_read
|
|
41
|
+
ctx = RailsOps::Context.new(ability: ABILITY.new(read: true))
|
|
42
|
+
assert_nothing_raised do
|
|
43
|
+
BASIC_OP.new(ctx, id: 1)
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def test_unpermitted_update
|
|
48
|
+
ctx = RailsOps::Context.new(ability: ABILITY.new(read: true))
|
|
49
|
+
op = BASIC_OP.new(ctx, id: 1)
|
|
50
|
+
assert_raises CanCan::AccessDenied do
|
|
51
|
+
op.run!
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
def test_permitted_update
|
|
56
|
+
ctx = RailsOps::Context.new(ability: ABILITY.new(read: true, update: true))
|
|
57
|
+
op = BASIC_OP.new(ctx, id: 1)
|
|
58
|
+
assert_nothing_raised do
|
|
59
|
+
op.run!
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
end
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
require 'test_helper'
|
|
2
|
+
require 'rails_ops/authorization_backend/can_can_can'
|
|
3
|
+
require 'cancancan'
|
|
4
|
+
|
|
5
|
+
class RailsOps::Operation::UpdateLazyAuthTest < ActiveSupport::TestCase
|
|
6
|
+
include TestHelper
|
|
7
|
+
|
|
8
|
+
BASIC_OP = Class.new(RailsOps::Operation::Model::Update) do
|
|
9
|
+
model ::Group
|
|
10
|
+
|
|
11
|
+
model_authorization_action :update, lazy: true
|
|
12
|
+
|
|
13
|
+
def perform
|
|
14
|
+
fail osparams.exception if osparams.exception
|
|
15
|
+
@done = true
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
ABILITY = Class.new do
|
|
20
|
+
include CanCan::Ability
|
|
21
|
+
|
|
22
|
+
def initialize(read: false, update: false)
|
|
23
|
+
can :read, Group if read
|
|
24
|
+
can :update, Group if update
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
setup do
|
|
29
|
+
Group.delete_all
|
|
30
|
+
Group.create!(id: 1, name: 'Group')
|
|
31
|
+
RailsOps.config.authorization_backend = 'RailsOps::AuthorizationBackend::CanCanCan'
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def test_unpermitted_read
|
|
35
|
+
ctx = RailsOps::Context.new(ability: ABILITY.new)
|
|
36
|
+
assert_raises CanCan::AccessDenied do
|
|
37
|
+
BASIC_OP.new(ctx, id: 1)
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def test_permitted_read
|
|
42
|
+
ctx = RailsOps::Context.new(ability: ABILITY.new(read: true))
|
|
43
|
+
assert_nothing_raised do
|
|
44
|
+
BASIC_OP.new(ctx, id: 1)
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
def test_unpermitted_update
|
|
49
|
+
ctx = RailsOps::Context.new(ability: ABILITY.new(read: true))
|
|
50
|
+
op = BASIC_OP.new(ctx, id: 1)
|
|
51
|
+
assert_raises CanCan::AccessDenied do
|
|
52
|
+
op.run!
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
def test_permitted_update
|
|
57
|
+
ctx = RailsOps::Context.new(ability: ABILITY.new(read: true, update: true))
|
|
58
|
+
op = BASIC_OP.new(ctx, id: 1)
|
|
59
|
+
assert_nothing_raised do
|
|
60
|
+
op.run!
|
|
61
|
+
end
|
|
62
|
+
end
|
|
63
|
+
end
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: rails_ops
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.1.
|
|
4
|
+
version: 1.1.22
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Sitrox
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2021-
|
|
11
|
+
date: 2021-11-01 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: bundler
|
|
@@ -52,6 +52,20 @@ dependencies:
|
|
|
52
52
|
- - ">="
|
|
53
53
|
- !ruby/object:Gem::Version
|
|
54
54
|
version: '0'
|
|
55
|
+
- !ruby/object:Gem::Dependency
|
|
56
|
+
name: cancancan
|
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
|
58
|
+
requirements:
|
|
59
|
+
- - ">="
|
|
60
|
+
- !ruby/object:Gem::Version
|
|
61
|
+
version: '0'
|
|
62
|
+
type: :development
|
|
63
|
+
prerelease: false
|
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
65
|
+
requirements:
|
|
66
|
+
- - ">="
|
|
67
|
+
- !ruby/object:Gem::Version
|
|
68
|
+
version: '0'
|
|
55
69
|
- !ruby/object:Gem::Dependency
|
|
56
70
|
name: rubocop
|
|
57
71
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -148,10 +162,10 @@ executables: []
|
|
|
148
162
|
extensions: []
|
|
149
163
|
extra_rdoc_files: []
|
|
150
164
|
files:
|
|
165
|
+
- ".github/workflows/ruby.yml"
|
|
151
166
|
- ".gitignore"
|
|
152
167
|
- ".releaser_config"
|
|
153
168
|
- ".rubocop.yml"
|
|
154
|
-
- ".travis.yml"
|
|
155
169
|
- CHANGELOG.md
|
|
156
170
|
- Gemfile
|
|
157
171
|
- LICENSE
|
|
@@ -223,6 +237,7 @@ files:
|
|
|
223
237
|
- test/dummy/app/models/application_record.rb
|
|
224
238
|
- test/dummy/app/models/concerns/.keep
|
|
225
239
|
- test/dummy/app/models/group.rb
|
|
240
|
+
- test/dummy/app/models/user.rb
|
|
226
241
|
- test/dummy/app/views/layouts/application.html.erb
|
|
227
242
|
- test/dummy/app/views/layouts/mailer.html.erb
|
|
228
243
|
- test/dummy/app/views/layouts/mailer.text.erb
|
|
@@ -273,6 +288,8 @@ files:
|
|
|
273
288
|
- test/unit/rails_ops/operation/model/load_test.rb
|
|
274
289
|
- test/unit/rails_ops/operation/model/update_test.rb
|
|
275
290
|
- test/unit/rails_ops/operation/model_test.rb
|
|
291
|
+
- test/unit/rails_ops/operation/update_auth_test.rb
|
|
292
|
+
- test/unit/rails_ops/operation/update_lazy_auth_test.rb
|
|
276
293
|
- test/unit/rails_ops/operation_test.rb
|
|
277
294
|
homepage:
|
|
278
295
|
licenses: []
|
|
@@ -292,7 +309,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
292
309
|
- !ruby/object:Gem::Version
|
|
293
310
|
version: '0'
|
|
294
311
|
requirements: []
|
|
295
|
-
rubygems_version: 3.
|
|
312
|
+
rubygems_version: 3.2.22
|
|
296
313
|
signing_key:
|
|
297
314
|
specification_version: 4
|
|
298
315
|
summary: An operations service layer for rails projects.
|
|
@@ -316,6 +333,7 @@ test_files:
|
|
|
316
333
|
- test/dummy/app/models/application_record.rb
|
|
317
334
|
- test/dummy/app/models/concerns/.keep
|
|
318
335
|
- test/dummy/app/models/group.rb
|
|
336
|
+
- test/dummy/app/models/user.rb
|
|
319
337
|
- test/dummy/app/views/layouts/application.html.erb
|
|
320
338
|
- test/dummy/app/views/layouts/mailer.html.erb
|
|
321
339
|
- test/dummy/app/views/layouts/mailer.text.erb
|
|
@@ -366,4 +384,6 @@ test_files:
|
|
|
366
384
|
- test/unit/rails_ops/operation/model/load_test.rb
|
|
367
385
|
- test/unit/rails_ops/operation/model/update_test.rb
|
|
368
386
|
- test/unit/rails_ops/operation/model_test.rb
|
|
387
|
+
- test/unit/rails_ops/operation/update_auth_test.rb
|
|
388
|
+
- test/unit/rails_ops/operation/update_lazy_auth_test.rb
|
|
369
389
|
- test/unit/rails_ops/operation_test.rb
|