summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorerdgeist <erdgeist@erdgeist.org>2026-08-06 13:30:38 +0200
committererdgeist <erdgeist@erdgeist.org>2026-08-06 13:30:38 +0200
commit5644fffbc3c58e6dd7e3c4103c28bad8f4c0bbc6 (patch)
treebc58310f60ac37c5d6927177d5d09a28a05a2b3b /app
parent2da0ce9f3c4bdbe12a80a0d28e964e9658c53f31 (diff)
Let editors set a node external homepage, gated and witnessed
Diffstat (limited to 'app')
-rw-r--r--app/controllers/nodes_controller.rb3
-rw-r--r--app/helpers/node_actions_helper.rb12
-rw-r--r--app/models/node.rb20
-rw-r--r--app/models/node_action.rb1
-rw-r--r--app/views/nodes/edit.html.erb6
5 files changed, 40 insertions, 2 deletions
diff --git a/app/controllers/nodes_controller.rb b/app/controllers/nodes_controller.rb
index 5b919b1f..22606674 100644
--- a/app/controllers/nodes_controller.rb
+++ b/app/controllers/nodes_controller.rb
@@ -116,7 +116,8 @@ class NodesController < ApplicationController
116 rescue LockedByAnotherUser => e 116 rescue LockedByAnotherUser => e
117 flash[:error] = e.message 117 flash[:error] = e.message
118 redirect_to node_path(@node) 118 redirect_to node_path(@node)
119 rescue ActiveRecord::RecordInvalid 119 rescue ActiveRecord::RecordInvalid => e
120 flash.now[:error] = e.record.errors.full_messages.to_sentence
120 @page = @node.autosave || @node.draft || @node.head 121 @page = @node.autosave || @node.draft || @node.head
121 render :action => :edit 122 render :action => :edit
122 end 123 end
diff --git a/app/helpers/node_actions_helper.rb b/app/helpers/node_actions_helper.rb
index 4cf990b8..c4de46cc 100644
--- a/app/helpers/node_actions_helper.rb
+++ b/app/helpers/node_actions_helper.rb
@@ -28,7 +28,8 @@ module NodeActionsHelper
28 "admin_revoke" => "shield-minus", 28 "admin_revoke" => "shield-minus",
29 "event_create" => "calendar-plus", 29 "event_create" => "calendar-plus",
30 "event_update" => "calendar-event", 30 "event_update" => "calendar-event",
31 "event_destroy" => "calendar-x" 31 "event_destroy" => "calendar-x",
32 "node_external_url" => "world"
32 }.freeze 33 }.freeze
33 34
34 def verb_icon action 35 def verb_icon action
@@ -64,6 +65,7 @@ module NodeActionsHelper
64 return true if m["translation_diff"].present? 65 return true if m["translation_diff"].present?
65 return true if m["changes"].present? || m["description_changed"] 66 return true if m["changes"].present? || m["description_changed"]
66 return true if m["title"].is_a?(Hash) && m.dig("title", "from") != m.dig("title", "to") 67 return true if m["title"].is_a?(Hash) && m.dig("title", "from") != m.dig("title", "to")
68 return true if m["external_url"].present?
67 %w[author tags template_changed assets assets_changed assets_reordered 69 %w[author tags template_changed assets assets_changed assets_reordered
68 abstract_changed body_changed].any? { |key| m[key].present? } 70 abstract_changed body_changed].any? { |key| m[key].present? }
69 end 71 end
@@ -95,6 +97,9 @@ module NodeActionsHelper
95 end 97 end
96 items << t("node_actions.assets_reordered") if m["assets_reordered"] 98 items << t("node_actions.assets_reordered") if m["assets_reordered"]
97 items << t("node_actions.assets_changed") if m["assets_changed"] 99 items << t("node_actions.assets_changed") if m["assets_changed"]
100 items << t("node_actions.detail_external_url",
101 :from => m.dig("external_url", "from").presence || t("node_actions.event_none"),
102 :to => m.dig("external_url", "to").presence || t("node_actions.event_none")) if m["external_url"]
98 items 103 items
99 end 104 end
100 105
@@ -400,6 +405,11 @@ module NodeActionsHelper
400 event_sentence(action, "event_destroy") 405 event_sentence(action, "event_destroy")
401 end 406 end
402 407
408 def summarize_node_external_url action
409 t("node_actions.node_external_url", :actor => actor_ref(action),
410 :subject => subject_ref(action)).html_safe
411 end
412
403 def event_sentence action, key 413 def event_sentence action, key
404 if action.node 414 if action.node
405 t("node_actions.#{key}_on", :actor => actor_ref(action), 415 t("node_actions.#{key}_on", :actor => actor_ref(action),
diff --git a/app/models/node.rb b/app/models/node.rb
index f8c29b48..4b7c9772 100644
--- a/app/models/node.rb
+++ b/app/models/node.rb
@@ -42,6 +42,9 @@ class Node < ApplicationRecord
42 :inclusion => { :in => ->(_) { Page.custom_templates } }, 42 :inclusion => { :in => ->(_) { Page.custom_templates } },
43 :allow_blank => true, 43 :allow_blank => true,
44 :if => :default_template_name_changed? 44 :if => :default_template_name_changed?
45 validates :external_url, :format => { :with => %r{\Ahttps?://}i,
46 :allow_blank => true,
47 :message => :must_be_http }
45 48
46 # Everything outside the Trash subtree, the Trash node included. 49 # Everything outside the Trash subtree, the Trash node included.
47 # Relies on unique_name being authoritative for tree position -- 50 # Relies on unique_name being authoritative for tree position --
@@ -605,6 +608,23 @@ class Node < ApplicationRecord
605 self.created_at < new_id_format_date ? unique_path : id 608 self.created_at < new_id_format_date ? unique_path : id
606 end 609 end
607 610
611 def update_external_url!(url, current_user = nil)
612 normalised = url.presence
613 return false if normalised == external_url
614
615 guard_live_change!(current_user)
616 previous = external_url
617
618 transaction do
619 update!(:external_url => normalised)
620 NodeAction.record!(:node => self, :user => current_user,
621 :action => "node_external_url",
622 :path => unique_name,
623 :external_url => { "from" => previous, "to" => normalised })
624 end
625 true
626 end
627
608 # Full-text search across all locale translations using PostgreSQL tsvector. 628 # Full-text search across all locale translations using PostgreSQL tsvector.
609 # Uses 'simple' dictionary (no stemming, no stopwords) so queries work 629 # Uses 'simple' dictionary (no stemming, no stopwords) so queries work
610 # across German and English content without language detection. 630 # across German and English content without language detection.
diff --git a/app/models/node_action.rb b/app/models/node_action.rb
index bfa469b1..f1e4eaea 100644
--- a/app/models/node_action.rb
+++ b/app/models/node_action.rb
@@ -134,6 +134,7 @@ class NodeAction < ApplicationRecord
134 # from the node verbs' "tags", which is a pair, 134 # from the node verbs' "tags", which is a pair,
135 # so one renderer cannot mistake the other. 135 # so one renderer cannot mistake the other.
136 # "path" -- the node's unique_name, when it has a node 136 # "path" -- the node's unique_name, when it has a node
137 # "external_url" -- pair
137 # 138 #
138 # On "event_update" only, and only when something changed -- an 139 # On "event_update" only, and only when something changed -- an
139 # update that changes nothing records no entry at all: 140 # update that changes nothing records no entry at all:
diff --git a/app/views/nodes/edit.html.erb b/app/views/nodes/edit.html.erb
index b65416e1..c153c241 100644
--- a/app/views/nodes/edit.html.erb
+++ b/app/views/nodes/edit.html.erb
@@ -114,6 +114,12 @@
114 %> 114 %>
115 </div> 115 </div>
116 116
117 <div class="layout_row_label"><%= t(".external_url") %></div>
118 <div class="layout_row_content">
119 <%= f.text_field :external_url %>
120 <p class="field_hint"><%= t(".external_url_hint") %></p>
121 </div>
122
117 <div class="layout_row_label"><%= t(".tags") %></div> 123 <div class="layout_row_label"><%= t(".tags") %></div>
118 <div class="layout_row_content"> 124 <div class="layout_row_content">
119 <%= text_field_tag :tag_list, @page.tag_list.join(', ') %> 125 <%= text_field_tag :tag_list, @page.tag_list.join(', ') %>