refactor: finalize phase 6g concern decomposition#1183
Merged
Conversation
Extract controller runtime concerns for request context, session runtime, hook lifecycle, and frontend visited-state wiring.\n\nFix admin custom field rendering fallback so missing/ string-key field_key values no longer resolve to an empty partial path, covering Footer Description and Seo Site.\n\nUpdate focused specs and phase plan notes for the combined Phase 6B scope. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
[skip ci] Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
- Restore PluginRoutes.all_helpers include in CamaleonController for plugin controller-side method availability. - De-duplicate concerns by including SiteHelper into RequestContextConcern and SessionHelper/EmailHelper into SessionRuntimeConcern (single source of truth). - Restore backwards-compatibility ivars (@current_site, @user, @_front_breadcrumb, @_hooks_skip honored as initial input) without making helper logic depend on them. - short_code_helper: assign locals before resolve_shortcode_theme_asset so the AssetNotFound rescue cannot reference nil; broaden theme asset regex to accept a leading slash. - .gitignore: ignore SQLite WAL/SHM files. Co-authored-by: Junie <junie@jetbrains.com>
… compatibility (#1183) Co-authored-by: Junie <junie@jetbrains.com>
…ural guard spec (#1183) Co-authored-by: Junie <junie@jetbrains.com>
Co-authored-by: Junie <junie@jetbrains.com>
Meta rows are keyed by (objectid, object_class). The #1173 polymorphic meta refactor dropped the object_class scope, so a custom field whose numeric id collided with another model's id read the wrong _default meta and lost field_key, causing the TinyMCE editor field on Theme settings to render as a plain text_box. Restore the explicit scopes and add a regression spec. Co-authored-by: Junie <junie@jetbrains.com>
…cessor Co-authored-by: Junie <junie@jetbrains.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What and Why
This PR finalizes the Phase 6G runtime concern decomposition of
CamaleonControllerand follows up with a comprehensive set of bug fixes discovered during code review and manual testing of the refactored code.Refactor goals (original commits):
CamaleonCms::CamaleonControllerinto focused*RuntimeConcern/*LifecycleConcernmodules underapp/controllers/concerns/camaleon_cms/includeof the corresponding helper module (single source of truth)PluginRoutes.all_helperscontroller-side inclusion so plugin helper methods remain reachable from controllers@current_site,@user,@_front_breadcrumb,@_hooks_skip) out of shared view helpers (which Rails mixes into every view) and into the controller concerns exclusively, eliminating view ivar pollution while preserving backwards compatibility for gems/plugins/themesBug fixes (code-review follow-ups):
NoMethodError (undefined method 'theme_asset')raised when plugin/theme hooks (e.g. a theme'son_install_theme) run in controller context:RuntimeShortcodeThemeConcernnowincludesCamaleonCms::ThemeHelperinstead of duplicating only a subset of its methods, restoringtheme_asset/theme_gem_assetaliases plustheme_view/theme_layouton the controller runtime stackNoMethodError (undefined method 'cama_captcha_tag')raised when shortcodes/forms rendered in controller context (e.g. the contact-form plugin) call captcha rendering helpers:SessionCaptchaRuntimeConcernnowincludesCamaleonCms::CaptchaHelperinstead of re-implementing only the under-attack session countersNoMethodError (undefined method 'cama_content_append')raised when plugin hooks running in controller context (e.g.camaleon_post_order'son_list_poston the admin posts list) call thecama_content_*helpers:RuntimeHtmlContentConcernnowincludesCamaleonCms::ContentHelperinstead of duplicating onlycama_content_init/cama_content_stateapp/apps/themes/<site_id>/views) no longer being rendered on the frontend:FrontendController#configure_frontend_lookup_prefixesagain appends thethemes/<site_id>/viewslookup prefix (guarded byDir.exist?) ahead of the active theme prefix, so site-specific overrides take precedenceActionView::MissingTemplateraised when a plugin front controller renders one of its own templates (e.g./store/plugins/ecommerce=>render 'detail'): theLookupContext#find/#exists?override (added in fix: Phase 5 — Restore theme preview rendering and bootstrap missing nav menus #1181) dropped the plugin'sinit_plugin-prependedplugins/<name>/views/...lookup prefix. The override now only restricts to the current theme when all explicit prefixes are theme-scoped; otherwise it mergesself.prefixesas beforephoto.jpg=>thumb/photo-jpg.png).CamaleonCmsLocalUploader#file_parseand#objectsnow fall back to the legacy.pngthumbnail when the computed thumb is missing on disk but a.pngsibling exists (backwards-compatible).icofavicons):cama_compat_legacy_thumbnow falls back to the original file URL when neither the computed thumb nor a legacy.pngsibling exists on diskdefaulttheme's Genericons webfont:themes/default/assets/genericons/genericons.cssreferenced font files with relativeurl('font/...')paths that the browser resolves against the page root. The three@font-facereferences (.eot/.ttf/.svg) now use absolute asset-pipeline pathsNoMethodError (undefined method 'to_sym' for nil)raised when editing a custom field group that contains a legacy/orphaned field whose stored options have nofield_key:_get_items.html.erbnow guards against a blank@keyso the form renders instead of crashing<!--:en-->sample-post<!--:--><!--:ru-->sample-post<!--:-->not matching/sample-post), while it worked on 2.9.2: restored the multi-language-awareCamaleonCms::PostDefault.find_by_slugfinder at the post lookup sites and converted every slug lookup that should be locale-aware fromfind_by(slug:)tofind_by_slug(frontend controller, decorators,Site#get_valid_post_slug,PostType#default_category, nav-menu/shortcode/custom-field call sites). Each call carries an inline# rubocop:disable Rails/DynamicFindByfor visibilitySprockets::Rails::Helper::AssetNotPrecompiledErrorfor plugin/theme assets (sample: editing a post raised it forplugins/visibility_post/assets/js/form.jswhen the Sprockets manifest cache was cold/incomplete): on Sprockets >= 4 (withunknown_asset_fallbackdisabled) the gem's precompile declaration was gated to Sprockets 3 only and used aproc/glob, so on Sprockets 4 plugin/theme assets were not reliably declared as precompiled. The newCamaleonCms::AssetsPrecompile.logical_pathsenumerates the concrete plugin/theme asset files from the real Sprockets load paths (config.assets.paths) and declares their exact logical paths inconfig.assets.precompileas plain strings — the canonical, Sprockets-version-agnostic form. This covers host, gem-bundled (e.g.visibility_post) and separately gem-packagedgem_modeplugins/themes (e.g.plugins/cama_contact_form/admin_editor.js), matching the reach of the oldproc.Added in the last 2 commits:
object_classscoping onCustomFieldmetas (67b3dbb)-> { where(object_class: '...') }scopes onCustomField#metasandCustomFieldGroup#metas.CustomFieldand other models (e.g.,Post), leading to incorrect meta resolution.editorfield key, defaulting to a plain text box.Sprockets::Rails::AssetUrlProcessorincorrectly rewriting the TinyMCE skin's relative font URLs to invalid absolute paths.AssetUrlProcessorwith aTinymceSkinSafeAssetUrlProcessorsubclass that selectively expands relative URLs for the TinyMCE skin to full logical asset paths before delegating to the original processor for digest-rewriting.config.assets.versionto'1.1'to invalidate stale cached assets.Changes
Concern decomposition (64 files, ~2,950 insertions / 270 deletions)
app/controllers/concerns/camaleon_cms/RequestContextConcern,SessionRuntimeConcern,SessionCaptchaRuntimeConcern,HookLifecycleConcern,RuntimeHtmlContentConcern,RuntimeShortcodeThemeConcern,RuntimeUploaderConcernapp/controllers/camaleon_cms/camaleon_controller.rbPluginRoutes.all_helpersinclusion restoredapp/helpers/camaleon_cms/app/uploaders/camaleon_cms_local_uploader.rb.pngsibling, original URL)app/controllers/camaleon_cms/frontend_controller.rbthemes/<site_id>/viewslookup prefixconfig/initializers/action_view.rbapp/views/.../custom_fields/_get_items.html.erb@keyfor orphaned fieldsapp/apps/themes/default/assets/genericons/genericons.csslib/camaleon_cms/assets_precompile.rbconfig/initializers/assets.rbAssetUrlProcessorfor TinyMCE icons (development)app/models/camaleon_cms/custom_field.rbobject_classscope for metasSpecs added / updated
spec/find_by_slug_usage_spec.rb— new organic, behavioural guard spec ensuring multi-language-aware slug lookups don't revert tofind_by(slug:)spec/lib/camaleon_cms/assets_precompile_spec.rb— new spec for comprehensive asset precompile enumeration (incl.gem_mode)spec/controllers/concerns/camaleon_cms/— 4 new concern specs (request context, session runtime, session captcha, runtime state aggregate)spec/controllers/camaleon_cms/frontend_controller_lookup_prefixes_spec.rb— extended with site-override and plugin-prefix assertionsspec/initializers/action_view_lookup_context_spec.rb— new spec for the LookupContext overridespec/uploaders/local_uploader_spec.rb— 19 examples covering legacy thumb fallback, favicon fallback, andobjectscorrectionspec/views/camaleon_cms/admin/settings/custom_fields/— new view specs for_get_itemsand_renderpartialsspec/helpers/— extended coverage for hooks, theme, nav-menu, session, shortcode helpersspec/models/camaleon_cms/custom_field_metas_scope_spec.rb— new regression spec for meta ID collisionsspec/initializers/tinymce_asset_url_processor_spec.rb— new regression spec for TinyMCE skin font resolutionUser-Visible Impact
Plugin/theme authors: back-compat ivars (
@current_site,@user,@_front_breadcrumb,@_hooks_skip) are still assigned for templates and plugins — they are now set by controller concerns rather than helpers. No action required.Upgraders: the bugs fixed above (missing methods in controller context, broken site-override views, legacy thumbnail 404s, plugin template lookup, Sprockets 4 incompatibilities, missing TinyMCE icons/frame) were regressions introduced by the Phase 6G refactor commits or pre-existing latent issues; all are resolved in this PR.
Test Results
Full suite (
bin/rspec): 0 failures (15 pre-existing ImageMagick-dependent failures in environments without ImageMagick are unrelated to this PR). Organic guard specs (find_by_slug, assets precompile, TinyMCE, metas scope): 30 examples, 0 failures.