linked_rails 0.0.4.pre.g9e3bcac55 → 0.0.4.pre.g14b377f91
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/app/controllers/linked_rails/bulk_controller.rb +2 -37
- data/app/models/linked_rails/actions/item.rb +7 -15
- data/app/models/linked_rails/actions/object.rb +3 -5
- data/app/models/linked_rails/collection/view.rb +8 -9
- data/app/models/linked_rails/form/field/file_input.rb +1 -5
- data/app/models/linked_rails/form/field_factory.rb +7 -1
- data/app/models/linked_rails/form.rb +0 -1
- data/app/models/linked_rails/manifest.rb +17 -15
- data/app/models/linked_rails/menus/item.rb +1 -1
- data/app/models/linked_rails/menus/list.rb +4 -15
- data/app/models/linked_rails/ontology.rb +0 -1
- data/app/policies/linked_rails/collection_policy.rb +0 -1
- data/app/serializers/linked_rails/actions/object_serializer.rb +9 -0
- data/app/serializers/linked_rails/collection/view_serializer.rb +0 -1
- data/lib/generators/linked_rails/install/templates/locales.yml +0 -2
- data/lib/linked_rails/controller/error_handling.rb +0 -5
- data/lib/linked_rails/helpers/delta_helper.rb +1 -3
- data/lib/linked_rails/helpers/resource_helper.rb +1 -11
- data/lib/linked_rails/iri_mapper.rb +1 -1
- data/lib/linked_rails/model/collections.rb +1 -3
- data/lib/linked_rails/model/iri.rb +0 -1
- data/lib/linked_rails/model.rb +0 -1
- data/lib/linked_rails/params_parser.rb +4 -14
- data/lib/linked_rails/policy.rb +0 -4
- data/lib/linked_rails/serializer/actionable.rb +3 -3
- data/lib/linked_rails/serializer.rb +1 -7
- data/lib/linked_rails.rb +2 -11
- metadata +3 -10
- data/app/policies/linked_rails/form_policy.rb +0 -13
- data/app/policies/linked_rails/ontology_policy.rb +0 -13
- data/app/workers/linked_rails/invalidation_stream_worker.rb +0 -16
- data/lib/linked_rails/errors/forbidden.rb +0 -37
- data/lib/linked_rails/errors.rb +0 -3
- data/lib/linked_rails/model/cacheable.rb +0 -45
- data/lib/linked_rails/storage.rb +0 -32
- data/lib/linked_rails/url.rb +0 -11
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ad7cb510016bb7b42c2b472031bb0eebcd976cd93f0a20cfca9f70b87271a4c9
|
4
|
+
data.tar.gz: 5965b0ffb3715273ed446f29d3544124145b06162a66c866f899731c85819acb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7f82190e18c85082737f30ff5ed4b5ef1e13cf90b5a3b2c8941589a8812eb79dbf34948005a28895c6aa12884134c66e869258374759506bb7b1642829072773
|
7
|
+
data.tar.gz: 3abb5a9fe9fedde3040d55d89f2a3af74d13e97f93b07dca126a6dcbebcfd27309cee9548b0b95b09dec84cdc6519acd6f44c8e11a4d978e47eca82c4ee88cca
|
@@ -21,11 +21,8 @@ module LinkedRails
|
|
21
21
|
return response_for_wrong_host(opts) if wrong_host?(opts[:iri])
|
22
22
|
|
23
23
|
include = opts[:include].to_s == 'true'
|
24
|
-
resource = LinkedRails.iri_mapper.resource_from_iri(request_path_to_url(opts[:iri]), user_context)
|
25
24
|
|
26
|
-
|
27
|
-
|
28
|
-
response_from_resource(include, opts[:iri], resource)
|
25
|
+
response_from_request(include, RDF::URI(opts[:iri]))
|
29
26
|
rescue StandardError => e
|
30
27
|
handle_resource_error(opts, e)
|
31
28
|
end
|
@@ -87,19 +84,10 @@ module LinkedRails
|
|
87
84
|
false
|
88
85
|
end
|
89
86
|
|
90
|
-
def resource_cache_control(cacheable, status, resource_policy)
|
91
|
-
return :private unless status == 200 && cacheable
|
92
|
-
return 'no-cache' unless resource_policy.try(:public_resource?)
|
93
|
-
|
94
|
-
:public
|
95
|
-
end
|
96
|
-
|
97
87
|
def resource_params(param)
|
98
88
|
params = param.permit(:include, :iri)
|
99
89
|
params[:iri] = URI(params[:iri])
|
100
90
|
params
|
101
|
-
rescue URI::InvalidURIError
|
102
|
-
params.except(:iri)
|
103
91
|
end
|
104
92
|
|
105
93
|
def resource_response_body(iri, rack_body, status)
|
@@ -143,12 +131,6 @@ module LinkedRails
|
|
143
131
|
}.merge(opts)
|
144
132
|
end
|
145
133
|
|
146
|
-
def resource_status(resource_policy)
|
147
|
-
raise(LinkedRails::Errors::Forbidden.new(query: :show?)) unless resource_policy.show?
|
148
|
-
|
149
|
-
200
|
150
|
-
end
|
151
|
-
|
152
134
|
def response_for_wrong_host(opts)
|
153
135
|
iri = opts[:iri]
|
154
136
|
term = term_from_vocab(iri)
|
@@ -157,23 +139,6 @@ module LinkedRails
|
|
157
139
|
ontology_term_response(iri, term, opts[:include])
|
158
140
|
end
|
159
141
|
|
160
|
-
def response_from_resource(include, iri, resource)
|
161
|
-
resource_policy = policy(resource)
|
162
|
-
status = resource_status(resource_policy)
|
163
|
-
|
164
|
-
resource_response(
|
165
|
-
iri,
|
166
|
-
body: response_from_resource_body(include, iri, resource, status),
|
167
|
-
cache: resource_cache_control(resource.try(:cacheable?), status, resource_policy),
|
168
|
-
language: I18n.locale,
|
169
|
-
status: status
|
170
|
-
)
|
171
|
-
end
|
172
|
-
|
173
|
-
def response_from_resource_body(include, _iri, resource, status)
|
174
|
-
include && status == 200 ? resource_body(resource) : nil
|
175
|
-
end
|
176
|
-
|
177
142
|
def term_from_vocab(iri)
|
178
143
|
vocab = Vocab.for(iri)
|
179
144
|
tag = iri.to_s.split(vocab.to_s).last
|
@@ -251,7 +216,7 @@ module LinkedRails
|
|
251
216
|
|
252
217
|
def sanitized_relative_path(iri) # rubocop:disable Metrics/AbcSize
|
253
218
|
iri.path = "#{iri.path}/" unless iri.path&.ends_with?('/')
|
254
|
-
uri = URI(LinkedRails.iri.path.
|
219
|
+
uri = URI(LinkedRails.iri.path.present? ? iri.to_s.split("#{LinkedRails.iri.path}/").last : iri)
|
255
220
|
|
256
221
|
[uri.path, uri.query].compact.join('?')
|
257
222
|
end
|
@@ -61,15 +61,13 @@ module LinkedRails
|
|
61
61
|
end
|
62
62
|
|
63
63
|
def object
|
64
|
-
|
65
|
-
end
|
64
|
+
@object = list.instance_exec(&@object) if @object.respond_to?(:call)
|
66
65
|
|
67
|
-
|
68
|
-
iri_with_root(object_root_relative_iri)
|
66
|
+
@object || resource
|
69
67
|
end
|
70
68
|
|
71
|
-
def
|
72
|
-
object&.iri&.anonymous? ?
|
69
|
+
def object_iri
|
70
|
+
object&.iri&.anonymous? ? anonymous_object_iri : object&.iri
|
73
71
|
end
|
74
72
|
|
75
73
|
def parent
|
@@ -140,8 +138,8 @@ module LinkedRails
|
|
140
138
|
|
141
139
|
private
|
142
140
|
|
143
|
-
def
|
144
|
-
object_iri =
|
141
|
+
def anonymous_object_iri
|
142
|
+
object_iri = iri.dup
|
145
143
|
object_iri.path += '/action_object'
|
146
144
|
object_iri
|
147
145
|
end
|
@@ -154,12 +152,6 @@ module LinkedRails
|
|
154
152
|
LinkedRails.translate(:action, :label, self)
|
155
153
|
end
|
156
154
|
|
157
|
-
def object_from_var
|
158
|
-
return @object unless @object.respond_to?(:call)
|
159
|
-
|
160
|
-
@object = list.instance_exec(&@object)
|
161
|
-
end
|
162
|
-
|
163
155
|
def policy_expired?
|
164
156
|
@policy_expired ||= policy && resource_policy.try(:expired?)
|
165
157
|
end
|
@@ -195,7 +187,7 @@ module LinkedRails
|
|
195
187
|
|
196
188
|
def target_url_fallback # rubocop:disable Metrics/AbcSize
|
197
189
|
base = (resource.try(:singular_resource?) ? resource.singular_iri : resource.iri).dup
|
198
|
-
base.path = "#{base.path
|
190
|
+
base.path = "#{base.path}/#{target_path}" if target_path.present?
|
199
191
|
base.query = Rack::Utils.parse_nested_query(base.query).merge(target_query).to_param if target_query.present?
|
200
192
|
base
|
201
193
|
end
|
@@ -12,8 +12,8 @@ module LinkedRails
|
|
12
12
|
alias parent action
|
13
13
|
delegate :object, to: :action
|
14
14
|
|
15
|
-
def
|
16
|
-
action.
|
15
|
+
def iri
|
16
|
+
action.object_iri
|
17
17
|
end
|
18
18
|
|
19
19
|
class << self
|
@@ -30,9 +30,7 @@ module LinkedRails
|
|
30
30
|
|
31
31
|
parent = parent_from_params!(params, user_context)
|
32
32
|
|
33
|
-
|
34
|
-
object.instance_variable_set(:@iri, parent.object_iri)
|
35
|
-
object
|
33
|
+
new(action: parent) if parent.object.anonymous_iri?
|
36
34
|
end
|
37
35
|
end
|
38
36
|
end
|
@@ -8,9 +8,8 @@ module LinkedRails
|
|
8
8
|
include LinkedRails::Model
|
9
9
|
|
10
10
|
attr_accessor :collection, :filter
|
11
|
-
delegate :apply_scope, :association_base, :association_class, :
|
12
|
-
:
|
13
|
-
to: :collection
|
11
|
+
delegate :apply_scope, :association_base, :association_class, :default_page_size, :display, :include_members,
|
12
|
+
:parent, :policy, :total_page_count, :unfiltered_collection, :user_context, to: :collection
|
14
13
|
delegate :count, to: :members
|
15
14
|
|
16
15
|
alias id iri
|
@@ -43,7 +42,7 @@ module LinkedRails
|
|
43
42
|
end
|
44
43
|
|
45
44
|
def preview_includes
|
46
|
-
include_members ? {
|
45
|
+
include_members ? {member_sequence: :members} : %i[member_sequence]
|
47
46
|
end
|
48
47
|
|
49
48
|
def title
|
@@ -76,19 +75,19 @@ module LinkedRails
|
|
76
75
|
end
|
77
76
|
|
78
77
|
def iris_from_scope?
|
79
|
-
members_query.is_a?(ActiveRecord::Relation) && !polymorphic_collection?
|
78
|
+
members_query.is_a?(ActiveRecord::Relation) && !polymorphic_collection?
|
80
79
|
end
|
81
80
|
|
82
81
|
def members_array
|
83
82
|
members_query.to_a
|
84
83
|
end
|
85
84
|
|
86
|
-
def polymorphic_collection?
|
87
|
-
column =
|
88
|
-
polymorphic =
|
85
|
+
def polymorphic_collection?
|
86
|
+
column = association_class.inheritance_column
|
87
|
+
polymorphic = association_class.columns_hash.include?(column)
|
89
88
|
return false unless polymorphic
|
90
89
|
|
91
|
-
return true if
|
90
|
+
return true if association_class.descends_from_active_record?
|
92
91
|
|
93
92
|
members_query.where_values_hash.include?(column) &&
|
94
93
|
members_query.where_values_hash[column] != association_class.to_s
|
@@ -52,7 +52,13 @@ module LinkedRails
|
|
52
52
|
private
|
53
53
|
|
54
54
|
def attr_column(name)
|
55
|
-
|
55
|
+
column_model =
|
56
|
+
if model_class.is_delegated_attribute?(name)
|
57
|
+
model_class.class_for_delegated_attribute(name)
|
58
|
+
else
|
59
|
+
model_class
|
60
|
+
end
|
61
|
+
column_model.column_for_attribute(name)
|
56
62
|
end
|
57
63
|
|
58
64
|
def attr_to_datatype # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength
|
@@ -5,11 +5,15 @@ module LinkedRails
|
|
5
5
|
include ActiveModel::Model
|
6
6
|
include LinkedRails::Model
|
7
7
|
|
8
|
+
MANIFEST_KEY = 'cache:Manifest'
|
9
|
+
CACHE_DB = ENV.fetch('PERSISTENT_REDIS_DATABASE', '6')
|
10
|
+
|
8
11
|
def save
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
12
|
+
self.class.redis_client.hset(
|
13
|
+
MANIFEST_KEY,
|
14
|
+
{
|
15
|
+
LinkedRails.iri.to_s => web_manifest.to_json
|
16
|
+
}
|
13
17
|
)
|
14
18
|
end
|
15
19
|
|
@@ -41,7 +45,7 @@ module LinkedRails
|
|
41
45
|
def blob_preview_iri
|
42
46
|
return unless ActiveStorage::Blob.service.present?
|
43
47
|
|
44
|
-
|
48
|
+
LinkedRails.iri(path: 'rails/active_storage/blobs/redirect/{signed_id}/preview')
|
45
49
|
end
|
46
50
|
|
47
51
|
def blob_upload_iri
|
@@ -138,7 +142,7 @@ module LinkedRails
|
|
138
142
|
|
139
143
|
def web_manifest_sw_section
|
140
144
|
{
|
141
|
-
src: "#{scope
|
145
|
+
src: "#{scope}/sw.js",
|
142
146
|
scope: scope
|
143
147
|
}
|
144
148
|
end
|
@@ -161,22 +165,20 @@ module LinkedRails
|
|
161
165
|
|
162
166
|
class << self
|
163
167
|
def destroy(iri)
|
164
|
-
|
168
|
+
redis_client.hdel(MANIFEST_KEY, iri)
|
165
169
|
end
|
166
170
|
|
167
171
|
def move(from, to)
|
168
|
-
|
169
|
-
:persistent,
|
170
|
-
:redirect_prefix,
|
171
|
-
URL.as_href(from) => URL.as_href(to)
|
172
|
-
)
|
173
|
-
|
174
|
-
data = Storage.hget(:persistent, :manifest, URL.as_href(from))
|
172
|
+
data = redis_client.hget(MANIFEST_KEY, from)
|
175
173
|
|
176
|
-
|
174
|
+
redis_client.hset(MANIFEST_KEY, to, data) if data
|
177
175
|
|
178
176
|
destroy(from)
|
179
177
|
end
|
178
|
+
|
179
|
+
def redis_client
|
180
|
+
@redis_client = Redis.new(db: CACHE_DB)
|
181
|
+
end
|
180
182
|
end
|
181
183
|
end
|
182
184
|
end
|
@@ -26,7 +26,7 @@ module LinkedRails
|
|
26
26
|
end
|
27
27
|
|
28
28
|
def menus
|
29
|
-
@menus ||= available_menus.map(&method(:
|
29
|
+
@menus ||= available_menus.map(&method(:memoised_menu_item))
|
30
30
|
end
|
31
31
|
|
32
32
|
def menu(tag)
|
@@ -49,8 +49,9 @@ module LinkedRails
|
|
49
49
|
end
|
50
50
|
|
51
51
|
def menu_item(tag, options) # rubocop:disable Metrics/AbcSize
|
52
|
-
|
53
|
-
|
52
|
+
if options[:policy].present?
|
53
|
+
return unless resource_policy(options[:policy_resource]).send(options[:policy], *options[:policy_arguments])
|
54
|
+
end
|
54
55
|
options[:label_params] ||= {}
|
55
56
|
options[:label_params][:default] ||= ["menus.default.#{tag}".to_sym, tag.to_s.capitalize]
|
56
57
|
options[:label] ||= default_label(tag, options)
|
@@ -59,10 +60,6 @@ module LinkedRails
|
|
59
60
|
LinkedRails.menus_item_class.new(resource: resource, tag: tag, parent: self, **options)
|
60
61
|
end
|
61
62
|
|
62
|
-
def policy_verdict(policy, options)
|
63
|
-
policy.send(options[:policy], *options[:policy_arguments])
|
64
|
-
end
|
65
|
-
|
66
63
|
def resource_policy(policy_resource)
|
67
64
|
policy_resource ||= resource
|
68
65
|
policy_resource = instance_exec(&policy_resource) if policy_resource.respond_to?(:call)
|
@@ -72,14 +69,6 @@ module LinkedRails
|
|
72
69
|
@resource_policy[policy_resource] ||= Pundit.policy(user_context, policy_resource)
|
73
70
|
end
|
74
71
|
|
75
|
-
def show_menu_item?(_tag, options)
|
76
|
-
return true if options[:policy].blank?
|
77
|
-
|
78
|
-
policy = resource_policy(options[:policy_resource])
|
79
|
-
|
80
|
-
policy_verdict(policy, options)
|
81
|
-
end
|
82
|
-
|
83
72
|
def iri_template
|
84
73
|
base_template = resource.send(resource.try(:singular_resource?) ? :singular_iri_template : :iri_template)
|
85
74
|
|
@@ -6,10 +6,6 @@ module LinkedRails
|
|
6
6
|
extend ActiveSupport::Concern
|
7
7
|
include ActiveSupport::Rescuable
|
8
8
|
|
9
|
-
included do
|
10
|
-
rescue_from LinkedRails::Errors::Forbidden, with: :handle_error
|
11
|
-
end
|
12
|
-
|
13
9
|
private
|
14
10
|
|
15
11
|
def add_error_snackbar(error)
|
@@ -73,7 +69,6 @@ module LinkedRails
|
|
73
69
|
'Doorkeeper::Errors::InvalidGrantReuse' => 422,
|
74
70
|
'LinkedRails::Auth::Errors::Expired' => 410,
|
75
71
|
'LinkedRails::Auth::Errors::Unauthorized' => 401,
|
76
|
-
'LinkedRails::Errors::Forbidden' => 403,
|
77
72
|
'Pundit::NotAuthorizedError' => 403
|
78
73
|
}
|
79
74
|
end
|
@@ -8,9 +8,7 @@ module LinkedRails
|
|
8
8
|
end
|
9
9
|
|
10
10
|
def invalidate_collection_delta(collection)
|
11
|
-
|
12
|
-
|
13
|
-
[Vocab.sp[:Variable], Vocab.ontola[:baseCollection], iri, delta_iri(:invalidate)]
|
11
|
+
[Vocab.sp[:Variable], Vocab.ontola[:baseCollection], collection.iri, delta_iri(:invalidate)]
|
14
12
|
end
|
15
13
|
|
16
14
|
def invalidate_parent_collections_delta(resource)
|
@@ -46,22 +46,12 @@ module LinkedRails
|
|
46
46
|
|
47
47
|
private
|
48
48
|
|
49
|
-
def request_path_to_url(path)
|
50
|
-
return path unless path.present? && URI(path).relative?
|
51
|
-
|
52
|
-
port = [80, 443].include?(request.port) ? nil : request.port
|
53
|
-
URI::Generic.new(request.scheme, nil, request.host, port, nil, path, nil, nil, nil).to_s
|
54
|
-
end
|
55
|
-
|
56
49
|
def build_new_resource
|
57
50
|
controller_class.build_new(user_context: user_context)
|
58
51
|
end
|
59
52
|
|
60
53
|
def new_resource_from_parent
|
61
|
-
if requested_resource.is_a?(
|
62
|
-
requested_resource.is_a?(LinkedRails.collection_view_class)
|
63
|
-
return requested_resource.child_resource
|
64
|
-
end
|
54
|
+
return requested_resource.child_resource if requested_resource.is_a?(Collection)
|
65
55
|
|
66
56
|
parent_resource.build_child(
|
67
57
|
controller_class,
|
@@ -38,7 +38,7 @@ module LinkedRails
|
|
38
38
|
params = Rails.application.routes.recognize_path(iri.to_s, method: method)
|
39
39
|
|
40
40
|
route_params_to_opts(params.merge(query), iri.to_s)
|
41
|
-
rescue ActionController::RoutingError
|
41
|
+
rescue ActionController::RoutingError
|
42
42
|
EMPTY_IRI_OPTS.dup
|
43
43
|
end
|
44
44
|
|
@@ -70,9 +70,7 @@ module LinkedRails
|
|
70
70
|
|
71
71
|
module ClassMethods
|
72
72
|
def collection_iri(**opts)
|
73
|
-
|
74
|
-
|
75
|
-
LinkedRails.iri(path: collection_root_relative_iri(**opts), fragment: fragment)
|
73
|
+
LinkedRails.iri(path: collection_root_relative_iri(**opts))
|
76
74
|
end
|
77
75
|
|
78
76
|
# Sets the defaults for all collections for this class.
|
data/lib/linked_rails/model.rb
CHANGED
@@ -118,13 +118,9 @@ module LinkedRails
|
|
118
118
|
end
|
119
119
|
|
120
120
|
def parse_attribute(klass, field_options, value)
|
121
|
-
|
122
|
-
end
|
123
|
-
|
124
|
-
def parse_attribute_value(klass, field_options, value)
|
125
|
-
return nil if value == Vocab.libro[:null]
|
121
|
+
parsed_value = parse_enum_attribute(klass, field_options.key, value) || value
|
126
122
|
|
127
|
-
|
123
|
+
[field_options.key, parsed_value.to_s]
|
128
124
|
end
|
129
125
|
|
130
126
|
def parse_enum_attribute(klass, key, value)
|
@@ -137,15 +133,9 @@ module LinkedRails
|
|
137
133
|
|
138
134
|
def parse_iri_param(iri, reflection)
|
139
135
|
key = foreign_key_for_reflection(reflection)
|
140
|
-
|
136
|
+
value = parse_iri_param_value(iri, reflection) if key
|
141
137
|
|
142
|
-
|
143
|
-
[key, nil]
|
144
|
-
else
|
145
|
-
value = parse_iri_param_value(iri, reflection)
|
146
|
-
|
147
|
-
[key, value.to_s] if value
|
148
|
-
end
|
138
|
+
[key, value.to_s] if value
|
149
139
|
end
|
150
140
|
|
151
141
|
def parse_iri_param_value(iri, reflection)
|
data/lib/linked_rails/policy.rb
CHANGED
@@ -15,10 +15,10 @@ module LinkedRails
|
|
15
15
|
|
16
16
|
module ClassMethods
|
17
17
|
def action_triples(object, _params)
|
18
|
-
if
|
19
|
-
object.try(:action_triples) || []
|
20
|
-
else
|
18
|
+
if object.iri.anonymous? && !object.try(:singular_resource?)
|
21
19
|
[]
|
20
|
+
else
|
21
|
+
object.try(:action_triples) || []
|
22
22
|
end
|
23
23
|
end
|
24
24
|
end
|
@@ -115,13 +115,7 @@ module LinkedRails
|
|
115
115
|
collection_name = "#{name.to_s.singularize}_collection"
|
116
116
|
opts[:association] ||= name
|
117
117
|
opts[:polymorphic] ||= true
|
118
|
-
|
119
|
-
action_object = opts.delete(:action_object)
|
120
|
-
opts[:if] ||= -> (object) {
|
121
|
-
return action_object if object.iri.path.end_with?('/action_object')
|
122
|
-
|
123
|
-
named_object?(object)
|
124
|
-
}
|
118
|
+
opts[:if] ||= method(:named_object?)
|
125
119
|
|
126
120
|
collection_opts = {}
|
127
121
|
collection_opts[:page_size] = opts.delete(:page_size) if opts.key?(:page_size)
|
data/lib/linked_rails.rb
CHANGED
@@ -22,10 +22,6 @@ module LinkedRails
|
|
22
22
|
|
23
23
|
mattr_accessor :whitelisted_spi_ips
|
24
24
|
mattr_writer :host, :scheme
|
25
|
-
mattr_accessor :persistent_redis_database, default: ENV['PERSISTENT_REDIS_DATABASE'].presence || 6
|
26
|
-
mattr_accessor :stream_redis_database, default: ENV['STREAM_REDIS_DATABASE'].presence || 7
|
27
|
-
mattr_accessor :cache_redis_database, default: ENV['CACHE_REDIS_DATABASE'].presence || 8
|
28
|
-
mattr_accessor :cache_stream, default: ENV['CACHE_STREAM'].presence || 'transactions'
|
29
25
|
|
30
26
|
def self.configurable_class(parent, klass, default: nil, reader: nil) # rubocop:disable Metrics/AbcSize
|
31
27
|
method = :"#{[parent, klass.to_s.downcase].compact.join('_')}_class"
|
@@ -54,10 +50,8 @@ module LinkedRails
|
|
54
50
|
@@scheme ||= Rails.application.routes.default_url_options[:protocol] || :http # rubocop:disable Style/ClassVars
|
55
51
|
end
|
56
52
|
|
57
|
-
def iri(**
|
58
|
-
|
59
|
-
opts[:path] = opts[:path].presence || '/'
|
60
|
-
RDF::URI.new(**opts)
|
53
|
+
def iri(**opts)
|
54
|
+
RDF::URI.new(**{scheme: LinkedRails.scheme, host: LinkedRails.host}.merge(opts))
|
61
55
|
end
|
62
56
|
end
|
63
57
|
|
@@ -90,7 +84,6 @@ ActiveSupport::Inflector.inflections do |inflect|
|
|
90
84
|
inflect.acronym 'SHACL'
|
91
85
|
end
|
92
86
|
|
93
|
-
require 'linked_rails/errors'
|
94
87
|
require 'linked_rails/uri_template'
|
95
88
|
require 'linked_rails/vocab'
|
96
89
|
require 'linked_rails/cache'
|
@@ -108,5 +101,3 @@ require 'linked_rails/routes'
|
|
108
101
|
require 'linked_rails/serializer'
|
109
102
|
require 'linked_rails/translate'
|
110
103
|
require 'linked_rails/railtie'
|
111
|
-
require 'linked_rails/url'
|
112
|
-
require 'linked_rails/storage'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: linked_rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.4.pre.
|
4
|
+
version: 0.0.4.pre.g14b377f91
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Arthur Dingemans
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
11
|
+
date: 2022-08-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: active_response
|
@@ -299,12 +299,11 @@ files:
|
|
299
299
|
- app/policies/linked_rails/collection/view_policy.rb
|
300
300
|
- app/policies/linked_rails/collection_policy.rb
|
301
301
|
- app/policies/linked_rails/enum_value_policy.rb
|
302
|
-
- app/policies/linked_rails/form_policy.rb
|
303
302
|
- app/policies/linked_rails/menus/item_policy.rb
|
304
303
|
- app/policies/linked_rails/menus/list_policy.rb
|
305
|
-
- app/policies/linked_rails/ontology_policy.rb
|
306
304
|
- app/policies/linked_rails/sequence_policy.rb
|
307
305
|
- app/serializers/linked_rails/actions/item_serializer.rb
|
306
|
+
- app/serializers/linked_rails/actions/object_serializer.rb
|
308
307
|
- app/serializers/linked_rails/collection/filter_field_serializer.rb
|
309
308
|
- app/serializers/linked_rails/collection/filter_option_serializer.rb
|
310
309
|
- app/serializers/linked_rails/collection/filter_serializer.rb
|
@@ -339,7 +338,6 @@ files:
|
|
339
338
|
- app/serializers/linked_rails/web_page_serializer.rb
|
340
339
|
- app/serializers/linked_rails/web_site_serializer.rb
|
341
340
|
- app/serializers/linked_rails/widget_serializer.rb
|
342
|
-
- app/workers/linked_rails/invalidation_stream_worker.rb
|
343
341
|
- config/initializers/inflections.rb
|
344
342
|
- lib/generators/linked_rails/install/install_generator.rb
|
345
343
|
- lib/generators/linked_rails/install/templates/README
|
@@ -389,8 +387,6 @@ files:
|
|
389
387
|
- lib/linked_rails/enhancements/destroyable/controller.rb
|
390
388
|
- lib/linked_rails/enhancements/updatable/controller.rb
|
391
389
|
- lib/linked_rails/enhancements/updatable/serializer.rb
|
392
|
-
- lib/linked_rails/errors.rb
|
393
|
-
- lib/linked_rails/errors/forbidden.rb
|
394
390
|
- lib/linked_rails/helpers/delta_helper.rb
|
395
391
|
- lib/linked_rails/helpers/ontola_actions_helper.rb
|
396
392
|
- lib/linked_rails/helpers/resource_helper.rb
|
@@ -399,7 +395,6 @@ files:
|
|
399
395
|
- lib/linked_rails/middleware/linked_data_params.rb
|
400
396
|
- lib/linked_rails/model.rb
|
401
397
|
- lib/linked_rails/model/actionable.rb
|
402
|
-
- lib/linked_rails/model/cacheable.rb
|
403
398
|
- lib/linked_rails/model/collections.rb
|
404
399
|
- lib/linked_rails/model/dirty.rb
|
405
400
|
- lib/linked_rails/model/enhancements.rb
|
@@ -423,12 +418,10 @@ files:
|
|
423
418
|
- lib/linked_rails/serializer/actionable.rb
|
424
419
|
- lib/linked_rails/serializer/menuable.rb
|
425
420
|
- lib/linked_rails/serializer/singularable.rb
|
426
|
-
- lib/linked_rails/storage.rb
|
427
421
|
- lib/linked_rails/test_methods.rb
|
428
422
|
- lib/linked_rails/translate.rb
|
429
423
|
- lib/linked_rails/types/iri_type.rb
|
430
424
|
- lib/linked_rails/uri_template.rb
|
431
|
-
- lib/linked_rails/url.rb
|
432
425
|
- lib/linked_rails/version.rb
|
433
426
|
- lib/linked_rails/vocab.rb
|
434
427
|
- lib/nill_class_renderer.rb
|
@@ -1,16 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module LinkedRails
|
4
|
-
class InvalidationStreamWorker < ActiveJob::Base
|
5
|
-
def perform(type, iri, resource_type)
|
6
|
-
entry = {
|
7
|
-
type: type,
|
8
|
-
resource: iri,
|
9
|
-
resourceType: resource_type
|
10
|
-
}
|
11
|
-
id = Storage.xadd(:stream, LinkedRails.cache_stream, entry)
|
12
|
-
|
13
|
-
raise('No message id returned, implies failure') if id.blank?
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
@@ -1,37 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module LinkedRails
|
4
|
-
module Errors
|
5
|
-
class Forbidden < StandardError
|
6
|
-
attr_reader :query, :record, :policy, :action
|
7
|
-
|
8
|
-
# @param [Hash] options
|
9
|
-
# @option options [String] query The action of the request
|
10
|
-
# @option options [ActiveRecord::Base] record The record that was requested
|
11
|
-
# @option options [Policy] policy The policy that raised the exception
|
12
|
-
# @option options [String] message Override the default error message
|
13
|
-
# @return [String] the message
|
14
|
-
def initialize(**options)
|
15
|
-
@query = options.fetch(:query).to_s
|
16
|
-
@record = options[:record]
|
17
|
-
@policy = options[:policy]
|
18
|
-
@action = @query[-1] == '?' ? @query[0..-2] : @query
|
19
|
-
@message = options[:message]
|
20
|
-
|
21
|
-
raise StandardError if @query.blank? && @message.blank?
|
22
|
-
|
23
|
-
super(@message || default_message)
|
24
|
-
end
|
25
|
-
|
26
|
-
private
|
27
|
-
|
28
|
-
def default_message
|
29
|
-
I18n.t(
|
30
|
-
"pundit.#{@policy.class.to_s.underscore}.#{@query}",
|
31
|
-
action: @action,
|
32
|
-
default: I18n.t('errors.access_denied')
|
33
|
-
)
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|
37
|
-
end
|
data/lib/linked_rails/errors.rb
DELETED
@@ -1,45 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module LinkedRails
|
4
|
-
module Model
|
5
|
-
module Cacheable
|
6
|
-
extend ActiveSupport::Concern
|
7
|
-
|
8
|
-
included do
|
9
|
-
if respond_to?(:after_commit)
|
10
|
-
after_commit :publish_create, on: :create, if: :should_publish_changes
|
11
|
-
after_commit :publish_update, on: :update, if: :should_publish_changes
|
12
|
-
after_commit :publish_delete, on: :destroy, if: :should_publish_changes
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
|
-
def cacheable?
|
17
|
-
true
|
18
|
-
end
|
19
|
-
|
20
|
-
def publish_create
|
21
|
-
publish_message('io.ontola.transactions.Created')
|
22
|
-
end
|
23
|
-
|
24
|
-
def publish_update
|
25
|
-
publish_message('io.ontola.transactions.Updated')
|
26
|
-
end
|
27
|
-
|
28
|
-
def publish_delete
|
29
|
-
publish_message('io.ontola.transactions.Deleted')
|
30
|
-
end
|
31
|
-
|
32
|
-
private
|
33
|
-
|
34
|
-
def publish_message(type)
|
35
|
-
LinkedRails::InvalidationStreamWorker.perform_now(type, iri.to_s, self.class.iri.to_s)
|
36
|
-
rescue StandardError
|
37
|
-
LinkedRails::InvalidationStreamWorker.perform_later(type, iri.to_s, self.class.iri.to_s)
|
38
|
-
end
|
39
|
-
|
40
|
-
def should_publish_changes
|
41
|
-
cacheable? && !Rails.env.test?
|
42
|
-
end
|
43
|
-
end
|
44
|
-
end
|
45
|
-
end
|
data/lib/linked_rails/storage.rb
DELETED
@@ -1,32 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'redis'
|
4
|
-
|
5
|
-
module LinkedRails
|
6
|
-
class Storage
|
7
|
-
REDIS_DB = {
|
8
|
-
cache: LinkedRails.cache_redis_database,
|
9
|
-
persistent: LinkedRails.persistent_redis_database,
|
10
|
-
stream: LinkedRails.stream_redis_database
|
11
|
-
}.freeze
|
12
|
-
KEYS = {
|
13
|
-
manifest: 'cache:Manifest',
|
14
|
-
redirect_exact: 'cache:Redirect:Exact',
|
15
|
-
redirect_prefix: 'cache:Redirect:Prefix'
|
16
|
-
}.freeze
|
17
|
-
|
18
|
-
class << self
|
19
|
-
%i[xadd].each do |method|
|
20
|
-
define_method(method) do |db, *args|
|
21
|
-
Redis.new(db: REDIS_DB.fetch(db)).send(method, *args)
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
%i[hset hdel hget].each do |method|
|
26
|
-
define_method(method) do |db, key, *args|
|
27
|
-
Redis.new(db: REDIS_DB.fetch(db)).send(method, KEYS.fetch(key), *args)
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|