hyper-operation 0.5.12 → 0.99.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.gitignore +4 -1
- data/.travis.yml +33 -0
- data/DOCS-POLICIES.md +93 -0
- data/DOCS.md +1 -1
- data/Gemfile +5 -1
- data/Gemfile.lock +379 -0
- data/README.md +10 -9
- data/Rakefile +10 -2
- data/hyper-operation.gemspec +34 -29
- data/lib/hyper-operation.rb +5 -4
- data/lib/hyper-operation/boot.rb +1 -1
- data/lib/hyper-operation/engine.rb +1 -1
- data/lib/hyper-operation/http.rb +309 -0
- data/lib/hyper-operation/railway/params_wrapper.rb +1 -0
- data/lib/hyper-operation/server_op.rb +83 -18
- data/lib/hyper-operation/transport/client_drivers.rb +71 -28
- data/lib/hyper-operation/transport/connection.rb +22 -20
- data/lib/hyper-operation/transport/hyperloop.rb +1 -1
- data/lib/hyper-operation/transport/hyperloop_controller.rb +6 -1
- data/lib/hyper-operation/transport/policy.rb +78 -13
- data/lib/hyper-operation/version.rb +1 -1
- metadata +95 -319
- data/CODE_OF_CONDUCT.md +0 -49
- data/examples/chat-app/.gitignore +0 -21
- data/examples/chat-app/Gemfile +0 -57
- data/examples/chat-app/Gemfile.lock +0 -283
- data/examples/chat-app/README.md +0 -3
- data/examples/chat-app/Rakefile +0 -6
- data/examples/chat-app/app/assets/config/manifest.js +0 -3
- data/examples/chat-app/app/assets/images/.keep +0 -0
- data/examples/chat-app/app/assets/javascripts/application.js +0 -3
- data/examples/chat-app/app/assets/javascripts/cable.js +0 -13
- data/examples/chat-app/app/assets/javascripts/channels/.keep +0 -0
- data/examples/chat-app/app/assets/stylesheets/application.css +0 -15
- data/examples/chat-app/app/channels/application_cable/channel.rb +0 -4
- data/examples/chat-app/app/channels/application_cable/connection.rb +0 -4
- data/examples/chat-app/app/controllers/application_controller.rb +0 -3
- data/examples/chat-app/app/controllers/concerns/.keep +0 -0
- data/examples/chat-app/app/controllers/home_controller.rb +0 -5
- data/examples/chat-app/app/helpers/application_helper.rb +0 -2
- data/examples/chat-app/app/hyperloop/components/app.rb +0 -11
- data/examples/chat-app/app/hyperloop/components/formatted_div.rb +0 -13
- data/examples/chat-app/app/hyperloop/components/input_box.rb +0 -29
- data/examples/chat-app/app/hyperloop/components/message.rb +0 -29
- data/examples/chat-app/app/hyperloop/components/messages.rb +0 -9
- data/examples/chat-app/app/hyperloop/components/nav.rb +0 -30
- data/examples/chat-app/app/hyperloop/operations/operations.rb +0 -56
- data/examples/chat-app/app/hyperloop/stores/message_store.rb +0 -23
- data/examples/chat-app/app/models/application_record.rb +0 -3
- data/examples/chat-app/app/models/concerns/.keep +0 -0
- data/examples/chat-app/app/models/models.rb +0 -2
- data/examples/chat-app/app/models/public/.keep +0 -0
- data/examples/chat-app/app/models/public/announcement.rb +0 -8
- data/examples/chat-app/app/policies/application_policy.rb +0 -5
- data/examples/chat-app/app/views/layouts/application.html.erb +0 -51
- data/examples/chat-app/bin/bundle +0 -3
- data/examples/chat-app/bin/rails +0 -9
- data/examples/chat-app/bin/rake +0 -9
- data/examples/chat-app/bin/setup +0 -34
- data/examples/chat-app/bin/spring +0 -17
- data/examples/chat-app/bin/update +0 -29
- data/examples/chat-app/config.ru +0 -5
- data/examples/chat-app/config/application.rb +0 -13
- data/examples/chat-app/config/boot.rb +0 -3
- data/examples/chat-app/config/cable.yml +0 -9
- data/examples/chat-app/config/database.yml +0 -25
- data/examples/chat-app/config/environment.rb +0 -5
- data/examples/chat-app/config/environments/development.rb +0 -56
- data/examples/chat-app/config/environments/production.rb +0 -86
- data/examples/chat-app/config/environments/test.rb +0 -42
- data/examples/chat-app/config/initializers/application_controller_renderer.rb +0 -6
- data/examples/chat-app/config/initializers/assets.rb +0 -11
- data/examples/chat-app/config/initializers/backtrace_silencers.rb +0 -7
- data/examples/chat-app/config/initializers/cookies_serializer.rb +0 -5
- data/examples/chat-app/config/initializers/filter_parameter_logging.rb +0 -4
- data/examples/chat-app/config/initializers/hyperloop.rb +0 -4
- data/examples/chat-app/config/initializers/inflections.rb +0 -16
- data/examples/chat-app/config/initializers/mime_types.rb +0 -4
- data/examples/chat-app/config/initializers/new_framework_defaults.rb +0 -24
- data/examples/chat-app/config/initializers/session_store.rb +0 -3
- data/examples/chat-app/config/initializers/wrap_parameters.rb +0 -14
- data/examples/chat-app/config/locales/en.yml +0 -23
- data/examples/chat-app/config/puma.rb +0 -47
- data/examples/chat-app/config/routes.rb +0 -5
- data/examples/chat-app/config/secrets.yml +0 -22
- data/examples/chat-app/config/spring.rb +0 -6
- data/examples/chat-app/db/seeds.rb +0 -7
- data/examples/chat-app/lib/assets/.keep +0 -0
- data/examples/chat-app/lib/tasks/.keep +0 -0
- data/examples/chat-app/log/.keep +0 -0
- data/examples/chat-app/public/404.html +0 -67
- data/examples/chat-app/public/422.html +0 -67
- data/examples/chat-app/public/500.html +0 -66
- data/examples/chat-app/public/apple-touch-icon-precomposed.png +0 -0
- data/examples/chat-app/public/apple-touch-icon.png +0 -0
- data/examples/chat-app/public/favicon.ico +0 -0
- data/examples/chat-app/public/robots.txt +0 -5
- data/examples/chat-app/test/controllers/.keep +0 -0
- data/examples/chat-app/test/fixtures/.keep +0 -0
- data/examples/chat-app/test/fixtures/files/.keep +0 -0
- data/examples/chat-app/test/helpers/.keep +0 -0
- data/examples/chat-app/test/integration/.keep +0 -0
- data/examples/chat-app/test/mailers/.keep +0 -0
- data/examples/chat-app/test/models/.keep +0 -0
- data/examples/chat-app/test/test_helper.rb +0 -10
- data/examples/chat-app/tmp/.keep +0 -0
- data/examples/chat-app/vendor/assets/javascripts/.keep +0 -0
- data/examples/chat-app/vendor/assets/stylesheets/.keep +0 -0
- data/examples/five-letter-word-game/.gitignore +0 -21
- data/examples/five-letter-word-game/Gemfile +0 -62
- data/examples/five-letter-word-game/Gemfile.lock +0 -291
- data/examples/five-letter-word-game/README.md +0 -24
- data/examples/five-letter-word-game/Rakefile +0 -6
- data/examples/five-letter-word-game/app/assets/config/manifest.js +0 -3
- data/examples/five-letter-word-game/app/assets/images/.keep +0 -0
- data/examples/five-letter-word-game/app/assets/javascripts/application.js +0 -4
- data/examples/five-letter-word-game/app/assets/javascripts/cable.js +0 -13
- data/examples/five-letter-word-game/app/assets/javascripts/channels/.keep +0 -0
- data/examples/five-letter-word-game/app/assets/stylesheets/application.css +0 -15
- data/examples/five-letter-word-game/app/channels/application_cable/channel.rb +0 -4
- data/examples/five-letter-word-game/app/channels/application_cable/connection.rb +0 -4
- data/examples/five-letter-word-game/app/controllers/application_controller.rb +0 -14
- data/examples/five-letter-word-game/app/controllers/concerns/.keep +0 -0
- data/examples/five-letter-word-game/app/controllers/home_controller.rb +0 -5
- data/examples/five-letter-word-game/app/helpers/application_helper.rb +0 -2
- data/examples/five-letter-word-game/app/hyperloop/components/app.rb +0 -65
- data/examples/five-letter-word-game/app/hyperloop/components/guesses.rb +0 -8
- data/examples/five-letter-word-game/app/hyperloop/components/input_word.rb +0 -13
- data/examples/five-letter-word-game/app/hyperloop/models/user.rb +0 -27
- data/examples/five-letter-word-game/app/hyperloop/operations/ops.rb +0 -115
- data/examples/five-letter-word-game/app/hyperloop/stores/store.rb +0 -120
- data/examples/five-letter-word-game/app/jobs/application_job.rb +0 -2
- data/examples/five-letter-word-game/app/mailers/application_mailer.rb +0 -4
- data/examples/five-letter-word-game/app/models/application_record.rb +0 -3
- data/examples/five-letter-word-game/app/models/concerns/.keep +0 -0
- data/examples/five-letter-word-game/app/policies/hyperloop/application_policy.rb +0 -3
- data/examples/five-letter-word-game/app/policies/user_policy.rb +0 -4
- data/examples/five-letter-word-game/app/views/layouts/application.html.erb +0 -14
- data/examples/five-letter-word-game/app/views/layouts/mailer.html.erb +0 -13
- data/examples/five-letter-word-game/app/views/layouts/mailer.text.erb +0 -1
- data/examples/five-letter-word-game/bin/bundle +0 -3
- data/examples/five-letter-word-game/bin/rails +0 -9
- data/examples/five-letter-word-game/bin/rake +0 -9
- data/examples/five-letter-word-game/bin/setup +0 -34
- data/examples/five-letter-word-game/bin/spring +0 -17
- data/examples/five-letter-word-game/bin/update +0 -29
- data/examples/five-letter-word-game/config.ru +0 -5
- data/examples/five-letter-word-game/config/application.rb +0 -12
- data/examples/five-letter-word-game/config/boot.rb +0 -3
- data/examples/five-letter-word-game/config/cable.yml +0 -9
- data/examples/five-letter-word-game/config/database.yml +0 -46
- data/examples/five-letter-word-game/config/environment.rb +0 -5
- data/examples/five-letter-word-game/config/environments/development.rb +0 -56
- data/examples/five-letter-word-game/config/environments/production.rb +0 -86
- data/examples/five-letter-word-game/config/environments/test.rb +0 -42
- data/examples/five-letter-word-game/config/initializers/application_controller_renderer.rb +0 -6
- data/examples/five-letter-word-game/config/initializers/assets.rb +0 -15
- data/examples/five-letter-word-game/config/initializers/backtrace_silencers.rb +0 -7
- data/examples/five-letter-word-game/config/initializers/cookies_serializer.rb +0 -5
- data/examples/five-letter-word-game/config/initializers/filter_parameter_logging.rb +0 -4
- data/examples/five-letter-word-game/config/initializers/hyperloop.rb +0 -19
- data/examples/five-letter-word-game/config/initializers/inflections.rb +0 -16
- data/examples/five-letter-word-game/config/initializers/mime_types.rb +0 -4
- data/examples/five-letter-word-game/config/initializers/new_framework_defaults.rb +0 -24
- data/examples/five-letter-word-game/config/initializers/session_store.rb +0 -3
- data/examples/five-letter-word-game/config/initializers/wrap_parameters.rb +0 -14
- data/examples/five-letter-word-game/config/locales/en.yml +0 -23
- data/examples/five-letter-word-game/config/puma.rb +0 -47
- data/examples/five-letter-word-game/config/routes.rb +0 -5
- data/examples/five-letter-word-game/config/secrets.yml +0 -22
- data/examples/five-letter-word-game/config/spring.rb +0 -6
- data/examples/five-letter-word-game/db/schema.rb +0 -28
- data/examples/five-letter-word-game/db/seeds.rb +0 -7
- data/examples/five-letter-word-game/lib/assets/.keep +0 -0
- data/examples/five-letter-word-game/lib/tasks/.keep +0 -0
- data/examples/five-letter-word-game/log/.keep +0 -0
- data/examples/five-letter-word-game/public/404.html +0 -67
- data/examples/five-letter-word-game/public/422.html +0 -67
- data/examples/five-letter-word-game/public/500.html +0 -66
- data/examples/five-letter-word-game/public/apple-touch-icon-precomposed.png +0 -0
- data/examples/five-letter-word-game/public/apple-touch-icon.png +0 -0
- data/examples/five-letter-word-game/public/favicon.ico +0 -0
- data/examples/five-letter-word-game/public/robots.txt +0 -5
- data/examples/five-letter-word-game/test/controllers/.keep +0 -0
- data/examples/five-letter-word-game/test/fixtures/.keep +0 -0
- data/examples/five-letter-word-game/test/fixtures/files/.keep +0 -0
- data/examples/five-letter-word-game/test/helpers/.keep +0 -0
- data/examples/five-letter-word-game/test/integration/.keep +0 -0
- data/examples/five-letter-word-game/test/mailers/.keep +0 -0
- data/examples/five-letter-word-game/test/models/.keep +0 -0
- data/examples/five-letter-word-game/test/test_helper.rb +0 -10
- data/examples/five-letter-word-game/tmp/.keep +0 -0
- data/examples/five-letter-word-game/vendor/assets/javascripts/.keep +0 -0
- data/examples/five-letter-word-game/vendor/assets/stylesheets/.keep +0 -0
- data/examples/smoke_test/.gitignore +0 -21
- data/examples/smoke_test/Gemfile +0 -59
- data/examples/smoke_test/Gemfile.lock +0 -289
- data/examples/smoke_test/README.md +0 -24
- data/examples/smoke_test/Rakefile +0 -6
- data/examples/smoke_test/app/assets/config/manifest.js +0 -3
- data/examples/smoke_test/app/assets/images/.keep +0 -0
- data/examples/smoke_test/app/assets/javascripts/application.js +0 -15
- data/examples/smoke_test/app/assets/javascripts/cable.js +0 -13
- data/examples/smoke_test/app/assets/javascripts/channels/.keep +0 -0
- data/examples/smoke_test/app/assets/stylesheets/application.css +0 -15
- data/examples/smoke_test/app/channels/application_cable/channel.rb +0 -4
- data/examples/smoke_test/app/channels/application_cable/connection.rb +0 -4
- data/examples/smoke_test/app/controllers/app_controller.rb +0 -5
- data/examples/smoke_test/app/controllers/application_controller.rb +0 -3
- data/examples/smoke_test/app/helpers/application_helper.rb +0 -2
- data/examples/smoke_test/app/hyperloop/components/hello.rb +0 -25
- data/examples/smoke_test/app/hyperloop/operations/operations/nested_send_to_all.rb +0 -7
- data/examples/smoke_test/app/hyperloop/operations/send_to_all.rb +0 -6
- data/examples/smoke_test/app/hyperloop/stores/messages.rb +0 -4
- data/examples/smoke_test/app/jobs/application_job.rb +0 -2
- data/examples/smoke_test/app/mailers/application_mailer.rb +0 -4
- data/examples/smoke_test/app/models/application_record.rb +0 -3
- data/examples/smoke_test/app/models/concerns/.keep +0 -0
- data/examples/smoke_test/app/policies/application_policy.rb +0 -8
- data/examples/smoke_test/app/views/layouts/application.html.erb +0 -14
- data/examples/smoke_test/app/views/layouts/mailer.html.erb +0 -13
- data/examples/smoke_test/app/views/layouts/mailer.text.erb +0 -1
- data/examples/smoke_test/bin/bundle +0 -3
- data/examples/smoke_test/bin/rails +0 -9
- data/examples/smoke_test/bin/rake +0 -9
- data/examples/smoke_test/bin/setup +0 -34
- data/examples/smoke_test/bin/spring +0 -17
- data/examples/smoke_test/bin/update +0 -29
- data/examples/smoke_test/config.ru +0 -5
- data/examples/smoke_test/config/application.rb +0 -15
- data/examples/smoke_test/config/boot.rb +0 -3
- data/examples/smoke_test/config/cable.yml +0 -9
- data/examples/smoke_test/config/database.yml +0 -25
- data/examples/smoke_test/config/environment.rb +0 -5
- data/examples/smoke_test/config/environments/development.rb +0 -54
- data/examples/smoke_test/config/environments/production.rb +0 -86
- data/examples/smoke_test/config/environments/test.rb +0 -42
- data/examples/smoke_test/config/initializers/application_controller_renderer.rb +0 -6
- data/examples/smoke_test/config/initializers/assets.rb +0 -11
- data/examples/smoke_test/config/initializers/backtrace_silencers.rb +0 -7
- data/examples/smoke_test/config/initializers/cookies_serializer.rb +0 -5
- data/examples/smoke_test/config/initializers/filter_parameter_logging.rb +0 -4
- data/examples/smoke_test/config/initializers/hyperloop.rb +0 -32
- data/examples/smoke_test/config/initializers/inflections.rb +0 -16
- data/examples/smoke_test/config/initializers/mime_types.rb +0 -4
- data/examples/smoke_test/config/initializers/new_framework_defaults.rb +0 -24
- data/examples/smoke_test/config/initializers/session_store.rb +0 -3
- data/examples/smoke_test/config/initializers/wrap_parameters.rb +0 -14
- data/examples/smoke_test/config/locales/en.yml +0 -23
- data/examples/smoke_test/config/puma.rb +0 -47
- data/examples/smoke_test/config/routes.rb +0 -5
- data/examples/smoke_test/config/secrets.yml +0 -22
- data/examples/smoke_test/config/spring.rb +0 -6
- data/examples/smoke_test/db/seeds.rb +0 -7
- data/examples/smoke_test/lib/assets/.keep +0 -0
- data/examples/smoke_test/lib/tasks/.keep +0 -0
- data/examples/smoke_test/log/.keep +0 -0
- data/examples/smoke_test/public/404.html +0 -67
- data/examples/smoke_test/public/422.html +0 -67
- data/examples/smoke_test/public/500.html +0 -66
- data/examples/smoke_test/public/apple-touch-icon-precomposed.png +0 -0
- data/examples/smoke_test/public/apple-touch-icon.png +0 -0
- data/examples/smoke_test/public/favicon.ico +0 -0
- data/examples/smoke_test/public/robots.txt +0 -5
- data/examples/smoke_test/test/controllers/.keep +0 -0
- data/examples/smoke_test/test/fixtures/.keep +0 -0
- data/examples/smoke_test/test/fixtures/files/.keep +0 -0
- data/examples/smoke_test/test/helpers/.keep +0 -0
- data/examples/smoke_test/test/integration/.keep +0 -0
- data/examples/smoke_test/test/mailers/.keep +0 -0
- data/examples/smoke_test/test/models/.keep +0 -0
- data/examples/smoke_test/test/test_helper.rb +0 -10
- data/examples/smoke_test/tmp/.keep +0 -0
- data/examples/smoke_test/vendor/assets/javascripts/.keep +0 -0
- data/examples/smoke_test/vendor/assets/stylesheets/.keep +0 -0
- data/lib/hyper-operation/call_by_class_name.rb +0 -60
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 8c7fa9d96880d409b3869de5ce0cde0ad9e92977cf76e7987ac508fbd3c724ba
|
4
|
+
data.tar.gz: e9a5b22277beb20b54dfedc09876ac45b65892557b48dd5e436318c93b73a32d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a822149b518d86b889536971f9c0976b2b69aa85ba52b26053f3c4c661ff54f820a213440e77bbff1e6028df64589b2a8618d43d20b5bb869045e57f567bf323
|
7
|
+
data.tar.gz: 91791060f154b31dc31fb0223e9b42fbed20ad53cce9d1b2e148ce83eafb0c5ce693c22d56b4ca7f333b8901bac0dfee39e06c15af799f440114ac7005b06de1
|
data/.gitignore
CHANGED
@@ -5,6 +5,8 @@ capybara-*.html
|
|
5
5
|
/tmp
|
6
6
|
/db/*.sqlite3
|
7
7
|
/db/*.sqlite3-journal
|
8
|
+
/spec/test_app/db/*.sqlite3
|
9
|
+
/spec/test_app/db/*.sqlite3-journal
|
8
10
|
/public/system
|
9
11
|
/coverage/
|
10
12
|
/spec/tmp
|
@@ -49,4 +51,5 @@ bower.json
|
|
49
51
|
*.gem
|
50
52
|
|
51
53
|
.idea
|
52
|
-
|
54
|
+
.vscode
|
55
|
+
*.iml
|
data/.travis.yml
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
dist: trusty
|
2
|
+
language: ruby
|
3
|
+
cache: bundler
|
4
|
+
rvm:
|
5
|
+
- 2.4.4
|
6
|
+
- 2.5.1
|
7
|
+
- ruby-head
|
8
|
+
services:
|
9
|
+
- mysql
|
10
|
+
env:
|
11
|
+
- DRIVER=google-chrome TZ=Europe/Berlin
|
12
|
+
matrix:
|
13
|
+
fast_finish: true
|
14
|
+
allow_failures:
|
15
|
+
- rvm: ruby-head
|
16
|
+
before_install:
|
17
|
+
- if [[ "$DRIVER" == "google-chrome" ]]; then wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | sudo apt-key add -; fi
|
18
|
+
- if [[ "$DRIVER" == "google-chrome" ]]; then echo "deb http://dl.google.com/linux/chrome/deb/ stable main" | sudo tee /etc/apt/sources.list.d/google-chrome.list; fi
|
19
|
+
- if [[ "$DRIVER" == "google-chrome" ]]; then sudo apt-get update -qq && sudo apt-get install -qq -y google-chrome-stable; fi
|
20
|
+
- gem install bundler
|
21
|
+
before_script:
|
22
|
+
- cd spec/test_app
|
23
|
+
- bundle install --jobs=3 --retry=3
|
24
|
+
- bundle exec rails db:setup
|
25
|
+
- cd ../../
|
26
|
+
- if [[ "$DRIVER" == "google-chrome" ]]; then bundle exec chromedriver-update; fi
|
27
|
+
- if [[ "$DRIVER" == "google-chrome" ]]; then ls -lR ~/.chromedriver-helper/; fi
|
28
|
+
- if [[ "$DRIVER" == "google-chrome" ]]; then bundle exec chromedriver --version; fi
|
29
|
+
- if [[ "$DRIVER" == "google-chrome" ]]; then google-chrome --version; fi
|
30
|
+
- if [[ "$DRIVER" == "google-chrome" ]]; then which google-chrome; fi
|
31
|
+
script: bundle exec rspec
|
32
|
+
gemfile:
|
33
|
+
- gemfiles/opal_0_11_react-rails_2_4.gemfile
|
data/DOCS-POLICIES.md
CHANGED
@@ -407,6 +407,99 @@ class MessagePolicy
|
|
407
407
|
end
|
408
408
|
```
|
409
409
|
|
410
|
+
## Regulating Scopes
|
411
|
+
|
412
|
+
Consider the following expression (evaluated on the client)
|
413
|
+
|
414
|
+
```ruby
|
415
|
+
Order.for_vip_customers.count
|
416
|
+
```
|
417
|
+
|
418
|
+
Even though the policy system will prevent us from looking into the actual attributes of any record, a malicioius hacker can find private information about our data if the above expression is not secured. Moreover a DOS attack could be formed by repeatedly attempting to perform a variant of `Order.all`.
|
419
|
+
|
420
|
+
To prevent this scopes and relationships can also be regulated. A scope and relationship regulation is a proc that will return either a truthy or falsy value or calls the `denied!` method. The proc is evaluated in the context of the relationship object, and the `acting_user` method is available for the proc's use in making decisions.
|
421
|
+
|
422
|
+
All the scopes in a chain are evaluated together, and permission is granted or denied as follows:
|
423
|
+
|
424
|
+
+ If *any* of the regulations in a chain of scopes calls `denied!` then the remote request is aborted;
|
425
|
+
+ If *any* of the regulations in a chain of scopes returns a truthy value then access is granted to the entire chain;
|
426
|
+
+ If *none* of the regulations in a chain of scopes returns a truthy value then the request is aborted.
|
427
|
+
|
428
|
+
Example:
|
429
|
+
|
430
|
+
```ruby
|
431
|
+
class Order < ApplicationRecord
|
432
|
+
regulate_scope(:for_vip_customers) { denied! unless acting_user.admin? }
|
433
|
+
regulate_scope(:active) { acting_user.admin? }
|
434
|
+
end
|
435
|
+
|
436
|
+
class User < ApplicationRecord
|
437
|
+
regulate_relationship(:orders) { self == acting_user }
|
438
|
+
end
|
439
|
+
|
440
|
+
# in component code
|
441
|
+
|
442
|
+
user.orders.count # valid if user is the acting user because the orders regulation returned true
|
443
|
+
# but will raise error if acting_user is not == user
|
444
|
+
user.orders.active.count # valid if user is the acting user or if current user is an administrator
|
445
|
+
user.orders.for_vip_customers # fails unless acting user is an admin
|
446
|
+
```
|
447
|
+
|
448
|
+
By default all relationships and scopes (including `all` and `unscoped` have a regulation that returns nil, so unless you explicitly provide a regulation that returns true, the client can not access any scopes.
|
449
|
+
|
450
|
+
There are some short hand ways to define regulations as well:
|
451
|
+
|
452
|
+
#### Constant Regulations
|
453
|
+
|
454
|
+
If the regulation always does the same thing you can specify what to do without the block:
|
455
|
+
|
456
|
+
```ruby
|
457
|
+
regulate_scope my_scope: :always_allow # any truthy value works
|
458
|
+
regulate_scope my_scope: :denied! # :deny or :denied work as well
|
459
|
+
regulate_relationship many_of_those: :denied! # works the same on relationships
|
460
|
+
```
|
461
|
+
|
462
|
+
Always denying a regulation effectively makes it inaccessible except on the server.
|
463
|
+
|
464
|
+
Likewise be careful of always returning true for a scope, as this means that a hacker only needs
|
465
|
+
to include this scope in the chain to gain access to the chain. So just make sure that scopes that return
|
466
|
+
true, narrow the scope down to something you would not mind anybody seeing.
|
467
|
+
|
468
|
+
For development you can easily access everything (except regulations that explicitly invoke denied!) simply by doing this:
|
469
|
+
|
470
|
+
```ruby
|
471
|
+
class ApplicationRecord < ActiveRecord::Base
|
472
|
+
regulate_scope all: :always_allow if Rails.env.development?
|
473
|
+
regulate_scope unscoped: :always_allow if Rails.env.development?
|
474
|
+
end
|
475
|
+
```
|
476
|
+
|
477
|
+
#### Regulations directly on scopes and has_many relationships
|
478
|
+
|
479
|
+
You can also directly add the regulation where you declare the scope or relationship using the `regulate:` option.
|
480
|
+
|
481
|
+
```ruby
|
482
|
+
# here is a handy scope to add to ApplicationRecord that you can attach to
|
483
|
+
# any scope chain to give admin's full access
|
484
|
+
scope :admin, ->() {}, regulate: -> () { acting_user.admin? || denied! }
|
485
|
+
|
486
|
+
# customers can always see their orders, otherwise we return nil meaning "don't know yet"
|
487
|
+
has_many :orders, regulate: -> () { acting_user == self }
|
488
|
+
```
|
489
|
+
|
490
|
+
## Regulating server_method and finder_method methods
|
491
|
+
|
492
|
+
The server or finder method proc will be executed in the context of the appropriate object (a record for server_method, and a relationship collection for finder_method.) Attached to this object will be the current `acting_user` method, and a `denied!` method.
|
493
|
+
|
494
|
+
You can use these methods to restrict access to server and finder methods.
|
495
|
+
|
496
|
+
```ruby
|
497
|
+
server_method :unit_cost do
|
498
|
+
denied! unless acting_user.admin? # only admin's can see this
|
499
|
+
# continue on calculating the unit cost
|
500
|
+
end
|
501
|
+
```
|
502
|
+
|
410
503
|
## Browser Initiated Change policies
|
411
504
|
|
412
505
|
To allow code in the browser to create, update or destroy a model, there must be a change access policy defined for that operation.
|
data/DOCS.md
CHANGED
data/Gemfile
CHANGED
@@ -1,3 +1,7 @@
|
|
1
1
|
source 'https://rubygems.org'
|
2
|
-
|
2
|
+
#gem "opal-jquery", git: "https://github.com/opal/opal-jquery.git", branch: "master"
|
3
|
+
gem 'hyper-spec', path: '../hyper-spec'
|
4
|
+
gem 'hyperloop-config', path: '../hyperloop-config'
|
5
|
+
gem 'hyper-store', path: '../hyper-store'
|
6
|
+
gem 'hyper-component', path: '../hyper-component'
|
3
7
|
gemspec
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,379 @@
|
|
1
|
+
GIT
|
2
|
+
remote: https://github.com/opal/opal-jquery.git
|
3
|
+
revision: 6249dfaf406ecd7199079b4f4d9dc67cfdf4d602
|
4
|
+
branch: master
|
5
|
+
specs:
|
6
|
+
opal-jquery (0.4.3)
|
7
|
+
opal (>= 0.10.0, < 0.12.0)
|
8
|
+
|
9
|
+
PATH
|
10
|
+
remote: ../hyper-component
|
11
|
+
specs:
|
12
|
+
hyper-component (1.0.0.lap28)
|
13
|
+
hyper-store (= 1.0.0.lap28)
|
14
|
+
hyperloop-config (= 1.0.0.lap28)
|
15
|
+
libv8 (~> 6.3.0)
|
16
|
+
mini_racer (~> 0.1.15)
|
17
|
+
opal (>= 0.11.0, < 0.12.0)
|
18
|
+
opal-activesupport (~> 0.3.1)
|
19
|
+
react-rails (>= 2.4.0, < 2.5.0)
|
20
|
+
|
21
|
+
PATH
|
22
|
+
remote: ../hyper-spec
|
23
|
+
specs:
|
24
|
+
hyper-spec (1.0.0.lap28)
|
25
|
+
capybara
|
26
|
+
chromedriver-helper (= 1.2.0)
|
27
|
+
libv8 (~> 6.3.0)
|
28
|
+
method_source
|
29
|
+
mini_racer (~> 0.1.15)
|
30
|
+
opal (>= 0.11.0, < 0.12.0)
|
31
|
+
parser (>= 2.3.3.1)
|
32
|
+
pry
|
33
|
+
rspec-rails
|
34
|
+
selenium-webdriver
|
35
|
+
timecop (~> 0.8.1)
|
36
|
+
uglifier
|
37
|
+
unparser
|
38
|
+
webdrivers
|
39
|
+
|
40
|
+
PATH
|
41
|
+
remote: ../hyper-store
|
42
|
+
specs:
|
43
|
+
hyper-store (1.0.0.lap28)
|
44
|
+
hyperloop-config (= 1.0.0.lap28)
|
45
|
+
opal (>= 0.11.0, < 0.12.0)
|
46
|
+
|
47
|
+
PATH
|
48
|
+
remote: ../hyperloop-config
|
49
|
+
specs:
|
50
|
+
hyperloop-config (1.0.0.lap28)
|
51
|
+
libv8 (~> 6.3.0)
|
52
|
+
mini_racer (~> 0.1.15)
|
53
|
+
opal (>= 0.11.0, < 0.12.0)
|
54
|
+
opal-browser (~> 0.2.0)
|
55
|
+
uglifier
|
56
|
+
|
57
|
+
PATH
|
58
|
+
remote: .
|
59
|
+
specs:
|
60
|
+
hyper-operation (1.0.0.lap28)
|
61
|
+
activerecord (>= 4.0.0)
|
62
|
+
hyper-component (= 1.0.0.lap28)
|
63
|
+
mutations
|
64
|
+
opal-activesupport (~> 0.3.1)
|
65
|
+
|
66
|
+
GEM
|
67
|
+
remote: https://rubygems.org/
|
68
|
+
specs:
|
69
|
+
abstract_type (0.0.7)
|
70
|
+
actioncable (5.2.1)
|
71
|
+
actionpack (= 5.2.1)
|
72
|
+
nio4r (~> 2.0)
|
73
|
+
websocket-driver (>= 0.6.1)
|
74
|
+
actionmailer (5.2.1)
|
75
|
+
actionpack (= 5.2.1)
|
76
|
+
actionview (= 5.2.1)
|
77
|
+
activejob (= 5.2.1)
|
78
|
+
mail (~> 2.5, >= 2.5.4)
|
79
|
+
rails-dom-testing (~> 2.0)
|
80
|
+
actionpack (5.2.1)
|
81
|
+
actionview (= 5.2.1)
|
82
|
+
activesupport (= 5.2.1)
|
83
|
+
rack (~> 2.0)
|
84
|
+
rack-test (>= 0.6.3)
|
85
|
+
rails-dom-testing (~> 2.0)
|
86
|
+
rails-html-sanitizer (~> 1.0, >= 1.0.2)
|
87
|
+
actionview (5.2.1)
|
88
|
+
activesupport (= 5.2.1)
|
89
|
+
builder (~> 3.1)
|
90
|
+
erubi (~> 1.4)
|
91
|
+
rails-dom-testing (~> 2.0)
|
92
|
+
rails-html-sanitizer (~> 1.0, >= 1.0.3)
|
93
|
+
activejob (5.2.1)
|
94
|
+
activesupport (= 5.2.1)
|
95
|
+
globalid (>= 0.3.6)
|
96
|
+
activemodel (5.2.1)
|
97
|
+
activesupport (= 5.2.1)
|
98
|
+
activerecord (5.2.1)
|
99
|
+
activemodel (= 5.2.1)
|
100
|
+
activesupport (= 5.2.1)
|
101
|
+
arel (>= 9.0)
|
102
|
+
activestorage (5.2.1)
|
103
|
+
actionpack (= 5.2.1)
|
104
|
+
activerecord (= 5.2.1)
|
105
|
+
marcel (~> 0.3.1)
|
106
|
+
activesupport (5.2.1)
|
107
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
108
|
+
i18n (>= 0.7, < 2)
|
109
|
+
minitest (~> 5.1)
|
110
|
+
tzinfo (~> 1.1)
|
111
|
+
adamantium (0.2.0)
|
112
|
+
ice_nine (~> 0.11.0)
|
113
|
+
memoizable (~> 0.4.0)
|
114
|
+
addressable (2.5.2)
|
115
|
+
public_suffix (>= 2.0.2, < 4.0)
|
116
|
+
archive-zip (0.11.0)
|
117
|
+
io-like (~> 0.3.0)
|
118
|
+
arel (9.0.0)
|
119
|
+
ast (2.4.0)
|
120
|
+
babel-source (5.8.35)
|
121
|
+
babel-transpiler (0.7.0)
|
122
|
+
babel-source (>= 4.0, < 6)
|
123
|
+
execjs (~> 2.0)
|
124
|
+
builder (3.2.3)
|
125
|
+
capybara (3.8.0)
|
126
|
+
addressable
|
127
|
+
mini_mime (>= 0.1.3)
|
128
|
+
nokogiri (~> 1.8)
|
129
|
+
rack (>= 1.6.0)
|
130
|
+
rack-test (>= 0.6.3)
|
131
|
+
xpath (~> 3.1)
|
132
|
+
childprocess (0.9.0)
|
133
|
+
ffi (~> 1.0, >= 1.0.11)
|
134
|
+
chromedriver-helper (1.2.0)
|
135
|
+
archive-zip (~> 0.10)
|
136
|
+
nokogiri (~> 1.8)
|
137
|
+
coderay (1.1.2)
|
138
|
+
concord (0.1.5)
|
139
|
+
adamantium (~> 0.2.0)
|
140
|
+
equalizer (~> 0.0.9)
|
141
|
+
concurrent-ruby (1.0.5)
|
142
|
+
connection_pool (2.2.2)
|
143
|
+
cookiejar (0.3.3)
|
144
|
+
crass (1.0.4)
|
145
|
+
daemons (1.2.6)
|
146
|
+
database_cleaner (1.7.0)
|
147
|
+
diff-lcs (1.3)
|
148
|
+
em-http-request (1.1.5)
|
149
|
+
addressable (>= 2.3.4)
|
150
|
+
cookiejar (!= 0.3.1)
|
151
|
+
em-socksify (>= 0.3)
|
152
|
+
eventmachine (>= 1.0.3)
|
153
|
+
http_parser.rb (>= 0.6.0)
|
154
|
+
em-socksify (0.3.2)
|
155
|
+
eventmachine (>= 1.0.0.beta.4)
|
156
|
+
em-websocket (0.5.1)
|
157
|
+
eventmachine (>= 0.12.9)
|
158
|
+
http_parser.rb (~> 0.6.0)
|
159
|
+
equalizer (0.0.11)
|
160
|
+
erubi (1.7.1)
|
161
|
+
eventmachine (1.2.7)
|
162
|
+
execjs (2.7.0)
|
163
|
+
ffi (1.9.25)
|
164
|
+
globalid (0.4.1)
|
165
|
+
activesupport (>= 4.2.0)
|
166
|
+
hike (1.2.3)
|
167
|
+
http_parser.rb (0.6.0)
|
168
|
+
httpclient (2.8.3)
|
169
|
+
i18n (1.1.0)
|
170
|
+
concurrent-ruby (~> 1.0)
|
171
|
+
ice_nine (0.11.2)
|
172
|
+
interception (0.5)
|
173
|
+
io-like (0.3.0)
|
174
|
+
jquery-rails (4.3.3)
|
175
|
+
rails-dom-testing (>= 1, < 3)
|
176
|
+
railties (>= 4.2.0)
|
177
|
+
thor (>= 0.14, < 2.0)
|
178
|
+
libv8 (6.3.292.48.1)
|
179
|
+
loofah (2.2.2)
|
180
|
+
crass (~> 1.0.2)
|
181
|
+
nokogiri (>= 1.5.9)
|
182
|
+
mail (2.7.0)
|
183
|
+
mini_mime (>= 0.1.1)
|
184
|
+
marcel (0.3.2)
|
185
|
+
mimemagic (~> 0.3.2)
|
186
|
+
memoizable (0.4.2)
|
187
|
+
thread_safe (~> 0.3, >= 0.3.1)
|
188
|
+
method_source (0.9.0)
|
189
|
+
mimemagic (0.3.2)
|
190
|
+
mini_mime (1.0.1)
|
191
|
+
mini_portile2 (2.3.0)
|
192
|
+
mini_racer (0.1.15)
|
193
|
+
libv8 (~> 6.3)
|
194
|
+
minitest (5.11.3)
|
195
|
+
multi_json (1.13.1)
|
196
|
+
mutations (0.8.3)
|
197
|
+
activesupport
|
198
|
+
mysql2 (0.5.2)
|
199
|
+
nio4r (2.3.1)
|
200
|
+
nokogiri (1.8.4)
|
201
|
+
mini_portile2 (~> 2.3.0)
|
202
|
+
opal (0.11.3)
|
203
|
+
ast (>= 2.3.0)
|
204
|
+
hike (~> 1.2)
|
205
|
+
parser (= 2.3.3.1)
|
206
|
+
sourcemap (~> 0.1.0)
|
207
|
+
opal-activesupport (0.3.1)
|
208
|
+
opal (>= 0.5.0, < 1.0.0)
|
209
|
+
opal-browser (0.2.0)
|
210
|
+
opal
|
211
|
+
paggio
|
212
|
+
opal-rails (0.9.5)
|
213
|
+
jquery-rails
|
214
|
+
opal (>= 0.11.0, < 0.12)
|
215
|
+
opal-activesupport (>= 0.0.5)
|
216
|
+
opal-jquery (~> 0.4.0)
|
217
|
+
opal-sprockets (~> 0.4.2)
|
218
|
+
rails (>= 4.1, < 6.0)
|
219
|
+
sprockets-rails (>= 2.3.3, < 4.0)
|
220
|
+
opal-sprockets (0.4.2.0.11.0.3.1)
|
221
|
+
opal (~> 0.11.0)
|
222
|
+
sprockets (~> 3.1)
|
223
|
+
tilt (>= 1.4)
|
224
|
+
paggio (0.2.6)
|
225
|
+
parser (2.3.3.1)
|
226
|
+
ast (~> 2.2)
|
227
|
+
procto (0.0.3)
|
228
|
+
pry (0.11.3)
|
229
|
+
coderay (~> 1.1.0)
|
230
|
+
method_source (~> 0.9.0)
|
231
|
+
pry-rescue (1.4.5)
|
232
|
+
interception (>= 0.5)
|
233
|
+
pry
|
234
|
+
public_suffix (3.0.3)
|
235
|
+
puma (3.12.0)
|
236
|
+
pusher (1.3.1)
|
237
|
+
httpclient (~> 2.7)
|
238
|
+
multi_json (~> 1.0)
|
239
|
+
pusher-signature (~> 0.1.8)
|
240
|
+
pusher-fake (1.10.0)
|
241
|
+
em-http-request (~> 1.1)
|
242
|
+
em-websocket (~> 0.5)
|
243
|
+
multi_json (~> 1.6)
|
244
|
+
thin (~> 1.5)
|
245
|
+
pusher-signature (0.1.8)
|
246
|
+
rack (2.0.5)
|
247
|
+
rack-test (1.1.0)
|
248
|
+
rack (>= 1.0, < 3)
|
249
|
+
rails (5.2.1)
|
250
|
+
actioncable (= 5.2.1)
|
251
|
+
actionmailer (= 5.2.1)
|
252
|
+
actionpack (= 5.2.1)
|
253
|
+
actionview (= 5.2.1)
|
254
|
+
activejob (= 5.2.1)
|
255
|
+
activemodel (= 5.2.1)
|
256
|
+
activerecord (= 5.2.1)
|
257
|
+
activestorage (= 5.2.1)
|
258
|
+
activesupport (= 5.2.1)
|
259
|
+
bundler (>= 1.3.0)
|
260
|
+
railties (= 5.2.1)
|
261
|
+
sprockets-rails (>= 2.0.0)
|
262
|
+
rails-dom-testing (2.0.3)
|
263
|
+
activesupport (>= 4.2.0)
|
264
|
+
nokogiri (>= 1.6)
|
265
|
+
rails-html-sanitizer (1.0.4)
|
266
|
+
loofah (~> 2.2, >= 2.2.2)
|
267
|
+
railties (5.2.1)
|
268
|
+
actionpack (= 5.2.1)
|
269
|
+
activesupport (= 5.2.1)
|
270
|
+
method_source
|
271
|
+
rake (>= 0.8.7)
|
272
|
+
thor (>= 0.19.0, < 2.0)
|
273
|
+
rake (12.3.1)
|
274
|
+
react-rails (2.4.7)
|
275
|
+
babel-transpiler (>= 0.7.0)
|
276
|
+
connection_pool
|
277
|
+
execjs
|
278
|
+
railties (>= 3.2)
|
279
|
+
tilt
|
280
|
+
rspec (3.8.0)
|
281
|
+
rspec-core (~> 3.8.0)
|
282
|
+
rspec-expectations (~> 3.8.0)
|
283
|
+
rspec-mocks (~> 3.8.0)
|
284
|
+
rspec-core (3.8.0)
|
285
|
+
rspec-support (~> 3.8.0)
|
286
|
+
rspec-expectations (3.8.1)
|
287
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
288
|
+
rspec-support (~> 3.8.0)
|
289
|
+
rspec-mocks (3.8.0)
|
290
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
291
|
+
rspec-support (~> 3.8.0)
|
292
|
+
rspec-rails (3.8.0)
|
293
|
+
actionpack (>= 3.0)
|
294
|
+
activesupport (>= 3.0)
|
295
|
+
railties (>= 3.0)
|
296
|
+
rspec-core (~> 3.8.0)
|
297
|
+
rspec-expectations (~> 3.8.0)
|
298
|
+
rspec-mocks (~> 3.8.0)
|
299
|
+
rspec-support (~> 3.8.0)
|
300
|
+
rspec-steps (2.1.1)
|
301
|
+
rspec (>= 3.0, < 3.99)
|
302
|
+
rspec-support (3.8.0)
|
303
|
+
rspec-wait (0.0.9)
|
304
|
+
rspec (>= 3, < 4)
|
305
|
+
rubyzip (1.2.2)
|
306
|
+
selenium-webdriver (3.14.0)
|
307
|
+
childprocess (~> 0.5)
|
308
|
+
rubyzip (~> 1.2)
|
309
|
+
sourcemap (0.1.1)
|
310
|
+
sprockets (3.7.2)
|
311
|
+
concurrent-ruby (~> 1.0)
|
312
|
+
rack (> 1, < 3)
|
313
|
+
sprockets-rails (3.2.1)
|
314
|
+
actionpack (>= 4.0)
|
315
|
+
activesupport (>= 4.0)
|
316
|
+
sprockets (>= 3.0.0)
|
317
|
+
sqlite3 (1.3.13)
|
318
|
+
thin (1.7.2)
|
319
|
+
daemons (~> 1.0, >= 1.0.9)
|
320
|
+
eventmachine (~> 1.0, >= 1.0.4)
|
321
|
+
rack (>= 1, < 3)
|
322
|
+
thor (0.20.0)
|
323
|
+
thread_safe (0.3.6)
|
324
|
+
tilt (2.0.8)
|
325
|
+
timecop (0.8.1)
|
326
|
+
tzinfo (1.2.5)
|
327
|
+
thread_safe (~> 0.1)
|
328
|
+
uglifier (4.1.19)
|
329
|
+
execjs (>= 0.3.0, < 3)
|
330
|
+
unparser (0.2.8)
|
331
|
+
abstract_type (~> 0.0.7)
|
332
|
+
adamantium (~> 0.2.0)
|
333
|
+
concord (~> 0.1.5)
|
334
|
+
diff-lcs (~> 1.3)
|
335
|
+
equalizer (~> 0.0.9)
|
336
|
+
parser (>= 2.3.1.2, < 2.6)
|
337
|
+
procto (~> 0.0.2)
|
338
|
+
webdrivers (3.4.0)
|
339
|
+
nokogiri (~> 1.6)
|
340
|
+
rubyzip (~> 1.0)
|
341
|
+
selenium-webdriver (~> 3.0)
|
342
|
+
websocket-driver (0.7.0)
|
343
|
+
websocket-extensions (>= 0.1.0)
|
344
|
+
websocket-extensions (0.1.3)
|
345
|
+
xpath (3.1.0)
|
346
|
+
nokogiri (~> 1.8)
|
347
|
+
|
348
|
+
PLATFORMS
|
349
|
+
ruby
|
350
|
+
|
351
|
+
DEPENDENCIES
|
352
|
+
bundler
|
353
|
+
chromedriver-helper
|
354
|
+
database_cleaner
|
355
|
+
hyper-component!
|
356
|
+
hyper-operation!
|
357
|
+
hyper-spec!
|
358
|
+
hyper-store!
|
359
|
+
hyperloop-config!
|
360
|
+
mysql2
|
361
|
+
opal (>= 0.11.0, < 0.12.0)
|
362
|
+
opal-browser (~> 0.2.0)
|
363
|
+
opal-jquery!
|
364
|
+
opal-rails (~> 0.9.4)
|
365
|
+
pry-rescue
|
366
|
+
puma
|
367
|
+
pusher
|
368
|
+
pusher-fake
|
369
|
+
rails (>= 4.0.0)
|
370
|
+
rake
|
371
|
+
react-rails (>= 2.4.0, < 2.5.0)
|
372
|
+
rspec-rails
|
373
|
+
rspec-steps (~> 2.1.1)
|
374
|
+
rspec-wait
|
375
|
+
sqlite3
|
376
|
+
timecop (~> 0.8.1)
|
377
|
+
|
378
|
+
BUNDLED WITH
|
379
|
+
1.16.1
|