linked_rails 0.0.1 → 0.0.4.pre.g1faca9643
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/LICENSE +21 -674
- data/app/controllers/linked_rails/actions/objects_controller.rb +9 -0
- data/app/controllers/linked_rails/bulk_controller.rb +105 -22
- data/app/controllers/linked_rails/enum_values_controller.rb +0 -42
- data/app/models/linked_rails/actions/item.rb +64 -55
- data/app/models/linked_rails/actions/list.rb +6 -31
- data/app/models/linked_rails/actions/object.rb +38 -0
- data/app/models/linked_rails/collection/configuration.rb +55 -0
- data/app/models/linked_rails/collection/filter.rb +1 -1
- data/app/models/linked_rails/collection/filter_field.rb +19 -2
- data/app/models/linked_rails/collection/filter_option.rb +1 -1
- data/app/models/linked_rails/collection/filterable.rb +6 -9
- data/app/models/linked_rails/collection/infinite.rb +113 -0
- data/app/models/linked_rails/collection/infinite_view.rb +1 -90
- data/app/models/linked_rails/collection/iri.rb +47 -43
- data/app/models/linked_rails/collection/iri_mapping.rb +15 -7
- data/app/models/linked_rails/collection/paginated.rb +46 -0
- data/app/models/linked_rails/collection/paginated_view.rb +1 -33
- data/app/models/linked_rails/collection/sortable.rb +1 -9
- data/app/models/linked_rails/collection/sorting.rb +1 -1
- data/app/models/linked_rails/collection/view.rb +51 -14
- data/app/models/linked_rails/collection.rb +53 -85
- data/app/models/linked_rails/creative_work.rb +1 -1
- data/app/models/linked_rails/entry_point.rb +8 -5
- data/app/models/linked_rails/enum_value.rb +40 -2
- data/app/models/linked_rails/form/field/association_input.rb +7 -1
- data/app/models/linked_rails/form/field/file_input.rb +1 -0
- data/app/models/linked_rails/form/field/resource_field.rb +2 -0
- data/{lib/linked_rails/enhancements/indexable/model.rb → app/models/linked_rails/form/field/url_input.rb} +3 -3
- data/app/models/linked_rails/form/field.rb +37 -13
- data/app/models/linked_rails/form/field_factory.rb +48 -18
- data/app/models/linked_rails/form/group.rb +4 -6
- data/app/models/linked_rails/form/page.rb +8 -4
- data/app/models/linked_rails/form.rb +17 -21
- data/app/models/linked_rails/manifest.rb +102 -22
- data/app/models/linked_rails/menus/item.rb +10 -13
- data/app/models/linked_rails/menus/list.rb +16 -7
- data/app/models/linked_rails/ontology/base.rb +3 -1
- data/app/models/linked_rails/ontology/class.rb +3 -3
- data/app/models/linked_rails/ontology.rb +6 -5
- data/app/models/linked_rails/property_query.rb +2 -0
- data/app/models/linked_rails/sequence.rb +4 -13
- data/app/models/linked_rails/shacl/property_shape.rb +1 -1
- data/app/models/linked_rails/web_page.rb +0 -4
- data/app/models/linked_rails/web_site.rb +0 -4
- data/app/models/linked_rails/widget.rb +4 -11
- data/app/policies/linked_rails/actions/object_policy.rb +11 -0
- data/app/policies/linked_rails/collection_policy.rb +2 -2
- data/app/policies/linked_rails/form_policy.rb +13 -0
- data/app/policies/linked_rails/ontology_policy.rb +13 -0
- data/app/serializers/linked_rails/actions/item_serializer.rb +5 -5
- data/app/serializers/linked_rails/actions/object_serializer.rb +9 -0
- data/app/serializers/linked_rails/collection/filter_field_serializer.rb +3 -2
- data/app/serializers/linked_rails/collection/filter_option_serializer.rb +1 -1
- data/app/serializers/linked_rails/collection/filter_serializer.rb +1 -1
- data/app/serializers/linked_rails/collection/sorting_serializer.rb +1 -1
- data/app/serializers/linked_rails/collection/view_serializer.rb +3 -3
- data/app/serializers/linked_rails/collection_serializer.rb +8 -7
- data/app/serializers/linked_rails/condition_serializer.rb +3 -3
- data/app/serializers/linked_rails/entry_point_serializer.rb +3 -3
- data/app/serializers/linked_rails/enum_value_serializer.rb +1 -0
- data/app/serializers/linked_rails/form/field/association_input_serializer.rb +1 -0
- data/app/serializers/linked_rails/form/field/file_input_serializer.rb +11 -0
- data/app/serializers/linked_rails/form/field_serializer.rb +3 -1
- data/app/serializers/linked_rails/form/group_serializer.rb +1 -1
- data/app/serializers/linked_rails/form/page_serializer.rb +1 -1
- data/app/serializers/linked_rails/menus/item_serializer.rb +3 -3
- data/app/serializers/linked_rails/menus/list_serializer.rb +1 -1
- data/app/serializers/linked_rails/ontology_serializer.rb +2 -2
- data/app/serializers/linked_rails/property_query_serializer.rb +7 -0
- data/app/serializers/linked_rails/sequence_serializer.rb +2 -5
- data/app/serializers/linked_rails/shacl/node_shape_serializer.rb +1 -1
- data/app/serializers/linked_rails/shacl/property_shape_serializer.rb +1 -1
- data/app/serializers/linked_rails/shacl/shape_serializer.rb +5 -5
- data/app/serializers/linked_rails/web_page_serializer.rb +3 -3
- data/app/serializers/linked_rails/web_site_serializer.rb +1 -1
- data/app/serializers/linked_rails/widget_serializer.rb +3 -3
- data/app/workers/linked_rails/invalidation_stream_worker.rb +16 -0
- data/lib/generators/linked_rails/install/install_generator.rb +7 -8
- data/lib/generators/linked_rails/install/templates/README +7 -0
- data/lib/generators/linked_rails/install/templates/app_menu_list.rb +36 -7
- data/lib/generators/linked_rails/install/templates/application_menu_list.rb +40 -1
- data/lib/generators/linked_rails/install/templates/initializer.rb +1 -2
- data/lib/generators/linked_rails/install/templates/locales.yml +16 -0
- data/lib/generators/linked_rails/install/templates/rdf_serializers_initializer.rb +1 -1
- data/lib/generators/linked_rails/install/templates/vocab.rb +1 -0
- data/lib/generators/linked_rails/install/templates/vocab.yml +2 -2
- data/lib/generators/linked_rails/model/model_generator.rb +0 -1
- data/lib/generators/linked_rails/model/templates/controller.rb.tt +5 -1
- data/lib/generators/linked_rails/model/templates/form.rb.tt +3 -0
- data/lib/generators/linked_rails/model/templates/menu_list.rb.tt +15 -0
- data/lib/generators/linked_rails/model/templates/policy.rb.tt +13 -0
- data/lib/generators/linked_rails/model/templates/serializer.rb.tt +5 -1
- data/lib/linked_rails/active_response/controller/collections.rb +1 -1
- data/lib/linked_rails/active_response/controller/crud_defaults.rb +4 -4
- data/lib/linked_rails/active_response/controller/params.rb +10 -10
- data/lib/linked_rails/active_response/controller.rb +8 -18
- data/lib/linked_rails/active_response/responders/rdf.rb +19 -10
- data/lib/linked_rails/callable_variable.rb +1 -1
- data/lib/linked_rails/collection_params_parser.rb +93 -0
- data/lib/linked_rails/controller/actionable.rb +121 -0
- data/lib/linked_rails/controller/authorization.rb +6 -0
- data/lib/linked_rails/controller/default_actions/create.rb +52 -0
- data/lib/linked_rails/controller/default_actions/destroy.rb +42 -0
- data/lib/linked_rails/controller/default_actions/update.rb +43 -0
- data/lib/linked_rails/controller/delta.rb +58 -0
- data/lib/linked_rails/controller/error_handling.rb +14 -7
- data/lib/linked_rails/controller/rendering.rb +48 -0
- data/lib/linked_rails/controller.rb +24 -4
- data/lib/linked_rails/enhanceable.rb +1 -1
- data/lib/linked_rails/enhancements/creatable/controller.rb +1 -1
- data/lib/linked_rails/enhancements/destroyable/controller.rb +1 -1
- data/lib/linked_rails/enhancements/updatable/controller.rb +1 -1
- data/lib/linked_rails/enhancements.rb +0 -16
- data/lib/linked_rails/errors/forbidden.rb +37 -0
- data/lib/linked_rails/errors.rb +3 -0
- data/lib/linked_rails/helpers/delta_helper.rb +26 -57
- data/lib/linked_rails/helpers/ontola_actions_helper.rb +2 -2
- data/lib/linked_rails/helpers/resource_helper.rb +11 -2
- data/lib/linked_rails/iri_mapper.rb +17 -39
- data/lib/linked_rails/middleware/error_handling.rb +51 -0
- data/lib/linked_rails/middleware/linked_data_params.rb +30 -151
- data/lib/linked_rails/model/actionable.rb +68 -0
- data/lib/linked_rails/model/cacheable.rb +45 -0
- data/lib/linked_rails/model/collections.rb +201 -39
- data/lib/linked_rails/model/dirty.rb +6 -18
- data/lib/linked_rails/model/enhancements.rb +1 -6
- data/lib/linked_rails/model/filtering.rb +4 -6
- data/lib/linked_rails/model/indexable.rb +6 -16
- data/lib/linked_rails/model/iri.rb +29 -19
- data/lib/linked_rails/model/iri_mapping.rb +37 -8
- data/lib/linked_rails/model/menuable.rb +28 -0
- data/lib/linked_rails/model/serialization.rb +2 -15
- data/lib/linked_rails/model/singularable.rb +57 -0
- data/lib/linked_rails/model/sorting.rb +0 -5
- data/lib/linked_rails/model/tables.rb +26 -0
- data/lib/linked_rails/model.rb +18 -7
- data/lib/linked_rails/params_parser.rb +131 -54
- data/lib/linked_rails/policy/attribute_conditions.rb +2 -2
- data/lib/linked_rails/policy.rb +44 -46
- data/lib/linked_rails/railtie.rb +11 -0
- data/lib/linked_rails/rdf_error.rb +2 -2
- data/lib/linked_rails/renderers.rb +1 -0
- data/lib/linked_rails/routes.rb +38 -22
- data/lib/linked_rails/serializer/actionable.rb +27 -0
- data/lib/linked_rails/serializer/menuable.rb +31 -0
- data/lib/linked_rails/serializer/singularable.rb +26 -0
- data/lib/linked_rails/serializer.rb +28 -11
- data/lib/linked_rails/storage.rb +32 -0
- data/lib/linked_rails/test_methods.rb +114 -0
- data/lib/linked_rails/translate.rb +31 -9
- data/lib/linked_rails/types/iri_type.rb +37 -0
- data/lib/linked_rails/uri_template.rb +30 -0
- data/lib/linked_rails/url.rb +11 -0
- data/lib/linked_rails/version.rb +1 -1
- data/lib/linked_rails/vocab.rb +9 -0
- data/lib/linked_rails.rb +40 -14
- data/lib/rails/welcome_controller.rb +3 -2
- data/lib/rdf/list.rb +9 -0
- data/lib/rdf/query_fix.rb +15 -0
- metadata +80 -33
- data/app/models/linked_rails/actions/default_actions/create.rb +0 -60
- data/app/models/linked_rails/actions/default_actions/destroy.rb +0 -45
- data/app/models/linked_rails/actions/default_actions/update.rb +0 -50
- data/app/models/linked_rails/actions/default_actions.rb +0 -17
- data/lib/generators/linked_rails/install/templates/application_action_list.rb +0 -3
- data/lib/generators/linked_rails/model/templates/action_list.rb.tt +0 -6
- data/lib/linked_rails/enhancements/actionable/model.rb +0 -71
- data/lib/linked_rails/enhancements/actionable/serializer.rb +0 -25
- data/lib/linked_rails/enhancements/creatable/action.rb +0 -15
- data/lib/linked_rails/enhancements/destroyable/action.rb +0 -15
- data/lib/linked_rails/enhancements/destroyable/routing.rb +0 -19
- data/lib/linked_rails/enhancements/menuable/model.rb +0 -36
- data/lib/linked_rails/enhancements/menuable/serializer.rb +0 -33
- data/lib/linked_rails/enhancements/route_concerns.rb +0 -56
- data/lib/linked_rails/enhancements/singularable/controller.rb +0 -43
- data/lib/linked_rails/enhancements/singularable/model.rb +0 -47
- data/lib/linked_rails/enhancements/singularable/serializer.rb +0 -28
- data/lib/linked_rails/enhancements/tableable/model.rb +0 -28
- data/lib/linked_rails/enhancements/updatable/action.rb +0 -15
- data/lib/linked_rails/enhancements/updatable/routing.rb +0 -20
@@ -8,29 +8,58 @@ class AppMenuList < ApplicationMenuList
|
|
8
8
|
menus: -> { user_menu_items }
|
9
9
|
|
10
10
|
def iri_template
|
11
|
-
@iri_template ||= URITemplate.new('/menus{#fragment}')
|
11
|
+
@iri_template ||= LinkedRails::URITemplate.new('/menus{#fragment}')
|
12
12
|
end
|
13
13
|
|
14
14
|
private
|
15
15
|
|
16
|
-
def
|
17
|
-
|
18
|
-
items << menu_item(
|
16
|
+
def home_menu_item
|
17
|
+
menu_item(
|
19
18
|
:home,
|
20
19
|
label: I18n.t('menus.home'),
|
21
20
|
href: LinkedRails.iri,
|
22
21
|
image: 'fa-home'
|
23
22
|
)
|
24
|
-
|
23
|
+
end
|
24
|
+
|
25
|
+
def navigation_links
|
26
|
+
[home_menu_item]
|
25
27
|
end
|
26
28
|
|
27
29
|
def user_menu_items
|
28
30
|
return [] if user_context.guest?
|
29
31
|
|
30
|
-
[
|
32
|
+
[
|
33
|
+
otp_menu_item,
|
34
|
+
sign_out_menu_item
|
35
|
+
]
|
36
|
+
end
|
37
|
+
|
38
|
+
def otp_menu_item
|
39
|
+
if user_context.otp_active?
|
40
|
+
delete_otp_menu_item
|
41
|
+
else
|
42
|
+
add_otp_menu_item
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def delete_otp_menu_item
|
47
|
+
menu_item(
|
48
|
+
:otp,
|
49
|
+
label: I18n.t('menus.delete_otp'),
|
50
|
+
href: LinkedRails.iri(path: 'u/otp_secret/delete')
|
51
|
+
)
|
52
|
+
end
|
53
|
+
|
54
|
+
def add_otp_menu_item
|
55
|
+
menu_item(
|
56
|
+
:otp,
|
57
|
+
label: I18n.t('menus.add_otp'),
|
58
|
+
href: LinkedRails.iri(path: 'u/otp_secret/new')
|
59
|
+
)
|
31
60
|
end
|
32
61
|
|
33
|
-
def
|
62
|
+
def sign_out_menu_item
|
34
63
|
menu_item(
|
35
64
|
:signout,
|
36
65
|
action: Vocab.libro['actions/logout'],
|
@@ -1,3 +1,42 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
class ApplicationMenuList < LinkedRails::Menus::List
|
3
|
+
class ApplicationMenuList < LinkedRails::Menus::List
|
4
|
+
include LinkedRails::Helpers::OntolaActionsHelper
|
5
|
+
|
6
|
+
private
|
7
|
+
|
8
|
+
def copy_menu_item(url)
|
9
|
+
menu_item(
|
10
|
+
:copy,
|
11
|
+
action: ontola_copy_action(url),
|
12
|
+
item_type: 'copy',
|
13
|
+
image: 'fa-clipboard',
|
14
|
+
href: url
|
15
|
+
)
|
16
|
+
end
|
17
|
+
|
18
|
+
def delete_menu_item(resource)
|
19
|
+
iri = resource.iri.dup
|
20
|
+
iri.path += '/delete'
|
21
|
+
|
22
|
+
menu_item(
|
23
|
+
:destroy,
|
24
|
+
action: ontola_dialog_action(iri),
|
25
|
+
href: iri,
|
26
|
+
image: 'fa-close',
|
27
|
+
policy: :destroy?
|
28
|
+
)
|
29
|
+
end
|
30
|
+
|
31
|
+
def edit_menu_item(resource)
|
32
|
+
iri = resource.iri.dup
|
33
|
+
iri.path += '/edit'
|
34
|
+
|
35
|
+
menu_item(
|
36
|
+
:edit,
|
37
|
+
image: 'fa-edit',
|
38
|
+
href: iri,
|
39
|
+
policy: :update?
|
40
|
+
)
|
41
|
+
end
|
42
|
+
end
|
@@ -2,8 +2,7 @@
|
|
2
2
|
|
3
3
|
require_relative '../../lib/vocab'
|
4
4
|
|
5
|
-
LinkedRails.host = '
|
5
|
+
LinkedRails.host = raise('Enter your host. Use an ENV var if you have multiple environments')
|
6
6
|
LinkedRails.scheme = :https
|
7
|
-
LinkedRails.app_vocab = Vocab.example
|
8
7
|
|
9
8
|
LinkedRails::Renderers.register!
|
@@ -1,4 +1,18 @@
|
|
1
1
|
en:
|
2
|
+
actions:
|
3
|
+
default:
|
4
|
+
create:
|
5
|
+
label: "New %{type}"
|
6
|
+
success: 'Created successfully'
|
7
|
+
destroy:
|
8
|
+
label: "Delete"
|
9
|
+
description: "Are you sure you want to delete this %{type}?"
|
10
|
+
success: 'Destroyed successfully'
|
11
|
+
update:
|
12
|
+
label: "Edit"
|
13
|
+
success: 'Updated successfully'
|
14
|
+
errors:
|
15
|
+
access_denied: "You're not authorized for this action. (%{action})"
|
2
16
|
linked_rails:
|
3
17
|
status:
|
4
18
|
400: "Error in request"
|
@@ -10,3 +24,5 @@ en:
|
|
10
24
|
menus:
|
11
25
|
home: "Home"
|
12
26
|
sign_out: "Sign out"
|
27
|
+
add_otp: "Enable 2fa"
|
28
|
+
delete_otp: "Remove 2fa"
|
@@ -17,7 +17,6 @@ module LinkedRails
|
|
17
17
|
end
|
18
18
|
|
19
19
|
def copy_files # rubocop:disable Metrics/AbcSize
|
20
|
-
template 'action_list.rb', File.join('app', 'actions', class_path, "#{file_name}_action_list.rb")
|
21
20
|
template 'controller.rb', File.join('app', 'controllers', class_path, "#{plural_file_name}_controller.rb")
|
22
21
|
template 'form.rb', File.join('app', 'forms', class_path, "#{file_name}_form.rb")
|
23
22
|
template 'menu_list.rb', File.join('app', 'menus', class_path, "#{file_name}_menu_list.rb")
|
@@ -2,6 +2,10 @@
|
|
2
2
|
|
3
3
|
<% module_namespacing do -%>
|
4
4
|
class <%= controller_class_name %>Controller < ApplicationController
|
5
|
-
|
5
|
+
active_response :show, :index
|
6
|
+
|
7
|
+
has_collection_create_action
|
8
|
+
has_resource_update_action
|
9
|
+
has_resource_destroy_action
|
6
10
|
end
|
7
11
|
<% end -%>
|
@@ -2,5 +2,20 @@
|
|
2
2
|
|
3
3
|
<% module_namespacing do -%>
|
4
4
|
class <%= class_name %>MenuList < ApplicationMenuList
|
5
|
+
has_menu(
|
6
|
+
:actions,
|
7
|
+
image: 'fa-ellipsis-v',
|
8
|
+
menus: -> { action_menu_items }
|
9
|
+
)
|
10
|
+
|
11
|
+
private
|
12
|
+
|
13
|
+
def action_menu_items
|
14
|
+
[
|
15
|
+
edit_menu_item(resource),
|
16
|
+
delete_menu_item(resource),
|
17
|
+
copy_menu_item(resource.iri),
|
18
|
+
]
|
19
|
+
end
|
5
20
|
end
|
6
21
|
<% end -%>
|
@@ -2,5 +2,18 @@
|
|
2
2
|
|
3
3
|
<% module_namespacing do -%>
|
4
4
|
class <%= class_name %>Policy < ApplicationPolicy
|
5
|
+
permit_attributes %i[<%= attributes.reject(&:reference?).map { |attribute| attribute.name }.join(' ') %>]
|
6
|
+
|
7
|
+
def create?
|
8
|
+
false
|
9
|
+
end
|
10
|
+
|
11
|
+
def update?
|
12
|
+
false
|
13
|
+
end
|
14
|
+
|
15
|
+
def destroy?
|
16
|
+
false
|
17
|
+
end
|
5
18
|
end
|
6
19
|
<% end -%>
|
@@ -3,7 +3,11 @@
|
|
3
3
|
<% module_namespacing do -%>
|
4
4
|
class <%= class_name %>Serializer < ApplicationSerializer
|
5
5
|
<% attributes.each do |attribute| -%>
|
6
|
-
|
6
|
+
<% if attribute.reference? -%>
|
7
|
+
has_one :<%= attribute.name %>, predicate: Vocab.app[:<%= attribute.name.camelize(:lower) %>]
|
8
|
+
<% else -%>
|
9
|
+
attribute :<%= attribute.name %>, predicate: Vocab.app[:<%= attribute.name.camelize(:lower) %>]
|
10
|
+
<% end -%>
|
7
11
|
<% end -%>
|
8
12
|
end
|
9
13
|
<% end -%>
|
@@ -10,8 +10,8 @@ module LinkedRails
|
|
10
10
|
current_resource!
|
11
11
|
.class
|
12
12
|
.try(:reflect_on_all_associations)
|
13
|
-
|
14
|
-
|
13
|
+
&.select(&:collection?)
|
14
|
+
&.each { |association| current_resource!.association(association.name).reset }
|
15
15
|
end
|
16
16
|
|
17
17
|
def create_execute
|
@@ -50,7 +50,7 @@ module LinkedRails
|
|
50
50
|
def requested_resource
|
51
51
|
@requested_resource ||= controller_class.try(
|
52
52
|
:requested_resource,
|
53
|
-
LinkedRails.iri_mapper.route_params_to_opts(params.dup),
|
53
|
+
LinkedRails.iri_mapper.route_params_to_opts(params.dup, request.original_url),
|
54
54
|
user_context
|
55
55
|
)
|
56
56
|
end
|
@@ -80,7 +80,7 @@ module LinkedRails
|
|
80
80
|
end
|
81
81
|
|
82
82
|
def update_meta
|
83
|
-
changes_triples + changed_relations_triples
|
83
|
+
changes_triples(current_resource) + changed_relations_triples(current_resource)
|
84
84
|
end
|
85
85
|
|
86
86
|
def user_context
|
@@ -11,17 +11,13 @@ module LinkedRails
|
|
11
11
|
end
|
12
12
|
|
13
13
|
def params_parser
|
14
|
-
@params_parser ||= LinkedRails::ParamsParser.new(params)
|
15
|
-
end
|
16
|
-
|
17
|
-
def parsed_filter_params
|
18
|
-
filters = params_parser.filter_params
|
19
|
-
|
20
|
-
ActionController::Parameters.new(controller_class.try(:attributes_from_filters, filters) || {})
|
14
|
+
@params_parser ||= LinkedRails::ParamsParser.new(params: params, user_context: user_context)
|
21
15
|
end
|
22
16
|
|
23
17
|
def permit_filter_params
|
24
|
-
@permit_filter_params ||=
|
18
|
+
@permit_filter_params ||=
|
19
|
+
policy(requested_resource || new_resource)
|
20
|
+
.permitted_attributes_from_filters(params_parser.filter_params)
|
25
21
|
end
|
26
22
|
|
27
23
|
def permit_params
|
@@ -37,11 +33,15 @@ module LinkedRails
|
|
37
33
|
end
|
38
34
|
|
39
35
|
def permit_params_with_filters
|
40
|
-
permit_filter_params.merge(permit_params.to_h)
|
36
|
+
permitted = permit_filter_params.merge(permit_params.to_h)
|
37
|
+
permitted[:singular_resource] = true if params[:singular_route].to_s == 'true'
|
38
|
+
permitted
|
41
39
|
end
|
42
40
|
|
43
41
|
def resource_params
|
44
|
-
|
42
|
+
empty_params = !params.key?(permit_param_key) || params[permit_param_key] == {}
|
43
|
+
|
44
|
+
return ActionController::Parameters.new if empty_params && allow_empty_params?
|
45
45
|
|
46
46
|
params.require(permit_param_key)
|
47
47
|
end
|
@@ -8,30 +8,20 @@ require_relative 'controller/params'
|
|
8
8
|
|
9
9
|
module LinkedRails
|
10
10
|
module Controller
|
11
|
-
include Pundit
|
11
|
+
include Pundit::Authorization
|
12
12
|
include LinkedRails::ActiveResponse::Controller::Collections
|
13
13
|
include LinkedRails::ActiveResponse::Controller::CrudDefaults
|
14
14
|
include LinkedRails::ActiveResponse::Controller::Params
|
15
15
|
|
16
|
-
def
|
17
|
-
|
18
|
-
|
19
|
-
return record if record.is_a?(String)
|
20
|
-
return record.to_json if record.is_a?(Hash)
|
21
|
-
|
22
|
-
serializer_opts = RDF::Serializers::Renderers.transform_opts(
|
23
|
-
options,
|
24
|
-
serializer_params
|
25
|
-
)
|
26
|
-
|
27
|
-
serializer = RDF::Serializers.serializer_for(record)&.new(record, serializer_opts)
|
28
|
-
return record.to_json unless serializer
|
29
|
-
|
30
|
-
Oj.dump(serializer.serializable_hash, mode: :compat)
|
16
|
+
def success_message_translation_key
|
17
|
+
"actions.#{Translate.translation_key(controller_class)}.#{action_name}.success"
|
31
18
|
end
|
32
19
|
|
33
|
-
def
|
34
|
-
{
|
20
|
+
def success_message_translation_opts
|
21
|
+
{
|
22
|
+
default: [:"actions.default.#{action_name}.success", ''],
|
23
|
+
type: I18n.t("#{controller_class.model_name.collection}.type").capitalize
|
24
|
+
}
|
35
25
|
end
|
36
26
|
end
|
37
27
|
end
|
@@ -37,7 +37,7 @@ module LinkedRails
|
|
37
37
|
response_headers(opts)
|
38
38
|
controller.respond_with_resource(
|
39
39
|
resource: nil,
|
40
|
-
meta: error_meta(opts[:resource]),
|
40
|
+
meta: error_meta(opts[:resource], opts[:errors] || {}),
|
41
41
|
status: :unprocessable_entity
|
42
42
|
)
|
43
43
|
end
|
@@ -47,15 +47,22 @@ module LinkedRails
|
|
47
47
|
controller.respond_with_resource(opts)
|
48
48
|
end
|
49
49
|
|
50
|
-
def redirect(**opts) # rubocop:disable Metrics/AbcSize
|
50
|
+
def redirect(**opts) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
|
51
51
|
return super if controller.request.head?
|
52
52
|
|
53
|
+
opts[:status] ||= 200
|
54
|
+
|
53
55
|
response_headers(opts)
|
54
56
|
add_exec_action_header(
|
55
57
|
controller.response.headers,
|
56
58
|
ontola_redirect_action(opts[:location], reload: opts[:reload])
|
57
59
|
)
|
58
|
-
|
60
|
+
if opts[:meta].blank? || head_request?
|
61
|
+
controller.head(opts[:status], location: opts[:location], content_type: content_type)
|
62
|
+
else
|
63
|
+
opts[format] = []
|
64
|
+
controller.render opts
|
65
|
+
end
|
59
66
|
end
|
60
67
|
|
61
68
|
def resource(**opts) # rubocop:disable Metrics/AbcSize
|
@@ -89,10 +96,10 @@ module LinkedRails
|
|
89
96
|
]
|
90
97
|
end
|
91
98
|
|
92
|
-
def error_statements(iri, resource)
|
99
|
+
def error_statements(iri, resource, resource_errors)
|
93
100
|
index = 0
|
94
|
-
|
95
|
-
predicate = resource
|
101
|
+
resource_errors.map do |key, values|
|
102
|
+
predicate = resource&.class&.predicate_for_key(key.to_s.split('.').first)
|
96
103
|
if predicate
|
97
104
|
error_statements_for(iri, predicate, values)
|
98
105
|
else
|
@@ -106,16 +113,18 @@ module LinkedRails
|
|
106
113
|
values.map { |value| [iri, predicate, value.sub(/\S/, &:upcase)] }
|
107
114
|
end
|
108
115
|
|
109
|
-
def error_meta(resource)
|
116
|
+
def error_meta(resource, custom_errors)
|
110
117
|
form_iri = controller.request.headers['Request-Referrer']
|
111
|
-
|
118
|
+
resource_errors = (resource.try(:errors)&.messages || {}).merge(custom_errors)
|
119
|
+
|
120
|
+
return [] unless form_iri && resource_errors.present?
|
112
121
|
|
113
122
|
error_object = ::RDF::Node.new
|
114
123
|
[
|
115
124
|
error_mapping(form_iri, error_object),
|
116
125
|
error_type(error_object),
|
117
126
|
error_status(error_object)
|
118
|
-
] + error_statements(error_object, resource)
|
127
|
+
] + error_statements(error_object, resource, resource_errors)
|
119
128
|
end
|
120
129
|
|
121
130
|
def error_type(error_object)
|
@@ -149,7 +158,7 @@ module LinkedRails
|
|
149
158
|
error_statements_for(
|
150
159
|
iri,
|
151
160
|
::RDF["_#{index}"],
|
152
|
-
values.map { |value| resource
|
161
|
+
values.map { |value| resource&.errors&.full_message(key, value) || value }
|
153
162
|
)
|
154
163
|
end
|
155
164
|
end
|
@@ -5,7 +5,7 @@ module LinkedRails
|
|
5
5
|
extend ActiveSupport::Concern
|
6
6
|
|
7
7
|
module ClassMethods
|
8
|
-
def callable_variable(method, opts
|
8
|
+
def callable_variable(method, **opts) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
|
9
9
|
variable ||= opts[:variable] || method
|
10
10
|
default ||= opts[:default]
|
11
11
|
|
@@ -0,0 +1,93 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module LinkedRails
|
4
|
+
class CollectionParamsParser
|
5
|
+
attr_reader :params, :user_context
|
6
|
+
|
7
|
+
def initialize(params)
|
8
|
+
@user_context = params[:user_context]
|
9
|
+
@params = params.is_a?(Hash) ? ActionController::Parameters.new(params) : params
|
10
|
+
end
|
11
|
+
|
12
|
+
def collection_params
|
13
|
+
return @collection_params if instance_variable_defined?(:@collection_params)
|
14
|
+
|
15
|
+
values = permit_params(:display, :page_size, :table_type, :title, :type)
|
16
|
+
|
17
|
+
filter = filter_params
|
18
|
+
values[:filter] = filter if filter
|
19
|
+
|
20
|
+
sort = sorting_params
|
21
|
+
values[:sort] = sort if sort
|
22
|
+
|
23
|
+
values[:user_context] = user_context if user_context
|
24
|
+
|
25
|
+
@collection_params = values
|
26
|
+
end
|
27
|
+
|
28
|
+
def collection_view_params
|
29
|
+
return @collection_view_params if instance_variable_defined?(:@collection_view_params)
|
30
|
+
|
31
|
+
values = permit_params(:page)
|
32
|
+
|
33
|
+
before = before_params
|
34
|
+
values[:before] = before if before
|
35
|
+
|
36
|
+
@collection_view_params = values
|
37
|
+
end
|
38
|
+
|
39
|
+
def filter_params # rubocop:disable Metrics/AbcSize
|
40
|
+
return @filter_params if instance_variable_defined?(:@filter_params)
|
41
|
+
|
42
|
+
values = permit_params(filter: [])[:filter] || permit_params(filter: {})[:filter]
|
43
|
+
return @filter_params = values if values.is_a?(Hash)
|
44
|
+
return @filter_params = {} if values.blank?
|
45
|
+
|
46
|
+
@filter_params = values.each_with_object({}) do |f, hash|
|
47
|
+
values = f.split('=')
|
48
|
+
key = RDF::URI(CGI.unescape(values.first))
|
49
|
+
hash[key] ||= []
|
50
|
+
hash[key] << CGI.unescape(values.second)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
private
|
55
|
+
|
56
|
+
def before_params
|
57
|
+
return @before_params if instance_variable_defined?(:@before_params)
|
58
|
+
|
59
|
+
values = permit_params(before: [])[:before]
|
60
|
+
return @before_params = nil if values.blank?
|
61
|
+
|
62
|
+
@before_params = values.map do |f|
|
63
|
+
key, value = f.split('=')
|
64
|
+
{key: RDF::URI(CGI.unescape(key)), value: value}
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
def parse_filter_value(value)
|
69
|
+
return value if value.is_a?(Hash)
|
70
|
+
|
71
|
+
key, value = value.split('=')
|
72
|
+
{key: RDF::URI(CGI.unescape(key)), direction: value}
|
73
|
+
end
|
74
|
+
|
75
|
+
def permit_params(*keys)
|
76
|
+
params
|
77
|
+
.permit(*keys)
|
78
|
+
.to_h
|
79
|
+
.with_indifferent_access
|
80
|
+
end
|
81
|
+
|
82
|
+
def sorting_params
|
83
|
+
return @sorting_params if instance_variable_defined?(:@sorting_params)
|
84
|
+
|
85
|
+
values = permit_params(sort: [])[:sort]
|
86
|
+
return @sorting_params = nil if values.blank?
|
87
|
+
|
88
|
+
@sorting_params = values.map do |f|
|
89
|
+
parse_filter_value(f)
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|