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,73 @@
|
|
|
1
|
+
module ReactiveAdmin
|
|
2
|
+
# `?embed=1` on a classic URL: the same page without AA's chrome, plus a bridge that tells the
|
|
3
|
+
# embedding window about size, navigation and flashes. Meant for iframes on the same origin.
|
|
4
|
+
module Embed
|
|
5
|
+
LAYOUT = "reactive_admin/embed".freeze
|
|
6
|
+
CHROME = "#{AA.chrome_selectors} {display: none !important}".freeze
|
|
7
|
+
BRIDGE = File.expand_path("../../app/assets/reactive_admin/bridge.js", __dir__)
|
|
8
|
+
|
|
9
|
+
def self.bridge_js
|
|
10
|
+
return File.read(BRIDGE) if Rails.application.config.enable_reloading
|
|
11
|
+
|
|
12
|
+
@bridge_js ||= File.read(BRIDGE)
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
# Standard AA actions build the whole document themselves, so the chrome can only be hidden
|
|
16
|
+
# and the bridge appended; custom actions get the embed layout instead.
|
|
17
|
+
def self.inject(html, nonce: nil)
|
|
18
|
+
return html if html.include?("data-reactiveadmin-embed") || !html.match?(/<\/body>/i)
|
|
19
|
+
|
|
20
|
+
attribute = %( nonce="#{ERB::Util.h(nonce)}") if nonce
|
|
21
|
+
html.sub(/<body\b([^>]*)>/i) { "<body#{$1} data-reactiveadmin-embed>" }
|
|
22
|
+
.sub(/<\/head>/i) { "<style>#{CHROME}</style></head>" }
|
|
23
|
+
.sub(/<\/body>/i) { "<script#{attribute}>#{bridge_js}</script></body>" }
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
# A redirect keeps the request inside the embed.
|
|
27
|
+
def self.carry(url, request)
|
|
28
|
+
uri = URI.parse(url.to_s)
|
|
29
|
+
return url if uri.host.present? && uri.host != request.host
|
|
30
|
+
|
|
31
|
+
uri.query = Rack::Utils.parse_query(uri.query.to_s).merge("embed" => "1").to_query
|
|
32
|
+
uri.to_s
|
|
33
|
+
rescue URI::InvalidURIError
|
|
34
|
+
url
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def redirect_to(options = {}, response_options = {})
|
|
38
|
+
return super unless embed_request?
|
|
39
|
+
|
|
40
|
+
super(Embed.carry(url_for(options), request), response_options)
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def render(*args, &)
|
|
44
|
+
embed_request? ? super(*Layouts.replace(args, LAYOUT), &) : super
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
private
|
|
48
|
+
|
|
49
|
+
def embed_request?
|
|
50
|
+
return @embed_request if defined?(@embed_request)
|
|
51
|
+
|
|
52
|
+
@embed_request = params[:embed] == "1" && !reactiveadmin_request? && !frame_request?
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
def process_action(*)
|
|
56
|
+
super
|
|
57
|
+
finish_embed if embed_request?
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
def finish_embed
|
|
61
|
+
response.headers["X-Frame-Options"] = "SAMEORIGIN"
|
|
62
|
+
return unless response.media_type == "text/html" && response.body.present? && response.headers["Content-Disposition"].blank?
|
|
63
|
+
|
|
64
|
+
response.body = Embed.inject(response.body, nonce: request.content_security_policy_nonce)
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
define_method(AA.layout_hook) do
|
|
68
|
+
layout = super()
|
|
69
|
+
(embed_request? && layout) ? LAYOUT : layout
|
|
70
|
+
end
|
|
71
|
+
private AA.layout_hook
|
|
72
|
+
end
|
|
73
|
+
end
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
module ReactiveAdmin
|
|
2
|
+
class Engine < ::Rails::Engine
|
|
3
|
+
initializer "reactiveadmin.mime" do
|
|
4
|
+
Mime::Type.register "application/vnd.reactiveadmin+json", :reactiveadmin unless Mime[:reactiveadmin]
|
|
5
|
+
end
|
|
6
|
+
|
|
7
|
+
initializer "reactiveadmin.server_timing" do |app|
|
|
8
|
+
app.middleware.insert_after ActionDispatch::RequestId, ServerTiming
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
initializer "reactiveadmin.token_requests" do |app|
|
|
12
|
+
app.middleware.insert_after ServerTiming, Auth::TokenRequests
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
initializer "reactiveadmin.provenance" do
|
|
16
|
+
ActiveSupport.on_load(:action_view) { prepend Provenance::Helpers }
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
# Innermost, so the host's own middleware (CSP headers, host authorization) wraps the shell as it does any page.
|
|
20
|
+
initializer "reactiveadmin.ui_shell" do |app|
|
|
21
|
+
app.middleware.use Ui::Shell
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
initializer "reactiveadmin.ui_helper" do
|
|
25
|
+
ActiveSupport.on_load(:action_view) { include Ui::Helper }
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
# The overlay is redefined by the host's app/admin files on every AA (re)load.
|
|
29
|
+
initializer "reactiveadmin.menu_overlay" do
|
|
30
|
+
AA.on_before_load { MenuOverlay.reset! }
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
# Prepended so custom controller overrides that call super still reach us.
|
|
34
|
+
config.to_prepare do
|
|
35
|
+
Typeahead.install
|
|
36
|
+
AA.prepend_display_helper(CompositeKeys::DisplayName)
|
|
37
|
+
AA.prepend_csv_builder(Masking::Csv, CsvInjection, QueryGuard::ExportBuilder)
|
|
38
|
+
AA.prepend_tag(Provenance::Tags)
|
|
39
|
+
AA.extend_page(dsl: ResourceDSL, config: ResourceOptions)
|
|
40
|
+
AA.prepend_controller_extensions(
|
|
41
|
+
page: [Auth::Authentication, ApiErrors, Exposure::Guard, ApiGuards::Guard, PageControllerExtension, RateLimit::Guard, BackgroundRequests, ApiFallback, ApiGuards::Backstop, Auth::Request, Ui::Switch],
|
|
42
|
+
# Exposure and ApiGuards sit inside ControllerExtension so they answer before declared-action authorization.
|
|
43
|
+
resource: [Auth::Authentication, ApiErrors, Exposure::Guard, ApiGuards::Guard, ControllerExtension, RateLimit::Guard, QueryGuard::Guard, RansackGuard, BackgroundRequests, ApiFallback, ApiGuards::Backstop, Auth::Request, Ui::Switch]
|
|
44
|
+
)
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
end
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
module ReactiveAdmin
|
|
2
|
+
# Rails keys errors by attribute (`category` for a missing association, `category_id`
|
|
3
|
+
# for its uniqueness), while a client shows one field. Renames each key to the `name` of the field that
|
|
4
|
+
# posts that attribute and merges the messages. Keys inside has_many rows are already `assoc.attr`.
|
|
5
|
+
class ErrorKeys
|
|
6
|
+
def self.call(errors, sections) = new(sections).call(errors)
|
|
7
|
+
|
|
8
|
+
def initialize(sections)
|
|
9
|
+
fields = sections.flat_map { (it[:kind] == "has_many") ? [] : it[:fields].to_a }.select { it[:param] }
|
|
10
|
+
@names = fields.to_h { [it[:name], it[:name]] }
|
|
11
|
+
fields.each do |field|
|
|
12
|
+
attribute = field[:param][/\[(\w+)\](?:\[\])?\z/, 1]
|
|
13
|
+
[attribute, field[:name].delete_suffix("_id"), "#{field[:name]}_id"].each { @names[it] ||= field[:name] }
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def call(errors)
|
|
18
|
+
errors.each_with_object({}) do |(key, messages), mapped|
|
|
19
|
+
(mapped[@names.fetch(key.to_s) { key.to_s }] ||= []).concat(messages).uniq!
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
module ReactiveAdmin
|
|
2
|
+
# With `config.expose = :listed` the API serves only what the host names: resources and pages
|
|
3
|
+
# placed in the menu overlay, keys in `config.exposed_resources`, and anything marked
|
|
4
|
+
# `reactive { expose true }`. Everything else answers 404 whatever the authorization policy says.
|
|
5
|
+
# A nested-only resource also needs its parent to be exposed. `reactive { expose false }` denies
|
|
6
|
+
# outright. Classic ActiveAdmin is unaffected.
|
|
7
|
+
module Exposure
|
|
8
|
+
# Prepended to AA's controllers so every API endpoint is covered in one place: after
|
|
9
|
+
# authentication (signed-out clients learn nothing) and before any authorization.
|
|
10
|
+
module Guard
|
|
11
|
+
private
|
|
12
|
+
|
|
13
|
+
def authenticate_active_admin_user
|
|
14
|
+
super
|
|
15
|
+
return if performed? || !reactiveadmin_request?
|
|
16
|
+
return if Exposure.allowed?(active_admin_config)
|
|
17
|
+
|
|
18
|
+
render_api_error(:not_found, "Not found", 404)
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
module_function
|
|
23
|
+
|
|
24
|
+
def listed? = ReactiveAdmin.config.expose == :listed
|
|
25
|
+
|
|
26
|
+
# `config` is an ActiveAdmin resource or page.
|
|
27
|
+
def allowed?(config)
|
|
28
|
+
return true unless listed?
|
|
29
|
+
|
|
30
|
+
explicit = config.reactive_options[:expose]
|
|
31
|
+
return false if explicit == false
|
|
32
|
+
return false unless explicit || listed_keys(config).include?(key(config))
|
|
33
|
+
|
|
34
|
+
!Paths.nested?(config) || allowed?(config.belongs_to_config.target)
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def key(config) = page?(config) ? Menu.page_key(config) : Registry.route_key(config)
|
|
38
|
+
|
|
39
|
+
# Findings for `doctor`: listed keys that match nothing and, given a user, what the policy
|
|
40
|
+
# permits but the host has not exposed.
|
|
41
|
+
def audit(user: nil) = [*unknown_keys, *permitted_not_exposed(user)]
|
|
42
|
+
|
|
43
|
+
def page?(config) = AA.page?(config)
|
|
44
|
+
|
|
45
|
+
# Rebuilt when the overlay, the registrations or the configured list change.
|
|
46
|
+
def listed_keys(config)
|
|
47
|
+
stamp = [MenuOverlay.version, Registry.index.object_id, listed_config]
|
|
48
|
+
@listed = nil unless @stamp == stamp
|
|
49
|
+
@stamp = stamp
|
|
50
|
+
@listed ||= {
|
|
51
|
+
resource: Set.new([*MenuOverlay.keys(:resource), *placed_by_hint, *listed_config]),
|
|
52
|
+
page: Set.new([*MenuOverlay.keys(:page), *listed_config, *root_page_key])
|
|
53
|
+
}
|
|
54
|
+
@listed.fetch(page?(config) ? :page : :resource)
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
# The namespace's home (`root_to`) is where the shell lands, menu or not.
|
|
58
|
+
def root_page_key = AA.root_page_key(Registry.namespace)
|
|
59
|
+
|
|
60
|
+
def listed_config = Array(ReactiveAdmin.config.exposed_resources).map(&:to_s)
|
|
61
|
+
|
|
62
|
+
def placed_by_hint
|
|
63
|
+
Registry.resources.filter_map { Registry.route_key(it) if it.reactive_options[:menu]&.key?(:path) }
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
def unknown_keys
|
|
67
|
+
known = [*Registry.resources, *Registry.pages].map { key(it) }
|
|
68
|
+
(listed_config - known).map { {kind: :exposure_unknown_key, key: it} }
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
def permitted_not_exposed(user)
|
|
72
|
+
return [] unless listed? && user
|
|
73
|
+
|
|
74
|
+
authorizer = Authorizer.new(user)
|
|
75
|
+
candidates = [*Registry.resources.select { Registry.actions(it).include?(:index) }, *Registry.pages]
|
|
76
|
+
keys = candidates.reject { allowed?(it) || ApiGuards.fully_denied?(it) }.select { permitted?(authorizer, it) }.map { key(it) }.sort
|
|
77
|
+
keys.empty? ? [] : [{kind: :exposure_permitted_not_exposed, keys: keys.join(", ")}]
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
def permitted?(authorizer, config)
|
|
81
|
+
authorizer.authorized?(AA::Auth::READ, page?(config) ? config : config.resource_class, config:)
|
|
82
|
+
rescue
|
|
83
|
+
false
|
|
84
|
+
end
|
|
85
|
+
end
|
|
86
|
+
end
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
module ReactiveAdmin
|
|
2
|
+
# Translates a resource's AA `filter` declarations into manifest controls, mirroring
|
|
3
|
+
# ActiveAdmin::Filters::FormBuilder#default_input_type and the Inputs::Filters::* param naming.
|
|
4
|
+
class Filters
|
|
5
|
+
TEXT_PREDICATES = %w[cont eq start end].freeze
|
|
6
|
+
NUMBER_PREDICATES = %w[eq gt lt].freeze
|
|
7
|
+
TYPES = {
|
|
8
|
+
string: :string, text: :string, citext: :string,
|
|
9
|
+
integer: :numeric, float: :numeric, decimal: :numeric,
|
|
10
|
+
date: :date_range, datetime: :date_range, boolean: :boolean
|
|
11
|
+
}.freeze
|
|
12
|
+
|
|
13
|
+
# `options: false` leaves out option lists (which may read records); choice controls only point at `_options`.
|
|
14
|
+
def initialize(config, view, options: true)
|
|
15
|
+
@config = config
|
|
16
|
+
@view = view
|
|
17
|
+
@klass = config.resource_class
|
|
18
|
+
@with_options = options
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
# A filter's `if:`/`unless:` hides it from this user, so its params and options are refused too.
|
|
22
|
+
def self.skip?(view, opts)
|
|
23
|
+
(opts.key?(:if) && !AA.call_on(view, view, opts[:if])) || (opts.key?(:unless) && AA.call_on(view, view, opts[:unless]))
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def call
|
|
27
|
+
AA.filters(@config).filter_map do |attr, opts|
|
|
28
|
+
next if Filters.skip?(@view, opts)
|
|
29
|
+
|
|
30
|
+
build(attr.to_s, opts)
|
|
31
|
+
rescue => e
|
|
32
|
+
Rails.logger.warn("[reactiveadmin] skipped filter #{attr} on #{@config.resource_name}: #{e.class}")
|
|
33
|
+
Degradation.record(kind: :filter_dropped, where: "index/filter[#{attr}]", reason: "Filter raised #{e.class}; left out")
|
|
34
|
+
nil
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def choices(name)
|
|
39
|
+
declared = AA.filters(@config).find { |attr, _| attr.to_s == name }
|
|
40
|
+
raise ActiveRecord::RecordNotFound, "No filter #{name}" unless declared && !Filters.skip?(@view, declared.last)
|
|
41
|
+
|
|
42
|
+
choices_for(name, declared.last)
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
private
|
|
46
|
+
|
|
47
|
+
def build(name, opts)
|
|
48
|
+
type = (opts[:as] || default_type(name))&.to_sym or return
|
|
49
|
+
base = {name:, label: label(name, opts)}
|
|
50
|
+
|
|
51
|
+
case type
|
|
52
|
+
when :string, :text then base.merge(control: "text", **predicates(name, TEXT_PREDICATES, single: type == :text))
|
|
53
|
+
when :numeric then base.merge(control: "number", **predicates(name, NUMBER_PREDICATES))
|
|
54
|
+
when :date_range, :date_picker then base.merge(control: "date_range", range: {from: "#{name}_gteq", to: "#{name}_lteq"})
|
|
55
|
+
when :boolean then base.merge(control: "boolean", param: searchable?(name) ? name : "#{name}_eq", options: boolean_options)
|
|
56
|
+
when :select then choice(base, "select", name, opts)
|
|
57
|
+
when :check_boxes then choice(base, "checkboxes", name, opts)
|
|
58
|
+
when :datalist, :typeahead then choice(base, "typeahead", name, opts)
|
|
59
|
+
else raise ArgumentError, "unsupported filter type #{type}"
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
def default_type(name)
|
|
64
|
+
if name.match?(/_(eq|cont|start|end)\z/) then :string
|
|
65
|
+
elsif @klass._ransackers.key?(name) then TYPES[@klass._ransackers[name].type]
|
|
66
|
+
elsif reflection(name) || polymorphic_foreign_key?(name) then :select
|
|
67
|
+
elsif (column = @klass.columns_hash[name]) then TYPES[column.type]
|
|
68
|
+
end
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
def label(name, opts)
|
|
72
|
+
label = opts[:label]
|
|
73
|
+
label = label.call if label.is_a?(Proc)
|
|
74
|
+
(label || @klass.human_attribute_name(name)).to_s
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
def predicates(name, list, single: false)
|
|
78
|
+
return {param: name} if single || name.match?(/_(eq|cont|start|end|gt|lt)\z/)
|
|
79
|
+
|
|
80
|
+
{predicates: list.map { {param: "#{name}_#{it}", label: I18n.t("ransack.predicates.#{it}", default: it).capitalize} }}
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
def boolean_options = [{label: "Yes", value: "true"}, {label: "No", value: "false"}]
|
|
84
|
+
|
|
85
|
+
# Option lists backed by a relation are searched through the _options endpoint rather than
|
|
86
|
+
# queried here: the metadata of a resource with many such filters would otherwise run one
|
|
87
|
+
# query per filter on every cold load.
|
|
88
|
+
def choice(base, control, name, opts)
|
|
89
|
+
param = (control == "checkboxes") ? checkboxes_param(name) : choice_param(name, opts)
|
|
90
|
+
base = base.merge(param:, **(param.end_with?("_in") ? {multiple: true} : {}))
|
|
91
|
+
return base.merge(control:, options_path: Choices.path(@config, name, "filter")) unless @with_options
|
|
92
|
+
|
|
93
|
+
source = choices_for(name, opts)
|
|
94
|
+
listing = source.list([], ReactiveAdmin.config.inline_options_limit) unless source.is_a?(Choices::Records)
|
|
95
|
+
if listing.nil? || listing[:truncated]
|
|
96
|
+
base.merge(control: "typeahead", options: selected(source, base[:param]), options_path: Choices.path(@config, name, "filter"))
|
|
97
|
+
else
|
|
98
|
+
base.merge(control:, options: listing[:options])
|
|
99
|
+
end
|
|
100
|
+
rescue => e
|
|
101
|
+
Rails.logger.warn("[reactiveadmin] no options for filter #{name} on #{@config.resource_name}: #{e.class}")
|
|
102
|
+
Degradation.record(kind: :filter_options_failed, where: "index/filter[#{name}]", reason: "Filter options raised #{e.class}; shown without options")
|
|
103
|
+
base.merge(control:, options: [])
|
|
104
|
+
end
|
|
105
|
+
|
|
106
|
+
# A typeahead only carries the options that are currently selected; the rest are searched.
|
|
107
|
+
def selected(source, param)
|
|
108
|
+
values = Array(@view.params.dig(:q, param)).map(&:to_s).compact_blank
|
|
109
|
+
values.any? ? source.lookup(values) : []
|
|
110
|
+
end
|
|
111
|
+
|
|
112
|
+
def choice_param(name, opts)
|
|
113
|
+
return name if searchable?(name)
|
|
114
|
+
|
|
115
|
+
ref = reflection(name)
|
|
116
|
+
key = (ref && !ref.polymorphic?) ? "#{name}_#{ref.association_primary_key}" : name
|
|
117
|
+
key + (opts[:multiple] ? "_in" : "_eq")
|
|
118
|
+
end
|
|
119
|
+
|
|
120
|
+
# AA's check_boxes input always filters with `_in`, on the association's foreign key or ids.
|
|
121
|
+
def checkboxes_param(name)
|
|
122
|
+
return name if searchable?(name)
|
|
123
|
+
|
|
124
|
+
ref = reflection(name)
|
|
125
|
+
key = if ref.nil? then name
|
|
126
|
+
elsif through?(ref) then "#{ref.through_reflection.name}_#{ref.foreign_key}"
|
|
127
|
+
elsif ref.collection? then "#{name.singularize}_ids"
|
|
128
|
+
else ref.foreign_key
|
|
129
|
+
end
|
|
130
|
+
"#{key}_in"
|
|
131
|
+
end
|
|
132
|
+
|
|
133
|
+
def through?(ref)
|
|
134
|
+
ref.options[:through] && @klass.ransackable_associations.include?(ref.name.to_s) &&
|
|
135
|
+
ref.through_reflection.klass.ransackable_attributes.include?(ref.foreign_key)
|
|
136
|
+
rescue
|
|
137
|
+
false
|
|
138
|
+
end
|
|
139
|
+
|
|
140
|
+
def choices_for(name, opts)
|
|
141
|
+
ref = reflection(name)
|
|
142
|
+
value = ref&.association_primary_key || :id
|
|
143
|
+
cache = Choices.cache_key(@config, "filter", name, @view)
|
|
144
|
+
return Choices.source(opts[:source], @view, scope: opts[:scope], policy: true, cache:) if opts[:source]
|
|
145
|
+
return Choices.for(opts[:collection], @view, value:, cache:, policy: true) if opts[:collection]
|
|
146
|
+
return Choices.for(ref.klass, @view, value:, policy: true) if ref && !ref.polymorphic?
|
|
147
|
+
|
|
148
|
+
@klass.columns_hash.key?(name) ? Choices.column(AA.scoped_collection(@view.controller), name, @view) : Choices.for([], @view)
|
|
149
|
+
end
|
|
150
|
+
|
|
151
|
+
def reflection(name) = @klass.reflect_on_association(name)
|
|
152
|
+
|
|
153
|
+
def polymorphic_foreign_key?(name)
|
|
154
|
+
@klass.reflect_on_all_associations.any? { it.macro == :belongs_to && it.options[:polymorphic] && it.foreign_type == name }
|
|
155
|
+
end
|
|
156
|
+
|
|
157
|
+
# Ransack already understands names that carry a predicate or are exposed scopes.
|
|
158
|
+
def searchable?(name)
|
|
159
|
+
return false if @klass.columns_hash.key?(name)
|
|
160
|
+
|
|
161
|
+
Ransack::Predicate.detect_from_string(name).present? ||
|
|
162
|
+
Ransack::Context.for(@klass).ransackable_scope?(name, @klass)
|
|
163
|
+
end
|
|
164
|
+
end
|
|
165
|
+
end
|