rails_ops 1.0.2 → 1.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA256:
3
- metadata.gz: c7a282f1eb15d57dad6975725b65767cd67154367d3990ec96360b76b317b14c
4
- data.tar.gz: a7e9d4c6d3eef2b2166b2b1685f1c6908be6e23b215e1c7a6475d6f3d69e4cf6
2
+ SHA1:
3
+ metadata.gz: '065973dd5cb31471910f1febb0abcf52d654cfba'
4
+ data.tar.gz: 533500fe5913bbb75f1629409268cd736c455ae7
5
5
  SHA512:
6
- metadata.gz: 8ddb1d73625f62c2738112b7e459dd30d76b53a0c4897e9e3a52a20f4b1294b8867b2c8d044c8a998e5b2393edb0f0b208e0224ead5a6b281f1124772128be9f
7
- data.tar.gz: 55624989107ab3de4dfd28f884f7c001172147d755f42986473ec6643f06ac868a4bf2bce4d85f8c305d25f23c35bef29a997239518b9059e3fad4d8f278a8ab
6
+ metadata.gz: c4fe791a2df0e6f23971661839e66c149940a8008e123c51bf42ce1810802944a6ccf63cc090719aaeeca842e5a8154dabdfedc9ab707c601901111c27d1a62c
7
+ data.tar.gz: b790df6bb1dcb2b74347d6e519dbac82b241d51c10e35bc72150706cb319ff4df51560bdbbd95576ca34b0f53090e5d0a5814e54e98821e8b7d19403a40cba75
data/CHANGELOG.md CHANGED
@@ -1,5 +1,26 @@
1
1
  # Change log
2
2
 
3
+ ## 1.0.3 (2019-03-18)
4
+
5
+ * Add missing imports of required third-party gems
6
+
7
+ * Add policy chain `before_model_save` for model operations
8
+
9
+ * Add policy chain `before_nested_model_ops` for model operations
10
+
11
+ * If existing, use `ActiveSupport::ParameterFilter` over
12
+ `ActionDispatch::Http::ParameterFilter` which is deprecated in Rails 6
13
+
14
+ * Fix error catching of nested model operations
15
+
16
+ * Fix error handling of sub operations
17
+
18
+ * Add `view` to operation contexts that contains the `view_context`. Only use
19
+ this for frontend operations that are always called from within a controller.
20
+
21
+ * Expose `op_context` as a view helper method. This is useful for instantiating
22
+ new (view) operations from within views and helpers.
23
+
3
24
  ## 1.0.2 (2019-01-29)
4
25
 
5
26
  * Fix mass assignment protection errors under Rails 3
data/README.md CHANGED
@@ -338,8 +338,8 @@ an appropriate exception.
338
338
 
339
339
  ### Policy chains
340
340
 
341
- As mentioned above, policies can be executed at 3 points in your operation's
342
- lifecycle. This is possible using *policy chains*:
341
+ As mentioned above, policies can be executed at various points in your
342
+ operation's lifecycle. This is possible using *policy chains*:
343
343
 
344
344
  - `:on_init`
345
345
 
@@ -351,6 +351,18 @@ lifecycle. This is possible using *policy chains*:
351
351
  Obviously this is never called if the operation is just instantiated and never
352
352
  run. This is the default chain.
353
353
 
354
+ - `:before_model_save`
355
+
356
+ This only applies to operations deriving from `RailsOps::Operation::Model` and
357
+ its descendants. Policies in this chain run after nested model operations are
358
+ performed immediately before the "main" model is saved.
359
+
360
+ - `:before_nested_model_ops`
361
+
362
+ This only applies to operations deriving from `RailsOps::Operation::Model` and
363
+ its descendants. Policies in this chain run after nested model operations are
364
+ performed before performing any nested model operations.
365
+
354
366
  - `:after_perform`
355
367
 
356
368
  Policies in this chain run immediately after the `perform` method is called.
@@ -464,6 +476,12 @@ operations. Contexts can include the following data:
464
476
  the operation context when calling an operation from a controller. This hash
465
477
  is used by {RailsOps::Mixins::Routes}.
466
478
 
479
+ - View context
480
+
481
+ If the operation has been created from within a controller, the property
482
+ `view` includes the current view context. Only use this for frontend
483
+ operations that will always be called from a controller.
484
+
467
485
  - Called via hook
468
486
 
469
487
  `called_via_hook` is a boolean indicating whether or not this operation was
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.0.2
1
+ 1.0.3
data/lib/rails_ops.rb CHANGED
@@ -1,3 +1,6 @@
1
+ require 'schemacop'
2
+ require 'request_store'
3
+
1
4
  module RailsOps
2
5
  AUTH_THREAD_STORAGE_KEY = :rails_ops_authorization_enabled
3
6
 
@@ -6,6 +6,7 @@ module RailsOps
6
6
  attribute :session
7
7
  attribute :called_via_hook
8
8
  attribute :url_options
9
+ attribute :view
9
10
 
10
11
  # For compatibility with rails < 4
