linked_rails 0.0.4.pre.g8d7195543 → 0.0.4.pre.g9b7bc9073
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/controllers/linked_rails/bulk_controller.rb +2 -37
- data/app/models/linked_rails/actions/item.rb +1 -1
- data/app/models/linked_rails/collection/view.rb +3 -4
- 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 +20 -94
- data/app/models/linked_rails/menus/item.rb +1 -1
- data/app/models/linked_rails/menus/list.rb +1 -1
- data/app/models/linked_rails/ontology.rb +0 -1
- 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/delta.rb +21 -1
- data/lib/linked_rails/controller/error_handling.rb +0 -5
- data/lib/linked_rails/helpers/resource_helper.rb +1 -11
- data/lib/linked_rails/iri_mapper.rb +1 -1
- data/lib/linked_rails/middleware/linked_data_params.rb +1 -1
- data/lib/linked_rails/model/dirty.rb +11 -0
- data/lib/linked_rails/model/iri.rb +0 -1
- data/lib/linked_rails/model.rb +0 -1
- data/lib/linked_rails/params_parser.rb +7 -6
- data/lib/linked_rails/policy.rb +0 -4
- data/lib/linked_rails.rb +2 -11
- metadata +4 -26
- 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: d86a69fbe49260dc07acefa64442a1a3a886a9d1b45cab169fc4e514ffe27b75
|
4
|
+
data.tar.gz: 2bd8aa4736a567bbb045889c96b3c5f8c02bcfbab7bbd90b8374c86d614599d0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e907be3993d7b5a334649d29f5b8703a0a3bccb5ca0c8a747b96c93e8a1e27fe30c5ae110f3cab02c80ae75e69fc5e59a33abeee0a22e6e87e030fa7d03a6410
|
7
|
+
data.tar.gz: ec7768a12f8801cccf9e2ff3b95ce295bd5257cc4d888ab010a436ec74469ec53b9f910043ef094b10239d4c2672310b4e45b08aff57a44f1a4f30af6fb5004a
|
@@ -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
|
@@ -187,7 +187,7 @@ module LinkedRails
|
|
187
187
|
|
188
188
|
def target_url_fallback # rubocop:disable Metrics/AbcSize
|
189
189
|
base = (resource.try(:singular_resource?) ? resource.singular_iri : resource.iri).dup
|
190
|
-
base.path = "#{base.path
|
190
|
+
base.path = "#{base.path}/#{target_path}" if target_path.present?
|
191
191
|
base.query = Rack::Utils.parse_nested_query(base.query).merge(target_query).to_param if target_query.present?
|
192
192
|
base
|
193
193
|
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
|
@@ -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,27 +5,6 @@ module LinkedRails
|
|
5
5
|
include ActiveModel::Model
|
6
6
|
include LinkedRails::Model
|
7
7
|
|
8
|
-
def save
|
9
|
-
Storage.hset(
|
10
|
-
:persistent,
|
11
|
-
:manifest,
|
12
|
-
URL.as_href(LinkedRails.iri) => web_manifest.to_json
|
13
|
-
)
|
14
|
-
end
|
15
|
-
|
16
|
-
def web_manifest
|
17
|
-
web_manifest_base.merge(
|
18
|
-
ontola: web_manifest_ontola_section,
|
19
|
-
serviceworker: web_manifest_sw_section
|
20
|
-
)
|
21
|
-
end
|
22
|
-
|
23
|
-
private
|
24
|
-
|
25
|
-
def allowed_external_sources
|
26
|
-
[]
|
27
|
-
end
|
28
|
-
|
29
8
|
def app_name
|
30
9
|
Rails.application.railtie_name.chomp('_application').humanize
|
31
10
|
end
|
@@ -38,27 +17,8 @@ module LinkedRails
|
|
38
17
|
'#eef0f2'
|
39
18
|
end
|
40
19
|
|
41
|
-
def blob_preview_iri
|
42
|
-
return unless ActiveStorage::Blob.service.present?
|
43
|
-
|
44
|
-
"#{LinkedRails.iri(path: 'rails/active_storage/blobs/redirect')}/{signed_id}/preview"
|
45
|
-
end
|
46
|
-
|
47
|
-
def blob_upload_iri
|
48
|
-
return unless ActiveStorage::Blob.service.present?
|
49
|
-
|
50
|
-
LinkedRails.iri(path: 'rails/active_storage/direct_uploads')
|
51
|
-
end
|
52
|
-
|
53
20
|
def css_class; end
|
54
21
|
|
55
|
-
def csp_entries
|
56
|
-
{
|
57
|
-
connectSrc: [ActiveStorage::Blob.service.try(:bucket)&.url].compact,
|
58
|
-
scriptSrc: [ActiveStorage::Blob.service.try(:bucket)&.url].compact
|
59
|
-
}
|
60
|
-
end
|
61
|
-
|
62
22
|
def header_background
|
63
23
|
:primary
|
64
24
|
end
|
@@ -67,16 +27,17 @@ module LinkedRails
|
|
67
27
|
:white
|
68
28
|
end
|
69
29
|
|
70
|
-
def
|
71
|
-
[
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
30
|
+
def preload_iris
|
31
|
+
[
|
32
|
+
scope,
|
33
|
+
LinkedRails.iri(path: 'ns/core').to_s,
|
34
|
+
LinkedRails.iri(path: 'c_a').to_s,
|
35
|
+
LinkedRails.iri(path: 'menus').to_s
|
36
|
+
]
|
76
37
|
end
|
77
38
|
|
78
39
|
def scope
|
79
|
-
LinkedRails.iri.to_s
|
40
|
+
@scope ||= LinkedRails.iri.to_s
|
80
41
|
end
|
81
42
|
|
82
43
|
def site_theme_color
|
@@ -91,46 +52,43 @@ module LinkedRails
|
|
91
52
|
app_name
|
92
53
|
end
|
93
54
|
|
94
|
-
def start_url
|
95
|
-
scope == '/' ? scope : "#{scope}/"
|
96
|
-
end
|
97
|
-
|
98
55
|
def theme; end
|
99
56
|
|
100
57
|
def theme_options
|
101
58
|
{}
|
102
59
|
end
|
103
60
|
|
61
|
+
def web_manifest
|
62
|
+
web_manifest_base.merge(
|
63
|
+
ontola: web_manifest_ontola_section,
|
64
|
+
serviceworker: web_manifest_sw_section
|
65
|
+
)
|
66
|
+
end
|
67
|
+
|
104
68
|
def web_manifest_base # rubocop:disable Metrics/MethodLength
|
105
69
|
{
|
106
70
|
background_color: background_color,
|
107
71
|
dir: :rtl,
|
108
72
|
display: :standalone,
|
109
|
-
|
110
|
-
lang: lang,
|
73
|
+
lang: :nl,
|
111
74
|
name: app_name,
|
112
75
|
scope: scope,
|
113
76
|
short_name: app_name,
|
114
|
-
start_url:
|
77
|
+
start_url: scope,
|
115
78
|
theme_color: site_theme_color
|
116
79
|
}
|
117
80
|
end
|
118
81
|
|
119
82
|
def web_manifest_ontola_section # rubocop:disable Metrics/MethodLength
|
120
83
|
{
|
121
|
-
|
122
|
-
blob_preview_iri: blob_preview_iri,
|
123
|
-
blob_upload_iri: blob_upload_iri,
|
124
|
-
csp: csp_entries,
|
84
|
+
css_class: css_class,
|
125
85
|
header_background: header_background,
|
126
86
|
header_text: header_text,
|
127
|
-
|
87
|
+
preload: preload_iris,
|
128
88
|
primary_color: site_theme_color,
|
129
89
|
secondary_color: site_secondary_color,
|
130
|
-
styled_headers: styled_headers,
|
131
90
|
theme: theme,
|
132
91
|
theme_options: theme_options.to_query,
|
133
|
-
tracking: tracking,
|
134
92
|
website_iri: LinkedRails.iri.to_s,
|
135
93
|
websocket_path: websocket_path
|
136
94
|
}
|
@@ -138,7 +96,7 @@ module LinkedRails
|
|
138
96
|
|
139
97
|
def web_manifest_sw_section
|
140
98
|
{
|
141
|
-
src: "#{scope
|
99
|
+
src: "#{scope}/sw.js?manifestLocation=#{Rack::Utils.escape("#{scope}/manifest.json")}",
|
142
100
|
scope: scope
|
143
101
|
}
|
144
102
|
end
|
@@ -146,37 +104,5 @@ module LinkedRails
|
|
146
104
|
def websocket_path
|
147
105
|
Rails.application.config.try(:action_cable).try(:mount_path).try(:[], 1..-1)
|
148
106
|
end
|
149
|
-
|
150
|
-
def preconnect
|
151
|
-
[]
|
152
|
-
end
|
153
|
-
|
154
|
-
def styled_headers
|
155
|
-
false
|
156
|
-
end
|
157
|
-
|
158
|
-
def tracking
|
159
|
-
[]
|
160
|
-
end
|
161
|
-
|
162
|
-
class << self
|
163
|
-
def destroy(iri)
|
164
|
-
Storage.hdel(:persistent, :manifest, URL.as_href(iri))
|
165
|
-
end
|
166
|
-
|
167
|
-
def move(from, to)
|
168
|
-
Storage.hset(
|
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))
|
175
|
-
|
176
|
-
Storage.hset(:persistent, :manifest, URL.as_href(to), data) if data
|
177
|
-
|
178
|
-
destroy(from)
|
179
|
-
end
|
180
|
-
end
|
181
107
|
end
|
182
108
|
end
|
@@ -5,8 +5,20 @@ module LinkedRails
|
|
5
5
|
module Delta
|
6
6
|
include LinkedRails::Helpers::DeltaHelper
|
7
7
|
|
8
|
-
def changes_triples(resource)
|
8
|
+
def changes_triples(resource) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
|
9
9
|
resource_serializer(resource)&.send(:repository).statements
|
10
|
+
|
11
|
+
# resource.previous_changes_by_predicate.map do |predicate, (_old_value, _new_value)|
|
12
|
+
# serializer_attributes = resource.class.predicate_mapping[predicate]
|
13
|
+
# next if serializer_attributes.is_a?(FastJsonapi::Relationship)
|
14
|
+
#
|
15
|
+
# attr_name = serializer_attributes.key
|
16
|
+
# serialized_value =
|
17
|
+
# serializer.class.attributes_to_serialize[attr_name]&.serialize(resource, serializer_params, {})
|
18
|
+
# (serialized_value.is_a?(Array) ? serialized_value : [serialized_value]).map do |value|
|
19
|
+
# change_triple(resource, predicate, value)
|
20
|
+
# end
|
21
|
+
# end.compact.flatten
|
10
22
|
end
|
11
23
|
|
12
24
|
def changed_relations_triples(resource, inverted = nil) # rubocop:disable Metrics/AbcSize
|
@@ -23,6 +35,14 @@ module LinkedRails
|
|
23
35
|
|
24
36
|
private
|
25
37
|
|
38
|
+
def change_triple(resource, predicate, value)
|
39
|
+
if value.nil?
|
40
|
+
RDF::Statement.new(resource.iri, predicate, Vocab.sp[:Variable], graph_name: delta_iri(:remove))
|
41
|
+
else
|
42
|
+
RDF::Statement.new(resource.iri, predicate, value, graph_name: delta_iri(:replace))
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
26
46
|
def changed_relation_triples(predicate, destructed, resources, inverted)
|
27
47
|
related_resource_invalidations =
|
28
48
|
resources.flat_map do |resource|
|
@@ -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
|
@@ -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
|
|
@@ -22,6 +22,17 @@ module LinkedRails
|
|
22
22
|
end
|
23
23
|
end
|
24
24
|
|
25
|
+
def previous_changes_by_predicate
|
26
|
+
serializer_class = RDF::Serializers.serializer_for(self)
|
27
|
+
return {} unless respond_to?(:previous_changes) && serializer_class
|
28
|
+
|
29
|
+
Hash[
|
30
|
+
previous_changes
|
31
|
+
.map { |k, v| [self.class.predicate_for_key(k.to_sym), v] }
|
32
|
+
.select { |k, _v| k.present? }
|
33
|
+
]
|
34
|
+
end
|
35
|
+
|
25
36
|
def previously_changed_relations(inverted = nil)
|
26
37
|
serializer_class = RDF::Serializers.serializer_for(self)
|
27
38
|
return {} unless serializer_class.try(:relationships_to_serialize)
|
data/lib/linked_rails/model.rb
CHANGED
@@ -3,7 +3,8 @@
|
|
3
3
|
module LinkedRails
|
4
4
|
class ParamsParser # rubocop:disable Metrics/ClassLength
|
5
5
|
include ::Empathy::EmpJson::Helpers::Slices
|
6
|
-
include ::Empathy::EmpJson::Helpers::
|
6
|
+
include ::Empathy::EmpJson::Helpers::Primitives
|
7
|
+
include ::Empathy::EmpJson::Helpers::Values
|
7
8
|
|
8
9
|
attr_accessor :params, :slice, :user_context
|
9
10
|
delegate :filter_params, to: :collection_params_parser
|
@@ -62,11 +63,11 @@ module LinkedRails
|
|
62
63
|
def associated_class_from_params(reflection, object)
|
63
64
|
return reflection.klass unless reflection.polymorphic?
|
64
65
|
|
65
|
-
|
66
|
+
query = slice.query(subject: object, predicate: Vocab.rdfv[:type])
|
66
67
|
|
67
|
-
raise("No type given for '#{object}' referenced by polymorphic association '#{reflection.name}'") if
|
68
|
+
raise("No type given for '#{object}' referenced by polymorphic association '#{reflection.name}'") if query.empty?
|
68
69
|
|
69
|
-
iri_to_class(
|
70
|
+
iri_to_class(query.first.object)
|
70
71
|
end
|
71
72
|
|
72
73
|
def collection_params_parser
|
@@ -77,11 +78,11 @@ module LinkedRails
|
|
77
78
|
options = serializer_field(klass, predicate)
|
78
79
|
return unless value.count == 1 && options.present?
|
79
80
|
|
80
|
-
parsed_value = value.first.start_with?('http') ? RDF::URI(value.first) : value.first
|
81
|
+
parsed_value = value.first.start_with?('http') ? RDF::URI(value.first) : RDF::Literal(value.first)
|
81
82
|
parse_param(
|
82
83
|
klass,
|
83
84
|
options.predicate,
|
84
|
-
|
85
|
+
parsed_value
|
85
86
|
)
|
86
87
|
end
|
87
88
|
|
data/lib/linked_rails/policy.rb
CHANGED
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.g9b7bc9073
|
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-08-
|
11
|
+
date: 2022-08-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: active_response
|
@@ -26,20 +26,6 @@ dependencies:
|
|
26
26
|
version: 0.0.2
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: emp_json
|
29
|
-
requirement: !ruby/object:Gem::Requirement
|
30
|
-
requirements:
|
31
|
-
- - ">="
|
32
|
-
- !ruby/object:Gem::Version
|
33
|
-
version: 1.3.0
|
34
|
-
type: :runtime
|
35
|
-
prerelease: false
|
36
|
-
version_requirements: !ruby/object:Gem::Requirement
|
37
|
-
requirements:
|
38
|
-
- - ">="
|
39
|
-
- !ruby/object:Gem::Version
|
40
|
-
version: 1.3.0
|
41
|
-
- !ruby/object:Gem::Dependency
|
42
|
-
name: kaminari-activerecord
|
43
29
|
requirement: !ruby/object:Gem::Requirement
|
44
30
|
requirements:
|
45
31
|
- - ">="
|
@@ -53,7 +39,7 @@ dependencies:
|
|
53
39
|
- !ruby/object:Gem::Version
|
54
40
|
version: '0'
|
55
41
|
- !ruby/object:Gem::Dependency
|
56
|
-
name:
|
42
|
+
name: kaminari-activerecord
|
57
43
|
requirement: !ruby/object:Gem::Requirement
|
58
44
|
requirements:
|
59
45
|
- - ">="
|
@@ -67,7 +53,7 @@ dependencies:
|
|
67
53
|
- !ruby/object:Gem::Version
|
68
54
|
version: '0'
|
69
55
|
- !ruby/object:Gem::Dependency
|
70
|
-
name:
|
56
|
+
name: pundit
|
71
57
|
requirement: !ruby/object:Gem::Requirement
|
72
58
|
requirements:
|
73
59
|
- - ">="
|
@@ -299,10 +285,8 @@ files:
|
|
299
285
|
- app/policies/linked_rails/collection/view_policy.rb
|
300
286
|
- app/policies/linked_rails/collection_policy.rb
|
301
287
|
- app/policies/linked_rails/enum_value_policy.rb
|
302
|
-
- app/policies/linked_rails/form_policy.rb
|
303
288
|
- app/policies/linked_rails/menus/item_policy.rb
|
304
289
|
- app/policies/linked_rails/menus/list_policy.rb
|
305
|
-
- app/policies/linked_rails/ontology_policy.rb
|
306
290
|
- app/policies/linked_rails/sequence_policy.rb
|
307
291
|
- app/serializers/linked_rails/actions/item_serializer.rb
|
308
292
|
- app/serializers/linked_rails/actions/object_serializer.rb
|
@@ -340,7 +324,6 @@ files:
|
|
340
324
|
- app/serializers/linked_rails/web_page_serializer.rb
|
341
325
|
- app/serializers/linked_rails/web_site_serializer.rb
|
342
326
|
- app/serializers/linked_rails/widget_serializer.rb
|
343
|
-
- app/workers/linked_rails/invalidation_stream_worker.rb
|
344
327
|
- config/initializers/inflections.rb
|
345
328
|
- lib/generators/linked_rails/install/install_generator.rb
|
346
329
|
- lib/generators/linked_rails/install/templates/README
|
@@ -390,8 +373,6 @@ files:
|
|
390
373
|
- lib/linked_rails/enhancements/destroyable/controller.rb
|
391
374
|
- lib/linked_rails/enhancements/updatable/controller.rb
|
392
375
|
- lib/linked_rails/enhancements/updatable/serializer.rb
|
393
|
-
- lib/linked_rails/errors.rb
|
394
|
-
- lib/linked_rails/errors/forbidden.rb
|
395
376
|
- lib/linked_rails/helpers/delta_helper.rb
|
396
377
|
- lib/linked_rails/helpers/ontola_actions_helper.rb
|
397
378
|
- lib/linked_rails/helpers/resource_helper.rb
|
@@ -400,7 +381,6 @@ files:
|
|
400
381
|
- lib/linked_rails/middleware/linked_data_params.rb
|
401
382
|
- lib/linked_rails/model.rb
|
402
383
|
- lib/linked_rails/model/actionable.rb
|
403
|
-
- lib/linked_rails/model/cacheable.rb
|
404
384
|
- lib/linked_rails/model/collections.rb
|
405
385
|
- lib/linked_rails/model/dirty.rb
|
406
386
|
- lib/linked_rails/model/enhancements.rb
|
@@ -424,12 +404,10 @@ files:
|
|
424
404
|
- lib/linked_rails/serializer/actionable.rb
|
425
405
|
- lib/linked_rails/serializer/menuable.rb
|
426
406
|
- lib/linked_rails/serializer/singularable.rb
|
427
|
-
- lib/linked_rails/storage.rb
|
428
407
|
- lib/linked_rails/test_methods.rb
|
429
408
|
- lib/linked_rails/translate.rb
|
430
409
|
- lib/linked_rails/types/iri_type.rb
|
431
410
|
- lib/linked_rails/uri_template.rb
|
432
|
-
- lib/linked_rails/url.rb
|
433
411
|
- lib/linked_rails/version.rb
|
434
412
|
- lib/linked_rails/vocab.rb
|
435
413
|
- 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
|