Skip to content
This repository was archived by the owner on Oct 19, 2018. It is now read-only.

Commit 3df1ee0

Browse files
committed
closes #96
1 parent ed6fac2 commit 3df1ee0

File tree

6 files changed

+26
-17
lines changed

6 files changed

+26
-17
lines changed

Gemfile

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
source 'https://rubygems.org'
22
gem "opal-jquery", git: "https://github.com/opal/opal-jquery.git", branch: "master"
3+
gem 'hyperloop-config', path: '../hyperloop-config'
4+
gem 'hyper-operation', path: '../hyper-operation'
35
gemspec

lib/active_record_base.rb

+3-3
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ class Relation
4242
def __secure_collection_check(acting_user)
4343
return self if __synchromesh_permission_granted
4444
return self if __secure_remote_access_to_unscoped(self, acting_user).__synchromesh_permission_granted
45-
denied!
45+
Hyperloop::InternalPolicy.raise_operation_access_violation(:scoped_permission_not_granted, "Last relation: #{self}, acting_user: #{acting_user}")
4646
end
4747
end
4848
# Monkey patches and extensions to base
@@ -56,7 +56,7 @@ class << self
5656
# access protection fault.
5757

5858
def denied!
59-
Hyperloop::InternalPolicy.raise_operation_access_violation
59+
Hyperloop::InternalPolicy.raise_operation_access_violation(:scoped_denied, "#{self} regulation denies scope access. Called from #{caller_locations(1)}")
6060
end
6161

6262
# Here we set up the base `all` and `unscoped` methods. See below for more on how
@@ -275,7 +275,7 @@ def __secure_remote_access_to_find_by(_self, _acting_user, *args)
275275
end
276276

277277
def denied!
278-
Hyperloop::InternalPolicy.raise_operation_access_violation
278+
Hyperloop::InternalPolicy.raise_operation_access_violation(:scoped_denied, "#{self.class} regulation denies scope access. Called from #{caller_locations(1)}")
279279
end
280280

281281
# call do_not_synchronize to block synchronization of a model

lib/reactive_record/active_record/reactive_record/operations.rb

+3-2
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ def self.deserialize_response(response)
5050
end
5151
# fetch queued up records from the server
5252
# subclass of ControllerOp so we can pass the controller
53-
# along to on_fetch_error
53+
# along to on_error
5454
class Fetch < Base
5555
param :acting_user, nils: true
5656
param models: []
@@ -65,7 +65,8 @@ class Fetch < Base
6565
]
6666
end
6767
failed do |e|
68-
ReactiveRecord.on_fetch_error(e, params.to_h)
68+
# AccessViolations are already sent to on_error
69+
Hyperloop.on_error(e, :fetch_error, params.to_h) unless e.is_a? Hyperloop::AccessViolation
6970
raise e
7071
end
7172
end

lib/reactive_record/permissions.rb

+1-2
Original file line numberDiff line numberDiff line change
@@ -96,15 +96,14 @@ def belongs_to(attr_name, scope = nil, options = {})
9696
end
9797
end
9898

99-
10099
def check_permission_with_acting_user(user, permission, *args)
101100
old = acting_user
102101
self.acting_user = user
103102
if self.send(permission, *args)
104103
self.acting_user = old
105104
self
106105
else
107-
raise Hyperloop::AccessViolation, "for #{permission}(#{args})"
106+
Hyperloop::InternalPolicy.raise_operation_access_violation(:crud_access_violation, "for #{permission}(#{args}) acting_user: #{user}")
108107
end
109108
end
110109

lib/reactive_record/server_data_cache.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ def self.get_model(str)
122122
#
123123
# If str is not already loaded then we have an access violation.
124124
unless const_defined? str
125-
Hyperloop::InternalPolicy.raise_operation_access_violation
125+
Hyperloop::InternalPolicy.raise_operation_access_violation(:undefined_const, "#{str} is not a loaded constant")
126126
end
127127
str.constantize
128128
end

spec/batch6/on_fetch_error_spec.rb

+16-9
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
require 'spec_helper'
22
require 'test_components'
33

4-
describe "ReactiveRecord.on_fetch_error", js: true do
4+
describe "Hyperloop.on_error (for fetches) ", js: true do
55

66
before(:all) do
77
require 'pusher'
@@ -39,21 +39,27 @@
3939
ApplicationController.acting_user = nil
4040
end
4141

42-
it 'call ReactiveRecord.on_fetch_error for access violations' do
42+
it 'call Hyperloop.on_error for access violations' do
4343
TodoItem.class_eval do
4444
TodoItem.regulate_relationship(:comments) { acting_user == user }
4545
end
4646
todo_item1 = TodoItem.create(user: ApplicationController.acting_user)
4747
todo_item2 = TodoItem.create(user: nil)
4848
Comment.create(todo_item: todo_item1)
4949
Comment.create(todo_item: todo_item1)
50-
expect(ReactiveRecord).to receive(:on_fetch_error).once.with(
50+
# expect(Hyperloop).to receive(:on_error).once.with(
51+
# Hyperloop::AccessViolation,
52+
# :fetch_error,
53+
# 'acting_user' => ApplicationController.acting_user,
54+
# 'controller' => kind_of(ActionController::Base),
55+
# 'pending_fetches' => [['TodoItem', ['find_by', { 'id' => 2 }], 'comments', '*count']],
56+
# 'models' => [],
57+
# 'associations' => []
58+
# )
59+
expect(Hyperloop).to receive(:on_error).once.with(
5160
Hyperloop::AccessViolation,
52-
'acting_user' => ApplicationController.acting_user,
53-
'controller' => kind_of(ActionController::Base),
54-
'pending_fetches' => [['TodoItem', ['find_by', { 'id' => 2 }], 'comments', '*count']],
55-
'models' => [],
56-
'associations' => []
61+
:scoped_permission_not_granted,
62+
anything
5763
)
5864
expect_promise("ReactiveRecord.load { TodoItem.find(#{todo_item1.id}).comments.count }")
5965
.to eq(2)
@@ -68,8 +74,9 @@ def title
6874
end
6975
end
7076
TodoItem.create(user: nil)
71-
expect(ReactiveRecord).to receive(:on_fetch_error).once.with(
77+
expect(Hyperloop).to receive(:on_error).once.with(
7278
Exception,
79+
:fetch_error,
7380
hash_including(:acting_user, :controller, :pending_fetches, :models, :associations)
7481
)
7582
evaluate_ruby('TodoItem.find(1).title')

0 commit comments

Comments
 (0)