reactiveadmin 0.2.0
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 +7 -0
- data/CHANGELOG.md +88 -0
- data/LICENSE +21 -0
- data/README.md +81 -0
- data/app/assets/reactive_admin/bridge.js +89 -0
- data/app/controllers/reactive_admin/api_controller.rb +30 -0
- data/app/controllers/reactive_admin/client_errors_controller.rb +38 -0
- data/app/controllers/reactive_admin/manifest_controller.rb +10 -0
- data/app/controllers/reactive_admin/mcp_controller.rb +48 -0
- data/app/controllers/reactive_admin/openapi_controller.rb +13 -0
- data/app/controllers/reactive_admin/session_controller.rb +11 -0
- data/app/views/layouts/reactive_admin/embed.html.erb +30 -0
- data/lib/generators/reactiveadmin/install/install_generator.rb +341 -0
- data/lib/generators/reactiveadmin/install/templates/menu.rb.tt +25 -0
- data/lib/generators/reactiveadmin/install/templates/reactive_admin.rb.tt +53 -0
- data/lib/generators/reactiveadmin/install/templates/reactive_admin_annotated.rb.tt +110 -0
- data/lib/reactive_admin/aa/v3/controller.rb +76 -0
- data/lib/reactive_admin/aa/v3/forms.rb +29 -0
- data/lib/reactive_admin/aa/v3/inputs/filters/typeahead_input.rb +51 -0
- data/lib/reactive_admin/aa/v3/inputs/typeahead_input.rb +8 -0
- data/lib/reactive_admin/aa/v3/install.rb +36 -0
- data/lib/reactive_admin/aa/v3/menu.rb +67 -0
- data/lib/reactive_admin/aa/v3/presenters.rb +102 -0
- data/lib/reactive_admin/aa/v3/registry.rb +78 -0
- data/lib/reactive_admin/aa/v3/views.rb +63 -0
- data/lib/reactive_admin/aa/v3.rb +23 -0
- data/lib/reactive_admin/aa/v4.rb +59 -0
- data/lib/reactive_admin/aa.rb +46 -0
- data/lib/reactive_admin/action_items.rb +39 -0
- data/lib/reactive_admin/action_links.rb +197 -0
- data/lib/reactive_admin/action_safety.rb +19 -0
- data/lib/reactive_admin/actions.rb +95 -0
- data/lib/reactive_admin/api_errors.rb +116 -0
- data/lib/reactive_admin/api_fallback.rb +15 -0
- data/lib/reactive_admin/api_guards.rb +445 -0
- data/lib/reactive_admin/audit.rb +72 -0
- data/lib/reactive_admin/auth/guard.rb +68 -0
- data/lib/reactive_admin/auth/token_requests.rb +15 -0
- data/lib/reactive_admin/auth.rb +135 -0
- data/lib/reactive_admin/authorizer.rb +47 -0
- data/lib/reactive_admin/background_requests.rb +33 -0
- data/lib/reactive_admin/batch_actions.rb +57 -0
- data/lib/reactive_admin/choices.rb +289 -0
- data/lib/reactive_admin/client_error.rb +70 -0
- data/lib/reactive_admin/composite_keys.rb +12 -0
- data/lib/reactive_admin/configuration.rb +221 -0
- data/lib/reactive_admin/controller_extension.rb +229 -0
- data/lib/reactive_admin/csv_injection.rb +26 -0
- data/lib/reactive_admin/date_bound.rb +31 -0
- data/lib/reactive_admin/degradation.rb +72 -0
- data/lib/reactive_admin/diagnostics.rb +16 -0
- data/lib/reactive_admin/doctor.rb +466 -0
- data/lib/reactive_admin/dry_run.rb +147 -0
- data/lib/reactive_admin/dry_run_flag.rb +18 -0
- data/lib/reactive_admin/embed.rb +73 -0
- data/lib/reactive_admin/engine.rb +47 -0
- data/lib/reactive_admin/error_keys.rb +23 -0
- data/lib/reactive_admin/exposure.rb +86 -0
- data/lib/reactive_admin/filters.rb +165 -0
- data/lib/reactive_admin/fixtures/scrubber.rb +1075 -0
- data/lib/reactive_admin/fixtures.rb +161 -0
- data/lib/reactive_admin/form_content.rb +78 -0
- data/lib/reactive_admin/form_field.rb +279 -0
- data/lib/reactive_admin/form_has_many.rb +116 -0
- data/lib/reactive_admin/form_lock.rb +71 -0
- data/lib/reactive_admin/form_payload.rb +57 -0
- data/lib/reactive_admin/form_recorder.rb +192 -0
- data/lib/reactive_admin/form_schema.rb +160 -0
- data/lib/reactive_admin/frame.rb +97 -0
- data/lib/reactive_admin/html_nodes.rb +390 -0
- data/lib/reactive_admin/html_policy.rb +338 -0
- data/lib/reactive_admin/html_rich.rb +186 -0
- data/lib/reactive_admin/implicit_defaults.rb +102 -0
- data/lib/reactive_admin/index_options.rb +41 -0
- data/lib/reactive_admin/index_payload.rb +259 -0
- data/lib/reactive_admin/index_recorder.rb +115 -0
- data/lib/reactive_admin/index_views.rb +85 -0
- data/lib/reactive_admin/inline_style.rb +125 -0
- data/lib/reactive_admin/labels_payload.rb +34 -0
- data/lib/reactive_admin/ladder.rb +268 -0
- data/lib/reactive_admin/layout_classes.rb +167 -0
- data/lib/reactive_admin/legacy_inventory.rb +547 -0
- data/lib/reactive_admin/location.rb +22 -0
- data/lib/reactive_admin/lookup_audit.rb +30 -0
- data/lib/reactive_admin/lookup_payload.rb +41 -0
- data/lib/reactive_admin/manifest.rb +36 -0
- data/lib/reactive_admin/masked_json.rb +62 -0
- data/lib/reactive_admin/masking.rb +100 -0
- data/lib/reactive_admin/mcp/access.rb +111 -0
- data/lib/reactive_admin/mcp/api.rb +123 -0
- data/lib/reactive_admin/mcp/count_tool.rb +22 -0
- data/lib/reactive_admin/mcp/layout.rb +175 -0
- data/lib/reactive_admin/mcp/output.rb +46 -0
- data/lib/reactive_admin/mcp/prompts.rb +111 -0
- data/lib/reactive_admin/mcp/server.rb +134 -0
- data/lib/reactive_admin/mcp/shapes.rb +164 -0
- data/lib/reactive_admin/mcp/tools.rb +386 -0
- data/lib/reactive_admin/mcp.rb +53 -0
- data/lib/reactive_admin/media_nodes.rb +34 -0
- data/lib/reactive_admin/menu.rb +90 -0
- data/lib/reactive_admin/menu_overlay.rb +291 -0
- data/lib/reactive_admin/node_registry.rb +47 -0
- data/lib/reactive_admin/open_api/builder.rb +156 -0
- data/lib/reactive_admin/open_api/context.rb +46 -0
- data/lib/reactive_admin/open_api/core.rb +51 -0
- data/lib/reactive_admin/open_api/operation_ids.rb +18 -0
- data/lib/reactive_admin/open_api/page_doc.rb +75 -0
- data/lib/reactive_admin/open_api/parts.rb +86 -0
- data/lib/reactive_admin/open_api/resource_doc.rb +423 -0
- data/lib/reactive_admin/open_api/security.rb +55 -0
- data/lib/reactive_admin/open_api/write_schema.rb +104 -0
- data/lib/reactive_admin/open_api.rb +41 -0
- data/lib/reactive_admin/option_source.rb +36 -0
- data/lib/reactive_admin/option_sources.rb +14 -0
- data/lib/reactive_admin/options_payload.rb +61 -0
- data/lib/reactive_admin/page_controller_extension.rb +112 -0
- data/lib/reactive_admin/page_forms.rb +181 -0
- data/lib/reactive_admin/page_payload.rb +120 -0
- data/lib/reactive_admin/param_normalizer.rb +89 -0
- data/lib/reactive_admin/paths.rb +63 -0
- data/lib/reactive_admin/permissions.rb +31 -0
- data/lib/reactive_admin/provenance.rb +57 -0
- data/lib/reactive_admin/query_guard.rb +108 -0
- data/lib/reactive_admin/ransack_guard.rb +107 -0
- data/lib/reactive_admin/rate_limit.rb +59 -0
- data/lib/reactive_admin/reactive_dsl.rb +99 -0
- data/lib/reactive_admin/readiness.rb +189 -0
- data/lib/reactive_admin/registry.rb +69 -0
- data/lib/reactive_admin/resource_meta.rb +120 -0
- data/lib/reactive_admin/resource_summary.rb +41 -0
- data/lib/reactive_admin/routes.rb +60 -0
- data/lib/reactive_admin/row_errors.rb +29 -0
- data/lib/reactive_admin/rspec.rb +116 -0
- data/lib/reactive_admin/scrubbed_error.rb +22 -0
- data/lib/reactive_admin/search.rb +79 -0
- data/lib/reactive_admin/server_timing.rb +31 -0
- data/lib/reactive_admin/show_payload.rb +88 -0
- data/lib/reactive_admin/sidebars.rb +34 -0
- data/lib/reactive_admin/site.rb +55 -0
- data/lib/reactive_admin/style_report.rb +129 -0
- data/lib/reactive_admin/style_sources.rb +83 -0
- data/lib/reactive_admin/template_actions.rb +126 -0
- data/lib/reactive_admin/template_content.rb +49 -0
- data/lib/reactive_admin/template_form.rb +442 -0
- data/lib/reactive_admin/test_support.rb +31 -0
- data/lib/reactive_admin/typeahead.rb +33 -0
- data/lib/reactive_admin/ui/assets.rb +91 -0
- data/lib/reactive_admin/ui/client_build.rb +47 -0
- data/lib/reactive_admin/ui/helper.rb +24 -0
- data/lib/reactive_admin/ui/packaged_client.rb +67 -0
- data/lib/reactive_admin/ui/shell.rb +81 -0
- data/lib/reactive_admin/ui/switch.rb +38 -0
- data/lib/reactive_admin/ui.rb +43 -0
- data/lib/reactive_admin/value_payload.rb +147 -0
- data/lib/reactive_admin/value_token.rb +36 -0
- data/lib/reactive_admin/values.rb +43 -0
- data/lib/reactive_admin/version.rb +3 -0
- data/lib/reactive_admin/write_audit.rb +60 -0
- data/lib/reactive_admin/write_guards.rb +142 -0
- data/lib/reactive_admin.rb +153 -0
- data/lib/reactiveadmin.rb +1 -0
- data/lib/tasks/reactiveadmin.rake +36 -0
- data/lib/tasks/reactiveadmin_client.rake +11 -0
- data/lib/tasks/reactiveadmin_legacy.rake +7 -0
- data/lib/tasks/reactiveadmin_styles.rake +6 -0
- data/openapi/core.yaml +1643 -0
- data/vendor/client/assets/ActionPage-XUYorI8E.js +1 -0
- data/vendor/client/assets/ActionView-BsZFcsgp.js +1 -0
- data/vendor/client/assets/CommandPalette-C59HT1ip.js +1 -0
- data/vendor/client/assets/DatePicker-DuaK0iMg.js +1 -0
- data/vendor/client/assets/DateRangeCalendar-B2BDsG-X.js +1 -0
- data/vendor/client/assets/DegradedNotice-DiH5n2DO.js +1 -0
- data/vendor/client/assets/FormDialog-pmYl8Eov.js +1 -0
- data/vendor/client/assets/FormSkeleton-DuSBZO3C.js +1 -0
- data/vendor/client/assets/FrameView-2X8cFvUt.css +1 -0
- data/vendor/client/assets/FrameView-zmUeDO8d.js +1 -0
- data/vendor/client/assets/GroupOverview-DI5T3k5K.js +1 -0
- data/vendor/client/assets/InlineForm-CMEIMgeh.js +1 -0
- data/vendor/client/assets/JsonDiff-o7JWr7CH.js +3 -0
- data/vendor/client/assets/JsonEditor-D4VXdlEx.js +1 -0
- data/vendor/client/assets/JsonView-BrJLDmSN.js +1 -0
- data/vendor/client/assets/MobileMenu-GAeFOeEb.js +1 -0
- data/vendor/client/assets/Node-SQl61V4K.js +2 -0
- data/vendor/client/assets/PageView-C-laNEPZ.js +1 -0
- data/vendor/client/assets/ResourceForm-BPjsoCY6.js +1 -0
- data/vendor/client/assets/ResourceIndex-COezAw5t.js +3 -0
- data/vendor/client/assets/ResourceOrPage-CRZGCY84.js +1 -0
- data/vendor/client/assets/ResourceShow-DweRXn18.js +1 -0
- data/vendor/client/assets/Segmented-BE9TCbph.js +1 -0
- data/vendor/client/assets/Sidebars-CsB9rFqX.js +1 -0
- data/vendor/client/assets/breadcrumb-DSA3Tlyd.js +1 -0
- data/vendor/client/assets/button-CvZ4_DFC.js +1 -0
- data/vendor/client/assets/calendar-BoyMpJIf.js +1 -0
- data/vendor/client/assets/check-C5A3J16N.js +1 -0
- data/vendor/client/assets/command-CMuk0oAt.js +1 -0
- data/vendor/client/assets/dist-CqEI82S_.js +1 -0
- data/vendor/client/assets/dist-IW4yX942.js +1 -0
- data/vendor/client/assets/editor-yqRLzgsJ.js +2 -0
- data/vendor/client/assets/external-link-C2aR4slL.js +1 -0
- data/vendor/client/assets/frames-C9gPCc3N.js +1 -0
- data/vendor/client/assets/humanize-DtU_Kpr4.js +1 -0
- data/vendor/client/assets/ibm-plex-mono-cyrillic-400-normal-BSMlKf0J.woff2 +0 -0
- data/vendor/client/assets/ibm-plex-mono-cyrillic-400-normal-CEL4l2ZJ.woff +0 -0
- data/vendor/client/assets/ibm-plex-mono-cyrillic-500-normal-Ael50iVv.woff +0 -0
- data/vendor/client/assets/ibm-plex-mono-cyrillic-500-normal-Bq9vWWag.woff2 +0 -0
- data/vendor/client/assets/ibm-plex-mono-cyrillic-ext-400-normal-DMdlQ8Kv.woff +0 -0
- data/vendor/client/assets/ibm-plex-mono-cyrillic-ext-400-normal-xuaO2J-f.woff2 +0 -0
- data/vendor/client/assets/ibm-plex-mono-cyrillic-ext-500-normal-BIfNGwUT.woff +0 -0
- data/vendor/client/assets/ibm-plex-mono-cyrillic-ext-500-normal-BqneJy0T.woff2 +0 -0
- data/vendor/client/assets/ibm-plex-mono-latin-400-normal-CvHOgSBP.woff +0 -0
- data/vendor/client/assets/ibm-plex-mono-latin-400-normal-DMJ8VG8y.woff2 +0 -0
- data/vendor/client/assets/ibm-plex-mono-latin-500-normal-CB9ihrfo.woff +0 -0
- data/vendor/client/assets/ibm-plex-mono-latin-500-normal-DSY6xOcd.woff2 +0 -0
- data/vendor/client/assets/ibm-plex-mono-latin-ext-400-normal-BmRBH3aV.woff2 +0 -0
- data/vendor/client/assets/ibm-plex-mono-latin-ext-400-normal-D3D2R8hC.woff +0 -0
- data/vendor/client/assets/ibm-plex-mono-latin-ext-500-normal-CAhNIIs5.woff2 +0 -0
- data/vendor/client/assets/ibm-plex-mono-latin-ext-500-normal-CZ70TYgx.woff +0 -0
- data/vendor/client/assets/ibm-plex-mono-vietnamese-400-normal-BulugwFq.woff2 +0 -0
- data/vendor/client/assets/ibm-plex-mono-vietnamese-400-normal-DDuiU_S-.woff +0 -0
- data/vendor/client/assets/ibm-plex-mono-vietnamese-500-normal-C8zxqsMH.woff +0 -0
- data/vendor/client/assets/ibm-plex-mono-vietnamese-500-normal-DZ4AoWbu.woff2 +0 -0
- data/vendor/client/assets/ibm-plex-sans-cyrillic-ext-wght-normal-d45eAU9y.woff2 +0 -0
- data/vendor/client/assets/ibm-plex-sans-cyrillic-wght-normal-BAAhND-U.woff2 +0 -0
- data/vendor/client/assets/ibm-plex-sans-greek-wght-normal-CmyJS8uq.woff2 +0 -0
- data/vendor/client/assets/ibm-plex-sans-latin-ext-wght-normal-CIII54If.woff2 +0 -0
- data/vendor/client/assets/ibm-plex-sans-latin-wght-normal-IvpUvPa2.woff2 +0 -0
- data/vendor/client/assets/ibm-plex-sans-vietnamese-wght-normal-Dg1JeJN0.woff2 +0 -0
- data/vendor/client/assets/index-B51aUaAY.js +43 -0
- data/vendor/client/assets/index-Cs9rCoWM.css +2 -0
- data/vendor/client/assets/input-DByFmQPa.js +1 -0
- data/vendor/client/assets/json-De3PN-R6.css +1 -0
- data/vendor/client/assets/json-oTp7Q-d-.js +5 -0
- data/vendor/client/assets/media-D4a_En8R.js +1 -0
- data/vendor/client/assets/plus-CfJ9vo8X.js +1 -0
- data/vendor/client/assets/popover-CDtI9R8Q.js +1 -0
- data/vendor/client/assets/purify-G7QKJyJq.js +1 -0
- data/vendor/client/assets/query-CCsZN2fa.js +1 -0
- data/vendor/client/assets/recent-BrzLwL0D.js +1 -0
- data/vendor/client/assets/rich-BQc_q5T7.js +1 -0
- data/vendor/client/assets/rolldown-runtime-XKyaHtl9.js +1 -0
- data/vendor/client/assets/select-C43qDA3k.js +1 -0
- data/vendor/client/assets/sheet-BPl2n-4n.js +1 -0
- data/vendor/client/assets/textarea-BnOphXry.js +1 -0
- data/vendor/client/assets/uiMode-z0ZbRV49.js +1 -0
- data/vendor/client/assets/uiToggle-DwnRQTH1.js +1 -0
- data/vendor/client/assets/useRecordForm-X_DExEP2.js +1 -0
- data/vendor/client/assets/useRecordVisit-BRtfMi-q.js +1 -0
- data/vendor/client/assets/utils-DwBGbDkG.js +1 -0
- data/vendor/client/assets/vendor-calendar-nTZiq9oY.js +1 -0
- data/vendor/client/assets/vendor-datefns-BoC6MCnl.js +1 -0
- data/vendor/client/assets/vendor-forms-D0h8hG_S.js +55 -0
- data/vendor/client/assets/vendor-purify-BXoPR7WT.js +3 -0
- data/vendor/client/assets/vendor-query-DZ6APRNI.js +1 -0
- data/vendor/client/assets/vendor-react-C1iE8mnY.js +9 -0
- data/vendor/client/assets/vendor-router-CI6Vh4k_.js +1 -0
- data/vendor/client/assets/vendor-table-DuQ835by.js +4 -0
- data/vendor/client/index.html +24 -0
- data/vendor/client/manifest.json +867 -0
- data/vendor/client/reactiveadmin-client.json +4 -0
- metadata +350 -0
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
require "yaml"
|
|
2
|
+
|
|
3
|
+
module ReactiveAdmin
|
|
4
|
+
# A typed OpenAPI 3.1 document of the admin API this app serves, for a docs viewer. It is derived
|
|
5
|
+
# from what the manifest and the runtime use (resource summaries, filters, scopes, the controls-only
|
|
6
|
+
# write schema), filtered by the user's permissions, and states only what the code declares: never
|
|
7
|
+
# record data, option values, or anything masked, hidden or not exposed. Core's component schemas
|
|
8
|
+
# (openapi/core.yaml) are embedded and referenced.
|
|
9
|
+
module OpenApi
|
|
10
|
+
SPEC_VERSION = "3.1.0"
|
|
11
|
+
|
|
12
|
+
autoload :Core, "reactive_admin/open_api/core"
|
|
13
|
+
autoload :Builder, "reactive_admin/open_api/builder"
|
|
14
|
+
autoload :Context, "reactive_admin/open_api/context"
|
|
15
|
+
autoload :Parts, "reactive_admin/open_api/parts"
|
|
16
|
+
autoload :ResourceDoc, "reactive_admin/open_api/resource_doc"
|
|
17
|
+
autoload :PageDoc, "reactive_admin/open_api/page_doc"
|
|
18
|
+
autoload :WriteSchema, "reactive_admin/open_api/write_schema"
|
|
19
|
+
autoload :Security, "reactive_admin/open_api/security"
|
|
20
|
+
autoload :OperationIds, "reactive_admin/open_api/operation_ids"
|
|
21
|
+
|
|
22
|
+
module_function
|
|
23
|
+
|
|
24
|
+
# `user` limits the document to what they may do. `full` (the default without a user) describes the
|
|
25
|
+
# whole exposed surface, for the rake task: never serve it.
|
|
26
|
+
# `channel` (:session or :token) decides which of the `api` guards leave an operation out; a full
|
|
27
|
+
# document and one built outside a request describe the session's.
|
|
28
|
+
def build(user = nil, controller: nil, full: user.nil?, channel: nil) = Builder.new(user, controller:, full:, channel:).call
|
|
29
|
+
|
|
30
|
+
# Cached like `_meta`: per code version, locale, permission fingerprint and auth channel.
|
|
31
|
+
def fetch(controller)
|
|
32
|
+
channel = ApiGuards.channel_of(controller.request)
|
|
33
|
+
key = ["reactiveadmin", "openapi", ResourceMeta.code_version(Registry.index), I18n.locale, ReactiveAdmin.user_fingerprint(controller), channel]
|
|
34
|
+
Rails.cache.fetch(key, expires_in: ReactiveAdmin.config.meta_cache_ttl) do
|
|
35
|
+
build(ReactiveAdmin.current_user(controller), controller:, full: false, channel:)
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def to_yaml(document) = YAML.dump(document.deep_stringify_keys)
|
|
40
|
+
end
|
|
41
|
+
end
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
module ReactiveAdmin
|
|
2
|
+
# A named, host-registered list of options (see ReactiveAdmin.option_sources). The relation is
|
|
3
|
+
# kept lazy so the API can search it in SQL and the classic admin can still render all of it.
|
|
4
|
+
class OptionSource
|
|
5
|
+
attr_reader :name, :label, :value, :search, :hint
|
|
6
|
+
|
|
7
|
+
def self.implicit(relation, label: nil, value: :id) = new(nil, relation, label:, value:)
|
|
8
|
+
|
|
9
|
+
def initialize(name, relation, label: nil, value: :id, search: nil, hint: nil, policy: nil)
|
|
10
|
+
@name = name&.to_sym
|
|
11
|
+
@relation = relation
|
|
12
|
+
@label = label
|
|
13
|
+
@value = value || :id
|
|
14
|
+
@search = Array(search).presence
|
|
15
|
+
@hint = hint
|
|
16
|
+
@policy = policy
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
# `refine` receives the relation (and, when it takes two arguments, the form object).
|
|
20
|
+
def scoped(view, refine = nil, object = nil)
|
|
21
|
+
base = relation(view)
|
|
22
|
+
return base unless refine
|
|
23
|
+
|
|
24
|
+
(refine.arity == 1) ? refine.call(base) : refine.call(base, object)
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def policy? = @policy.nil? ? ReactiveAdmin.config.scope_options_by_policy : @policy
|
|
28
|
+
|
|
29
|
+
private
|
|
30
|
+
|
|
31
|
+
def relation(view)
|
|
32
|
+
relation = @relation.respond_to?(:call) ? view.instance_exec(&@relation) : @relation
|
|
33
|
+
relation.is_a?(Class) ? relation.all : relation
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
end
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
module ReactiveAdmin
|
|
2
|
+
# Registry behind `ReactiveAdmin.option_sources { source :users, -> { User.all }, ... }`.
|
|
3
|
+
class OptionSources
|
|
4
|
+
def initialize
|
|
5
|
+
@sources = {}
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
def source(name, relation, **) = @sources[name.to_sym] = OptionSource.new(name, relation, **)
|
|
9
|
+
|
|
10
|
+
def [](name) = @sources.fetch(name.to_sym) { raise KeyError, "unknown option source #{name.inspect}" }
|
|
11
|
+
|
|
12
|
+
def names = @sources.keys
|
|
13
|
+
end
|
|
14
|
+
end
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
module ReactiveAdmin
|
|
2
|
+
# Typeahead backend for the _options endpoint: filter and form controls whose collections
|
|
3
|
+
# are too large to inline.
|
|
4
|
+
class OptionsPayload
|
|
5
|
+
MAX_LIMIT = 100
|
|
6
|
+
MAX_VALUES = 25
|
|
7
|
+
# The endpoint's own params; the rest of a page's query is what its content reads.
|
|
8
|
+
RESERVED = %w[context form field term value limit cursor].freeze
|
|
9
|
+
|
|
10
|
+
# What a page or template was loaded with, for a search that renders it again to find the field.
|
|
11
|
+
def self.page_query(request) = request.query_parameters.except(*RESERVED)
|
|
12
|
+
|
|
13
|
+
# Comma-separated values, as a string or a list of them; more than `max` is a 400.
|
|
14
|
+
def self.split_values(raw, max = MAX_VALUES)
|
|
15
|
+
values = Array.wrap(raw).flat_map { it.to_s.split(",") }
|
|
16
|
+
raise ApiErrors::BadRequest, "Too many values (max #{max})" if values.size > max
|
|
17
|
+
|
|
18
|
+
values
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
# The source of each field in a context. A form is built for just those fields: their options
|
|
22
|
+
# may depend on the record, not on their siblings.
|
|
23
|
+
def self.sources(controller, context, fields)
|
|
24
|
+
case context
|
|
25
|
+
when "filter"
|
|
26
|
+
filters = Filters.new(AA.config_of(controller), controller.view_context)
|
|
27
|
+
fields.index_with { filters.choices(it) }
|
|
28
|
+
when "form"
|
|
29
|
+
schema = FormPayload.new(controller, only: fields).schema
|
|
30
|
+
schema.sections
|
|
31
|
+
fields.index_with { |field| schema.choices.fetch(field) { raise ActiveRecord::RecordNotFound, "No options for #{field}" } }
|
|
32
|
+
else raise ActionController::ParameterMissing, :context
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def initialize(controller)
|
|
37
|
+
@controller = controller
|
|
38
|
+
@params = controller.params
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def as_json(*)
|
|
42
|
+
source = choices
|
|
43
|
+
values = self.class.split_values(@params[:value])
|
|
44
|
+
result = if values.any?
|
|
45
|
+
{options: source.lookup(values), truncated: false}
|
|
46
|
+
else
|
|
47
|
+
limit = @params.fetch(:limit, ReactiveAdmin.config.inline_options_limit).to_i.clamp(1, MAX_LIMIT)
|
|
48
|
+
source.search(@params[:term].to_s, limit, @params[:cursor])
|
|
49
|
+
end
|
|
50
|
+
LookupAudit.record(@controller, model: source.try(:model), kind: values.any? ? :lookup : :search, field: @params[:field], result_count: result[:options].size)
|
|
51
|
+
result
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
private
|
|
55
|
+
|
|
56
|
+
def choices
|
|
57
|
+
field = @params.require(:field)
|
|
58
|
+
self.class.sources(@controller, @params[:context], [field]).fetch(field)
|
|
59
|
+
end
|
|
60
|
+
end
|
|
61
|
+
end
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
module ReactiveAdmin
|
|
2
|
+
# Prepended to ActiveAdmin::PageController: a register_page's own controller (authentication,
|
|
3
|
+
# authorization, `controller do` overrides, page actions) serves its API too.
|
|
4
|
+
module PageControllerExtension
|
|
5
|
+
include Frame
|
|
6
|
+
include Embed
|
|
7
|
+
include TemplateActions
|
|
8
|
+
include DryRunFlag
|
|
9
|
+
|
|
10
|
+
def index(*)
|
|
11
|
+
return super unless reactiveadmin_request?
|
|
12
|
+
|
|
13
|
+
(params[:context] == "page_form") ? render_form_options : render_page
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
# Through `index`, where hosts set up what the page's content needs.
|
|
17
|
+
def reactiveadmin_page = index
|
|
18
|
+
|
|
19
|
+
def default_render(*)
|
|
20
|
+
return render_native_template(action_name) if reactiveadmin_request? && request.get? && native_template?(action_name)
|
|
21
|
+
|
|
22
|
+
super
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def render(*args, &)
|
|
26
|
+
return super unless reactiveadmin_request? && template_render?(args)
|
|
27
|
+
|
|
28
|
+
path = rendered_template_path(args)
|
|
29
|
+
if native_template?(path)
|
|
30
|
+
render_native_page_or_rejection(path)
|
|
31
|
+
else
|
|
32
|
+
render_api_error(:unsupported, "This action renders an HTML page; use the classic admin", 501)
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
private
|
|
37
|
+
|
|
38
|
+
def render_page
|
|
39
|
+
lookup_context.formats = [:html]
|
|
40
|
+
render_collected("page") { PagePayload.new(self).as_json }
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
# Choices of a form in the content too long to inline, searched like any form's options.
|
|
44
|
+
def render_form_options
|
|
45
|
+
lookup_context.formats = [:html]
|
|
46
|
+
index = params.require(:form).to_i
|
|
47
|
+
form = PagePayload.new(self).forms[index] if index >= 0
|
|
48
|
+
source = form&.choices&.[](params.require(:field)) or raise ActiveRecord::RecordNotFound, "No options for that field"
|
|
49
|
+
authorize_form_action(form)
|
|
50
|
+
return if performed?
|
|
51
|
+
|
|
52
|
+
render json: TemplateOptions.new(self, source).as_json, content_type: "application/json"
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
# The choices belong to a form that posts to a page or resource action; they need that action's permission.
|
|
56
|
+
def authorize_form_action(form)
|
|
57
|
+
action = form.response[:action]
|
|
58
|
+
return if action[:method] == "get" # a read of this very page, which this request already is
|
|
59
|
+
|
|
60
|
+
path = URI.parse(action[:path]).path.delete_prefix(ReactiveAdmin.config.mount_path)
|
|
61
|
+
route = Rails.application.routes.recognize_path(path, method: action[:method])
|
|
62
|
+
config = Registry.for_controller_path(route[:controller]) || Registry.page_for_controller_path(route[:controller])
|
|
63
|
+
if (refusal = ApiGuards.refusal(self, config, [route[:action]], verb: action[:method]))
|
|
64
|
+
return render_api_denied(refusal)
|
|
65
|
+
end
|
|
66
|
+
authorize! action_to_permission(route[:action]), AA.page?(config) ? config : config.resource_class
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
# Writes run as html so the page action and its flashes behave as in the classic admin.
|
|
70
|
+
def process_action(*)
|
|
71
|
+
take_dry_run_param if reactiveadmin_request?
|
|
72
|
+
request.format = :html if reactiveadmin_request? && !request.get?
|
|
73
|
+
super
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
# Runs after the before_actions, so the content renders for a user who passed them.
|
|
77
|
+
def send_action(*)
|
|
78
|
+
refuse_unsupported_dry_run
|
|
79
|
+
normalize_form_params if reactiveadmin_request? && !request.get?
|
|
80
|
+
super
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
# A write to a form of the page's content is shaped as a browser's post of that form would be. The
|
|
84
|
+
# action still runs if the content can't be rendered for this write.
|
|
85
|
+
def normalize_form_params
|
|
86
|
+
lookup_context.formats = [:html]
|
|
87
|
+
PageForms.normalize(self, PagePayload.new(self).forms(controls_only: true))
|
|
88
|
+
rescue => e
|
|
89
|
+
Rails.logger.warn("[reactiveadmin] #{controller_path} write not shaped like the form's post: #{e.class} at #{e.backtrace&.first}")
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
def action_to_permission(action)
|
|
93
|
+
(action.to_s == "reactiveadmin_page") ? AA::Auth::READ : super
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
def render_redirect_result(location, response_options)
|
|
97
|
+
notes = flash.to_hash.merge(response_options.fetch(:flash, {}).to_h.stringify_keys, response_options.slice(:notice, :alert, :error).stringify_keys)
|
|
98
|
+
failure = notes.values_at("alert", "error").compact_blank.first
|
|
99
|
+
flash.clear
|
|
100
|
+
location = Location.for(location, host: request.host)
|
|
101
|
+
return render_invalid(failure, base: [failure], location:) if failure
|
|
102
|
+
|
|
103
|
+
render json: {ok: true, message: notes["notice"].presence, location:}.compact, content_type: "application/json"
|
|
104
|
+
end
|
|
105
|
+
|
|
106
|
+
def render_invalid(message = "Validation failed", base: [], location: nil, form: nil)
|
|
107
|
+
base = [*base, *flash.to_hash.values_at("alert", "error")].compact_blank.uniq
|
|
108
|
+
flash.clear
|
|
109
|
+
render_api_error(:invalid, message, 422, errors: {}, base:, location:, form:)
|
|
110
|
+
end
|
|
111
|
+
end
|
|
112
|
+
end
|
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
module ReactiveAdmin
|
|
2
|
+
# Formtastic forms in a page's or show's content become `form` nodes instead of frames. Each form's
|
|
3
|
+
# block runs against the TemplateForm recorder, and a form it recorded faithfully travels as a
|
|
4
|
+
# FormResponse the client renders inline; one it can't record keeps rendering as html, which the
|
|
5
|
+
# walker frames. Forms leave a marker in the html, like show-row JSON values do.
|
|
6
|
+
class PageForms
|
|
7
|
+
Recorded = Struct.new(:response, :choices)
|
|
8
|
+
|
|
9
|
+
# Mixed into the view that renders the content, ahead of TemplateForm::Recording.
|
|
10
|
+
module Recording
|
|
11
|
+
def semantic_form_for(*args, &block)
|
|
12
|
+
forms = reactiveadmin_page_forms or return super
|
|
13
|
+
forms.node(self) { super(*args, &block) } || forms.suspended { super(*args, &block) }
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def active_admin_form_for(*args, &block)
|
|
17
|
+
forms = reactiveadmin_page_forms or return super
|
|
18
|
+
forms.node(self) { super(*args, &block) } || forms.suspended { super(*args, &block) }
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def reactiveadmin_page_forms = @_reactiveadmin_page_forms
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
# For Arbre content: `active_admin_form_for` there is an Arbre component, not the view helper.
|
|
25
|
+
module ArbreForms
|
|
26
|
+
def active_admin_form_for(*args, &block)
|
|
27
|
+
forms = helpers.try(:reactiveadmin_page_forms) or return super
|
|
28
|
+
marker = forms.node(helpers) { helpers.active_admin_form_for(*args, &block) }
|
|
29
|
+
marker ? text_node(marker) : forms.suspended { super(*args, &block) }
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
# Runs the block with the view's forms recording, and returns what was recorded.
|
|
34
|
+
def self.recording(view, controller, controls_only: false)
|
|
35
|
+
forms = new(controller, controls_only:)
|
|
36
|
+
view.extend(TemplateForm::Recording)
|
|
37
|
+
view.extend(Recording)
|
|
38
|
+
view.instance_variable_set(:@_reactiveadmin_page_forms, forms)
|
|
39
|
+
yield
|
|
40
|
+
forms
|
|
41
|
+
ensure
|
|
42
|
+
view.instance_variable_set(:@_reactiveadmin_page_forms, nil)
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
# Gives a write's params the shape a browser's post of the form it came from would have, as a
|
|
46
|
+
# native form's does. Page content is rendered again to find that form.
|
|
47
|
+
def self.normalize(controller, forms)
|
|
48
|
+
path = controller.request.path
|
|
49
|
+
sections = forms.select { it.response.dig(:action, :path) == path && it.response.dig(:action, :method) != "get" }.flat_map { it.response.dig(:form, :sections) }
|
|
50
|
+
return if sections.empty?
|
|
51
|
+
|
|
52
|
+
fields = sections.flat_map { it[:fields] }
|
|
53
|
+
fields.select { it[:disabled] && it[:param] }.each { drop(controller.params, it[:param]) }
|
|
54
|
+
ParamNormalizer.call(controller.params, sections)
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
# Browsers don't post disabled inputs, so a client that does is submitting what the form withheld.
|
|
58
|
+
def self.drop(params, param)
|
|
59
|
+
*path, leaf = param.delete_suffix("[]").scan(/[^\[\]]+/)
|
|
60
|
+
path.inject(params) { |memo, key| memo.try(:[], key) }.try(:delete, leaf)
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
attr_reader :recorded
|
|
64
|
+
|
|
65
|
+
# `options: false` for content that has no page to search a long list of choices (a template's forms).
|
|
66
|
+
def initialize(controller, controls_only: false, options: nil)
|
|
67
|
+
@controller = controller
|
|
68
|
+
@controls_only = controls_only
|
|
69
|
+
@options = options
|
|
70
|
+
@config = AA.config_of(controller)
|
|
71
|
+
@recorded = []
|
|
72
|
+
@recording = false
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
# Renders a form as plain markup: the forms inside it (an Arbre form builds its own) are not recorded.
|
|
76
|
+
def suspended
|
|
77
|
+
previous = @recording
|
|
78
|
+
@recording = true
|
|
79
|
+
yield
|
|
80
|
+
ensure
|
|
81
|
+
@recording = previous
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
# Html with a marker for the form the block renders, or nil when it has to render as a plain form.
|
|
85
|
+
def node(view, &)
|
|
86
|
+
return if @recording
|
|
87
|
+
|
|
88
|
+
@recording = true
|
|
89
|
+
begin
|
|
90
|
+
response = record(view, &)
|
|
91
|
+
return unless response
|
|
92
|
+
|
|
93
|
+
@recorded << Recorded.new(response, @last_choices)
|
|
94
|
+
NodeRegistry.marker({type: "form", form: response})
|
|
95
|
+
rescue => e
|
|
96
|
+
Rails.logger.warn("[reactiveadmin] #{@config.resource_name} form not recordable: #{e.class} at #{e.backtrace&.first}")
|
|
97
|
+
Degradation.record(kind: :page_form_failed, where: Degradation.where, reason: "A form raised #{e.class} while recording; shown in a classic frame")
|
|
98
|
+
nil
|
|
99
|
+
ensure
|
|
100
|
+
@recording = false
|
|
101
|
+
end
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
private
|
|
105
|
+
|
|
106
|
+
def record(view)
|
|
107
|
+
state = TemplateForm::State.new(TemplateForm::Schema.new(@controller, view, controls_only: @controls_only))
|
|
108
|
+
markup = recording_in(view, state) { yield.to_s }
|
|
109
|
+
form = state.entries.reverse_each.find { it.first == :form }&.last or return
|
|
110
|
+
path = local_path(form[:path], form[:method])
|
|
111
|
+
return unless TemplateForm::METHODS.include?(form[:method]) && path
|
|
112
|
+
|
|
113
|
+
sections, title = state.arrange(markup)
|
|
114
|
+
state.schema.sections = sections
|
|
115
|
+
return unless state.schema.unsupported_kinds.empty?
|
|
116
|
+
|
|
117
|
+
fields = sections.flat_map { it[:fields] }
|
|
118
|
+
return if fields.any? { it[:options_path] } && !options?
|
|
119
|
+
|
|
120
|
+
@last_choices = state.schema.choices
|
|
121
|
+
fields.each { it[:options_path] &&= options_path(it[:name]) }
|
|
122
|
+
{
|
|
123
|
+
resource: key, title: title.to_s, actions: [], action: {method: form[:method], path: Paths.api(path)}, form: {sections:},
|
|
124
|
+
submit_label: state.submit_label, submit_confirm: state.submit_confirm, permissions: {}, submittable: true
|
|
125
|
+
}.compact
|
|
126
|
+
end
|
|
127
|
+
|
|
128
|
+
def recording_in(view, state)
|
|
129
|
+
previous = view.instance_variable_get(:@_reactiveadmin_template)
|
|
130
|
+
view.instance_variable_set(:@_reactiveadmin_template, state)
|
|
131
|
+
yield
|
|
132
|
+
ensure
|
|
133
|
+
view.instance_variable_set(:@_reactiveadmin_template, previous)
|
|
134
|
+
end
|
|
135
|
+
|
|
136
|
+
# Where the form posts, when that is a route of the admin the API serves too. A GET form only
|
|
137
|
+
# re-reads the view that holds it, so it is the one place that form is for.
|
|
138
|
+
def local_path(url, verb)
|
|
139
|
+
return own_view(url) if verb == "get"
|
|
140
|
+
|
|
141
|
+
uri = URI.parse(url.to_s)
|
|
142
|
+
return if uri.host.present? && uri.host != @controller.request.host
|
|
143
|
+
|
|
144
|
+
path = [uri.path, uri.query].compact.join("?")
|
|
145
|
+
path if path.start_with?("/#{ReactiveAdmin.config.namespace}/") && admin_route?(uri.path, verb)
|
|
146
|
+
rescue URI::InvalidURIError
|
|
147
|
+
nil
|
|
148
|
+
end
|
|
149
|
+
|
|
150
|
+
def admin_route?(path, verb)
|
|
151
|
+
controller = Rails.application.routes.recognize_path(path, method: verb)[:controller]
|
|
152
|
+
Registry.for_controller_path(controller) || Registry.page_for_controller_path(controller)
|
|
153
|
+
rescue ActionController::RoutingError
|
|
154
|
+
nil
|
|
155
|
+
end
|
|
156
|
+
|
|
157
|
+
# A page's content, or a template's further forms. A show page has no view of its own to re-read with a query.
|
|
158
|
+
def get_forms? = page? || @options == false
|
|
159
|
+
|
|
160
|
+
def own_view(url)
|
|
161
|
+
path = TemplateForm::Form.own_view(url, @controller.request) if get_forms?
|
|
162
|
+
path && ((@options == false) ? path : Ladder.page_path(@config, path))
|
|
163
|
+
end
|
|
164
|
+
|
|
165
|
+
# Options beyond the inline limit are searched by the page that holds the form: only it has
|
|
166
|
+
# set up what the content needs, including what the page's own query says. A show page has no
|
|
167
|
+
# such endpoint, so its forms stay frames.
|
|
168
|
+
def options_path(field)
|
|
169
|
+
query = OptionsPayload.page_query(@controller.request).merge(context: "page_form", form: @recorded.size, field:)
|
|
170
|
+
"#{Paths.api(Ladder.page_path(@config, classic_url))}?#{query.to_query}"
|
|
171
|
+
end
|
|
172
|
+
|
|
173
|
+
def classic_url = @controller.request.path.delete_prefix(ReactiveAdmin.config.mount_path).sub("/_pages/", "/")
|
|
174
|
+
|
|
175
|
+
def page? = AA.page?(@config)
|
|
176
|
+
|
|
177
|
+
def options? = @options.nil? ? page? : @options
|
|
178
|
+
|
|
179
|
+
def key = page? ? @config.underscored_resource_name : Registry.route_key(@config)
|
|
180
|
+
end
|
|
181
|
+
end
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
module ReactiveAdmin
|
|
2
|
+
# PageResponse for a register_page: its `content` block walked into nodes, plus its action items
|
|
3
|
+
# and the GET page actions that render something. Sidebars are not carried.
|
|
4
|
+
class PagePayload
|
|
5
|
+
# Arbre context that runs the content block the way ActiveAdmin::Views::Pages::Page does.
|
|
6
|
+
class Content < AA.arbre_element
|
|
7
|
+
include PageForms::ArbreForms
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def initialize(controller)
|
|
11
|
+
@controller = controller
|
|
12
|
+
@config = AA.config_of(controller)
|
|
13
|
+
@view = Masking.install(controller.view_context, @config)
|
|
14
|
+
@authorizer = Authorizer.for(controller)
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def as_json(*)
|
|
18
|
+
decision = Ladder.page(@config)
|
|
19
|
+
layout = NodeRegistry.with_scope { layout(decision) }
|
|
20
|
+
mode = rendered_mode(decision, layout)
|
|
21
|
+
items = ActionItems.new(@controller, "index", subject: @config).call
|
|
22
|
+
Degradation.record(kind: :page_frame, where: "page", reason: "Page content has forms; shown in a classic frame") if mode == "frame" && !forced?("frame")
|
|
23
|
+
Degradation.attach({
|
|
24
|
+
key:, title:, layout:, actions: items + page_actions(items),
|
|
25
|
+
view: {mode:, path: path(mode), custom_key: decision.custom_key, presentation: "page"}.compact
|
|
26
|
+
})
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
# What the content's forms recorded, to know how a write to one of them is shaped.
|
|
30
|
+
def forms(controls_only: false)
|
|
31
|
+
Degradation.with_collection(resource: @config.resource_name, action: "page", controller: @controller) { render_content(controls_only:) }
|
|
32
|
+
Array(@forms&.recorded)
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
private
|
|
36
|
+
|
|
37
|
+
def key = @config.underscored_resource_name
|
|
38
|
+
|
|
39
|
+
# The page's own URL, which carries its parent's id when it is nested.
|
|
40
|
+
def classic_url = @classic_url ||= @controller.request.path.delete_prefix(ReactiveAdmin.config.mount_path).sub("/_pages/", "/")
|
|
41
|
+
|
|
42
|
+
# What the content turned out to be: a page that walks into typed nodes is native even if its
|
|
43
|
+
# source looked scripted, and one with a frame node needs the frame.
|
|
44
|
+
def rendered_mode(decision, layout)
|
|
45
|
+
if decision.mode == "custom" then "custom"
|
|
46
|
+
elsif layout.size == 1 && layout.first[:type] == "iframe" then "iframe"
|
|
47
|
+
elsif framed?(layout) then "frame"
|
|
48
|
+
else
|
|
49
|
+
"native"
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
def framed?(nodes) = nodes.any? { it[:type] == "frame" || framed?(Array(it[:children])) }
|
|
54
|
+
|
|
55
|
+
def path(mode)
|
|
56
|
+
case mode
|
|
57
|
+
when "native" then Paths.api(Ladder.page_path(@config, classic_url))
|
|
58
|
+
when "frame" then classic_url
|
|
59
|
+
when "iframe" then Ladder.embed_url(classic_url)
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
def presenter = AA.page_presenter(@config, :index)
|
|
64
|
+
|
|
65
|
+
def title
|
|
66
|
+
custom = presenter && presenter[:title]
|
|
67
|
+
text = custom ? AA.render_or_call(@view, @view, custom) : @config.name
|
|
68
|
+
CGI.unescapeHTML(text.to_s)
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
def layout(decision)
|
|
72
|
+
return [] if decision.mode == "custom"
|
|
73
|
+
return [iframe] if decision.mode == "iframe" && forced?("iframe")
|
|
74
|
+
|
|
75
|
+
html = render_content(forms: !forced?("frame"))
|
|
76
|
+
return [{type: "frame", html: HtmlNodes.interactive(html, host: @controller.request.host), src: classic_url, title:}] if forced?("frame")
|
|
77
|
+
|
|
78
|
+
HtmlNodes.layout(html, src: classic_url, host: @controller.request.host, links:, title:, resource: @config.resource_name)
|
|
79
|
+
rescue => e
|
|
80
|
+
Rails.logger.warn("[reactiveadmin] #{@config.resource_name} page content embedded as iframe: #{e.class} at #{e.backtrace&.first}")
|
|
81
|
+
Degradation.record(kind: :page_iframe_fallback, where: "page", reason: "Page content raised #{e.class}; embedded as iframe")
|
|
82
|
+
[iframe]
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
def forced?(mode) = Ladder.override(@config, "*")&.fetch(:mode) == mode
|
|
86
|
+
|
|
87
|
+
def iframe = {type: "iframe", src: Ladder.embed_url(classic_url), title:}
|
|
88
|
+
|
|
89
|
+
def links = ActionLinks.new(host: @controller.request.host, base_url: @controller.request.base_url, authorizer: @authorizer, subject: @config)
|
|
90
|
+
|
|
91
|
+
# Formtastic forms are recorded into the nodes they stand for; the html left over keeps any other.
|
|
92
|
+
def render_content(forms: true, controls_only: false)
|
|
93
|
+
return "" unless presenter&.block
|
|
94
|
+
|
|
95
|
+
context = AA.arbre_context(@controller.view_assigns, @view)
|
|
96
|
+
render = -> { context.insert_tag(Content).instance_exec(&presenter.block) }
|
|
97
|
+
if forms
|
|
98
|
+
@forms = PageForms.recording(@view, @controller, controls_only:, &render)
|
|
99
|
+
else
|
|
100
|
+
render.call
|
|
101
|
+
end
|
|
102
|
+
context.to_s
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
# Only GETs: a page action that writes is the target of a form in the content.
|
|
106
|
+
def page_actions(linked)
|
|
107
|
+
@config.page_actions.filter_map do |declaration|
|
|
108
|
+
name = declaration.name.to_s
|
|
109
|
+
next if Array.wrap(declaration.http_verb) != [:get] || linked.any? { it[:key] == name }
|
|
110
|
+
|
|
111
|
+
href = File.join(classic_url, name)
|
|
112
|
+
action = {key: name, label: name.titleize, kind: "custom", placement: "header", method: "get", href:, api_path: Paths.api(href), enabled: true}
|
|
113
|
+
next ApiGuards.mark(action, @config, name) if ApiGuards.denies?(@config, name, verb: "get")
|
|
114
|
+
|
|
115
|
+
view = Ladder.view(@config, name, href:) or next
|
|
116
|
+
action.merge(view:)
|
|
117
|
+
end
|
|
118
|
+
end
|
|
119
|
+
end
|
|
120
|
+
end
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
module ReactiveAdmin
|
|
2
|
+
# Gives submitted params the shape a browser's post of the classic form would have, so every client
|
|
3
|
+
# behaves like classic whatever it sends for a blank or structured value. Only params that match a
|
|
4
|
+
# field of the form are touched, and each is judged by that field's declared control.
|
|
5
|
+
class ParamNormalizer
|
|
6
|
+
# Browsers have no blank for these: a checkbox is on or off, a file is chosen or not, a multi-select
|
|
7
|
+
# holds a list.
|
|
8
|
+
KEPT = %w[boolean file html multiselect checkboxes].freeze
|
|
9
|
+
ROW = /\[(?:\d+|__INDEX__)\]/
|
|
10
|
+
|
|
11
|
+
# `permitted` returns the host's strong parameters for the request.
|
|
12
|
+
def self.call(params, sections, permitted: nil) = new(sections, permitted).call(params)
|
|
13
|
+
|
|
14
|
+
def initialize(sections, permitted)
|
|
15
|
+
@permitted = permitted
|
|
16
|
+
fields = sections.flat_map { fields_in(it) }.select { it[:param] }
|
|
17
|
+
@controls = fields.to_h { [shape(it[:param].delete_suffix("[]")), it[:control]] }
|
|
18
|
+
@summarized = fields.select { it[:summary] }.to_set { shape(it[:param]) }
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
# An unselected radio posts nothing; any other blank control posts an empty string.
|
|
22
|
+
def call(node, path = [])
|
|
23
|
+
node.keys.each do |name|
|
|
24
|
+
here = [*path, name]
|
|
25
|
+
control = @controls[shape(bracketed(here))]
|
|
26
|
+
value = node[name]
|
|
27
|
+
if control == "json" then json(node, name, value, here, @summarized.include?(shape(bracketed(here))))
|
|
28
|
+
elsif value.is_a?(ActionController::Parameters) then call(value, here)
|
|
29
|
+
elsif control == "radio" then node.delete(name) if value.nil? || value == ""
|
|
30
|
+
elsif value.nil? && control && !KEPT.include?(control) then node[name] = ""
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
private
|
|
36
|
+
|
|
37
|
+
def fields_in(section)
|
|
38
|
+
return section[:fields] || [] unless section[:kind] == "has_many"
|
|
39
|
+
|
|
40
|
+
[*section[:records].to_a.flat_map { it[:fields] }, *section[:template_fields]]
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
# `a[b][3][c]` and `a[b][__INDEX__][c]` are the same field in different rows.
|
|
44
|
+
def shape(param) = param.gsub(ROW, "[#]")
|
|
45
|
+
|
|
46
|
+
def bracketed(path) = path.first + path.drop(1).map { "[#{it}]" }.join
|
|
47
|
+
|
|
48
|
+
# A textarea posts JSON text, which a host takes as a scalar `permit_params` attribute and parses.
|
|
49
|
+
# A host that permits `attr: {}` wants the structure, so it keeps one and parses JSON text into one. A summarized field was never
|
|
50
|
+
# sent its value, so blank means the client didn't load it: the stored value stays.
|
|
51
|
+
def json(node, name, value, path, summarized)
|
|
52
|
+
if summarized && (value.nil? || value == "") then node.delete(name)
|
|
53
|
+
elsif value.nil? then node[name] = ""
|
|
54
|
+
elsif value.is_a?(String) then node[name] = parse(value) if dropped?(path)
|
|
55
|
+
elsif !kept?(path) then node[name] = JSON.generate(plain(value))
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
# JSON text (a multipart upload's only way to send one) that the host's permit would drop as text, because it
|
|
60
|
+
# permits the structure; kept as text when it isn't JSON, so the permit drops it as before.
|
|
61
|
+
def parse(text)
|
|
62
|
+
parsed = JSON.parse(text)
|
|
63
|
+
(parsed.is_a?(Hash) || parsed.is_a?(Array)) ? parsed : text
|
|
64
|
+
rescue JSON::ParserError
|
|
65
|
+
text
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
# Only when the host's strong parameters are known and drop the text; unknown, the text stays as before.
|
|
69
|
+
def dropped?(path)
|
|
70
|
+
@permitted && !kept?(path) && !@allowed.nil?
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
# Whether the host's strong parameters keep the value as submitted.
|
|
74
|
+
def kept?(path)
|
|
75
|
+
@allowed = @permitted&.call unless defined?(@allowed)
|
|
76
|
+
!@allowed&.dig(*path).nil?
|
|
77
|
+
rescue
|
|
78
|
+
false
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
def plain(value)
|
|
82
|
+
case value
|
|
83
|
+
when ActionController::Parameters then value.to_unsafe_h.transform_values { plain(it) }
|
|
84
|
+
when Array then value.map { plain(it) }
|
|
85
|
+
else value
|
|
86
|
+
end
|
|
87
|
+
end
|
|
88
|
+
end
|
|
89
|
+
end
|