11
12
  if defined?(attr_accessible)
@@ -15,6 +16,7 @@ module RailsOps
15
16
  attr_accessible :session
16
17
  attr_accessible :called_via_hook
17
18
  attr_accessible :url_options
19
+ attr_accessible :view
18
20
  end
19
21
 
20
22
  # Returns a copy of the context with the given operation added to the
@@ -26,7 +28,8 @@ module RailsOps
26
28
  session: session,
27
29
  op_chain: op_chain + [op],
28
30
  called_via_hook: false,
29
- url_options: url_options
31
+ url_options: url_options,
32
+ view: view
30
33
  )
31
34
  end
32
35
 
@@ -22,6 +22,7 @@ module RailsOps
22
22
  helper_method :model
23
23
  helper_method :op
24
24
  helper_method :op?
25
+ helper_method :op_context
25
26
 
26
27
  after_action :ensure_operation_authorize_called!
27
28
  end
@@ -99,6 +100,7 @@ module RailsOps
99
100
  context.ability = current_ability if defined?(:current_ability)
100
101
  context.session = session
101
102
  context.url_options = url_options
103
+ context.view = view_context
102
104
  context
103
105
  end
104
106
  end
@@ -171,7 +171,7 @@ module RailsOps::Mixins::Model::Nesting
171
171
  # an exception happens here.
172
172
  begin
173
173
  op.run!
174
- rescue op.validation_errors => e
174
+ rescue *op.validation_errors => e
175
175
  fail RailsOps::Exceptions::SubOpValidationFailed, e
176
176
  end
177
177
 
@@ -5,7 +5,13 @@
5
5
  module RailsOps::Mixins::Policies
6
6
  extend ActiveSupport::Concern
7
7
 
8
- POLICY_CHAIN_KEYS = [:on_init, :before_perform, :after_perform].freeze
8
+ POLICY_CHAIN_KEYS = [
9
+ :on_init,
10
+ :before_perform,
11
+ :after_perform,
12
+ :before_nested_model_ops,
13
+ :before_model_save
14
+ ].freeze
9
15
 
10
16
  included do
11
17
  class_attribute :_policy_chains
@@ -21,7 +21,7 @@ module RailsOps::Mixins::SubOps
21
21
 
22
22
  begin
23
23
  return op.run!
24
- rescue op.validation_errors => e
24
+ rescue *op.validation_errors => e
25
25
  fail RailsOps::Exceptions::SubOpValidationFailed, e
26
26
  end
27
27
  end
@@ -75,7 +75,15 @@ class RailsOps::Operation
75
75
 
76
76
  # Return a hash of parameters with all sensitive data replaced.
77
77
  def filtered_params
78
- f = ActionDispatch::Http::ParameterFilter.new(Rails.application.config.filter_parameters)
78
+ if defined?(ActiveSupport::ParameterFilter)
79
+ # Rails >= 6
80
+ cls = ActiveSupport::ParameterFilter
81
+ else
82
+ # Rails < 6
83
+ cls = ActionDispatch::Http::ParameterFilter
84
+ end
85
+
86
+ f = cls.new(Rails.application.config.filter_parameters)
79
87
  return f.filter(params)
80
88
  end
81
89
 
@@ -148,7 +148,9 @@ class RailsOps::Operation::Model < RailsOps::Operation
148
148
  # nested model operations, you should call this method instead of calling
149
149
  # `model.save!` directly.
150
150
  def save!
151
+ run_policies :before_nested_model_ops
151
152
  perform_nested_model_ops!
153
+ run_policies :before_model_save
152
154
  model.save!
153
155
  end
154
156
 
data/rails_ops.gemspec CHANGED
@@ -1,14 +1,14 @@
1
1
  # -*- encoding: utf-8 -*-
2
- # stub: rails_ops 1.0.2 ruby lib
2
+ # stub: rails_ops 1.0.3 ruby lib
3
3
 
4
4
  Gem::Specification.new do |s|
5
5
  s.name = "rails_ops".freeze
6
- s.version = "1.0.2"
6
+ s.version = "1.0.3"
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 = "2019-01-31"
11
+ s.date = "2019-03-18"
12
12
  s.files = [".gitignore".freeze, ".releaser_config".freeze, ".rubocop.yml".freeze, ".travis.yml".freeze, "CHANGELOG.md".freeze, "Gemfile".freeze, "LICENSE.txt".freeze, "README.md".freeze, "RUBY_VERSION".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/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/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/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]
13
13
  s.rubygems_version = "2.6.6".freeze
14
14
  s.summary = "An operations service layer for rails projects.".freeze
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.0.2
4
+ version: 1.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sitrox
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-01-31 00:00:00.000000000 Z
11
+ date: 2019-03-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -285,7 +285,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
285
285
  version: '0'
286
286
  requirements: []
287
287
  rubyforge_project:
288
- rubygems_version: 2.7.6
288
+ rubygems_version: 2.5.2.3
289
289
  signing_key:
290
290
  specification_version: 4
291
291
  summary: An operations service layer for rails projects.