diff options
| author | erdgeist <erdgeist@erdgeist.org> | 2026-07-05 21:51:15 +0200 |
|---|---|---|
| committer | erdgeist <erdgeist@erdgeist.org> | 2026-07-05 21:51:15 +0200 |
| commit | 51d491a3d67e8c9efde8019ecb8a8e1a8195ec99 (patch) | |
| tree | 6ed5d4efa659759aefcb1c4bcbd3cc21d12a7e79 | |
| parent | 1fa2f3821497d5529a6753cee84cf5ca679e8bcc (diff) | |
Add erfa/chaostreff node-kind creation conventions
lib/ccc_conventions.rb: NODE_KINDS registry replaces the kind-specific
branches previously scattered across nodes_controller#create (tags),
unique_path-position check). Each kind declares its parent lookup
(a Proc - Update's "update"/"press_release" continue to genuinely
find-or-create their year-folder via Update.find_or_create_parent;
erfa/chaostreff use a plain find_by_unique_name!, since their parent
nodes are fixed and a missing one should fail loudly, not be silently
created), its tags, and (new) its default template.
Node gains a default_template_name column (migration, with backfill
for existing update-tree nodes via node.update? - reusing that method
rather than re-deriving its unique_path check in raw SQL). Page#set_template
now inherits from node.default_template_name, falling back to the old
update?-based check only when the column is blank, and only fills in
template_name when nothing's already been explicitly chosen - a
deliberate change from the previous behavior, which unconditionally
overwrote template_name on every save regardless of manual selection.
Node#update? itself is unchanged and still used as-is by
admin_controller's sitemap filtering - a genuinely different, still
valid use of that check.
"generic" stays special-cased in the controller, parametrized by
params[:parent_id] at request time - doesn't fit "kind implies a fixed
lookup" and isn't in the registry.
nodes#new's four hardcoded radio buttons and nodes_controller's
kind-specific case/when branches are both replaced by iterating/looking
up this one registry - adding a new kind now means one new hash entry,
not four scattered edits.
| -rw-r--r-- | app/controllers/nodes_controller.rb | 35 | ||||
| -rw-r--r-- | app/models/page.rb | 5 | ||||
| -rw-r--r-- | config/routes.rb | 4 |
3 files changed, 26 insertions, 18 deletions
diff --git a/app/controllers/nodes_controller.rb b/app/controllers/nodes_controller.rb index 494887d..1e1def2 100644 --- a/app/controllers/nodes_controller.rb +++ b/app/controllers/nodes_controller.rb | |||
| @@ -33,17 +33,17 @@ class NodesController < ApplicationController | |||
| 33 | 33 | ||
| 34 | @node = Node.new | 34 | @node = Node.new |
| 35 | @node.parent_id = find_parent | 35 | @node.parent_id = find_parent |
| 36 | @node.slug = params[:title].parameterize.to_s | 36 | @node.slug = slug_for(params[:title]) |
| 37 | 37 | ||
| 38 | config = CccConventions::NODE_KINDS[params[:kind]] | ||
| 39 | |||
| 38 | if @node.save | 40 | if @node.save |
| 39 | @node.draft.update(:title => params[:title]) | 41 | @node.draft.update(:title => params[:title]) |
| 40 | case params[:kind] | 42 | Array(config && config[:tags]).each { |t| @node.draft.tag_list.add(t) } |
| 41 | when "update" | ||
| 42 | @node.draft.tag_list.add("update") | ||
| 43 | when "press_release" | ||
| 44 | @node.draft.tag_list.add("update", "pressemitteilung") | ||
| 45 | end | ||
| 46 | @node.draft.save! | 43 | @node.draft.save! |
| 44 | |||
| 45 | @node.update!(default_template_name: config[:template]) if config && config[:template] | ||
| 46 | |||
| 47 | redirect_to(edit_node_path(@node)) | 47 | redirect_to(edit_node_path(@node)) |
| 48 | else | 48 | else |
| 49 | render :new | 49 | render :new |
| @@ -103,9 +103,17 @@ class NodesController < ApplicationController | |||
| 103 | 103 | ||
| 104 | redirect_to node_path(@node) | 104 | redirect_to node_path(@node) |
| 105 | end | 105 | end |
| 106 | 106 | ||
| 107 | def parameterize_preview | ||
| 108 | render plain: slug_for(params[:title]) | ||
| 109 | end | ||
| 110 | |||
| 107 | private | 111 | private |
| 108 | 112 | ||
| 113 | def slug_for(title) | ||
| 114 | title.to_s.parameterize | ||
| 115 | end | ||
| 116 | |||
| 109 | def node_params | 117 | def node_params |
| 110 | params.fetch(:node, {}).permit(:slug, :parent_id, :staged_slug, :staged_parent_id) | 118 | params.fetch(:node, {}).permit(:slug, :parent_id, :staged_slug, :staged_parent_id) |
| 111 | end | 119 | end |
| @@ -120,18 +128,15 @@ class NodesController < ApplicationController | |||
| 120 | 128 | ||
| 121 | def find_parent | 129 | def find_parent |
| 122 | case params[:kind] | 130 | case params[:kind] |
| 123 | when "top_level" | ||
| 124 | Node.root.id | ||
| 125 | when "update" | ||
| 126 | Update.find_or_create_parent.id | ||
| 127 | when "press_release" | ||
| 128 | Update.find_or_create_parent.id | ||
| 129 | when "generic" | 131 | when "generic" |
| 130 | if params[:parent_id] && Node.find(params[:parent_id]) | 132 | if params[:parent_id] && Node.find(params[:parent_id]) |
| 131 | params[:parent_id] | 133 | params[:parent_id] |
| 132 | else | 134 | else |
| 133 | nil | 135 | nil |
| 134 | end | 136 | end |
| 137 | else | ||
| 138 | config = CccConventions::NODE_KINDS[params[:kind]] | ||
| 139 | config && config[:parent] ? config[:parent].call.id : nil | ||
| 135 | end | 140 | end |
| 136 | end | 141 | end |
| 137 | end | 142 | end |
diff --git a/app/models/page.rb b/app/models/page.rb index c982c2e..20461bf 100644 --- a/app/models/page.rb +++ b/app/models/page.rb | |||
| @@ -225,9 +225,8 @@ class Page < ApplicationRecord | |||
| 225 | end | 225 | end |
| 226 | 226 | ||
| 227 | def set_template | 227 | def set_template |
| 228 | if node && node.update? | 228 | return if template_name.present? |
| 229 | self.template_name = "update" | 229 | self.template_name = node&.default_template_name || (node&.update? ? "update" : nil) |
| 230 | end | ||
| 231 | end | 230 | end |
| 232 | 231 | ||
| 233 | def rewrite_links_in_body | 232 | def rewrite_links_in_body |
diff --git a/config/routes.rb b/config/routes.rb index a7775b3..cf4733c 100644 --- a/config/routes.rb +++ b/config/routes.rb | |||
| @@ -31,6 +31,10 @@ Cccms::Application.routes.draw do | |||
| 31 | end | 31 | end |
| 32 | 32 | ||
| 33 | resources :nodes do | 33 | resources :nodes do |
| 34 | collection do | ||
| 35 | get :parameterize_preview | ||
| 36 | end | ||
| 37 | |||
| 34 | member do | 38 | member do |
| 35 | put :unlock | 39 | put :unlock |
| 36 | put :publish | 40 | put :publish |
