diff options
| author | erdgeist <erdgeist@erdgeist.org> | 2026-07-31 20:41:05 +0200 |
|---|---|---|
| committer | erdgeist <erdgeist@erdgeist.org> | 2026-07-31 20:41:05 +0200 |
| commit | 3b4e1423635fd9f33ae760312e438cc1e484662e (patch) | |
| tree | 0dd81aaf26ab5e4d7e178563f120b3e203c4dc0b /app | |
| parent | 683526b38442a9873d83a542b5cba1d15efc14d5 (diff) | |
Show the gate before it refuses, and check the destination
nodes#show renders publish and trash as disabled_action spans with a hint
naming what an editor can still do, matching how locked_by_other already
reads. Editing and reverting stay live: drafting is free everywhere.
Diffstat (limited to 'app')
| -rw-r--r-- | app/models/node.rb | 23 | ||||
| -rw-r--r-- | app/models/user.rb | 6 | ||||
| -rw-r--r-- | app/views/nodes/show.html.erb | 26 |
3 files changed, 42 insertions, 13 deletions
diff --git a/app/models/node.rb b/app/models/node.rb index ac3a6160..188b6c17 100644 --- a/app/models/node.rb +++ b/app/models/node.rb | |||
| @@ -236,7 +236,7 @@ class Node < ApplicationRecord | |||
| 236 | # Return nil if nothing to publish and no staged changes | 236 | # Return nil if nothing to publish and no staged changes |
| 237 | return nil unless self.draft || staged_slug || staged_parent_id | 237 | return nil unless self.draft || staged_slug || staged_parent_id |
| 238 | 238 | ||
| 239 | guard_live_change!(current_user) | 239 | guard_live_change!(current_user, :target_path => prospective_unique_name) |
| 240 | 240 | ||
| 241 | if in_trash? || trash_node? | 241 | if in_trash? || trash_node? |
| 242 | errors.add(:base, :publish_in_trash) | 242 | errors.add(:base, :publish_in_trash) |
| @@ -574,10 +574,8 @@ class Node < ApplicationRecord | |||
| 574 | false | 574 | false |
| 575 | end | 575 | end |
| 576 | 576 | ||
| 577 | def restricted? | 577 | def self.restricted_path? name |
| 578 | return true if root? | 578 | name = name.to_s |
| 579 | |||
| 580 | name = unique_name.to_s | ||
| 581 | return false if name.empty? | 579 | return false if name.empty? |
| 582 | 580 | ||
| 583 | CccConventions::RESTRICTED_SUBTREES.any? do |prefix| | 581 | CccConventions::RESTRICTED_SUBTREES.any? do |prefix| |
| @@ -585,6 +583,17 @@ class Node < ApplicationRecord | |||
| 585 | end | 583 | end |
| 586 | end | 584 | end |
| 587 | 585 | ||
| 586 | def restricted? | ||
| 587 | root? || self.class.restricted_path?(unique_name) | ||
| 588 | end | ||
| 589 | |||
| 590 | def prospective_unique_name | ||
| 591 | target_parent = staged_parent_id ? Node.find_by(:id => staged_parent_id) : parent | ||
| 592 | return nil unless target_parent | ||
| 593 | |||
| 594 | [target_parent.unique_name.presence, staged_slug.presence || slug].compact.join("/") | ||
| 595 | end | ||
| 596 | |||
| 588 | # Returns immutable node id for all new nodes so that the atom feed entry ids | 597 | # Returns immutable node id for all new nodes so that the atom feed entry ids |
| 589 | # stay the same eventhough the slug or positions changes. | 598 | # stay the same eventhough the slug or positions changes. |
| 590 | # Can be removed after a year or so ;) | 599 | # Can be removed after a year or so ;) |
| @@ -697,9 +706,9 @@ class Node < ApplicationRecord | |||
| 697 | 706 | ||
| 698 | private | 707 | private |
| 699 | 708 | ||
| 700 | def guard_live_change! user | 709 | def guard_live_change! user, target_path: nil |
| 701 | return if user.nil? | 710 | return if user.nil? |
| 702 | return if user.may_change_live?(self) | 711 | return if user.may_change_live?(self) && user.may_change_live_at?(target_path) |
| 703 | 712 | ||
| 704 | errors.add(:base, :not_permitted) | 713 | errors.add(:base, :not_permitted) |
| 705 | raise ActiveRecord::RecordInvalid.new(self) | 714 | raise ActiveRecord::RecordInvalid.new(self) |
diff --git a/app/models/user.rb b/app/models/user.rb index e8c3b9bb..bf0f40ee 100644 --- a/app/models/user.rb +++ b/app/models/user.rb | |||
| @@ -110,6 +110,12 @@ class User < ApplicationRecord | |||
| 110 | redaktion? | 110 | redaktion? |
| 111 | end | 111 | end |
| 112 | 112 | ||
| 113 | def may_change_live_at?(path) | ||
| 114 | return true if path.nil? | ||
| 115 | return true unless Node.restricted_path?(path) | ||
| 116 | redaktion? | ||
| 117 | end | ||
| 118 | |||
| 113 | def deactivate!(actor:) | 119 | def deactivate!(actor:) |
| 114 | return false if alumni? | 120 | return false if alumni? |
| 115 | transaction do | 121 | transaction do |
diff --git a/app/views/nodes/show.html.erb b/app/views/nodes/show.html.erb index 8b12e2eb..a6167c9e 100644 --- a/app/views/nodes/show.html.erb +++ b/app/views/nodes/show.html.erb | |||
| @@ -1,4 +1,5 @@ | |||
| 1 | <% locked_by_other = @node.locked? && @node.lock_owner != current_user %> | 1 | <% locked_by_other = @node.locked? && @node.lock_owner != current_user %> |
| 2 | <% may_change_live = current_user.may_change_live?(@node) %> | ||
| 2 | <div id="admin_layout" class="show_node"> | 3 | <div id="admin_layout" class="show_node"> |
| 3 | <h1><%= title_for_node(@node) %> <small>(<%= I18n.default_locale.to_s.upcase %>)</small></h1> | 4 | <h1><%= title_for_node(@node) %> <small>(<%= I18n.default_locale.to_s.upcase %>)</small></h1> |
| 4 | <div id="content"> | 5 | <div id="content"> |
| @@ -48,8 +49,12 @@ | |||
| 48 | <% unless locked_by_other %> | 49 | <% unless locked_by_other %> |
| 49 | <% if @node.draft && !@node.autosave && !@node.in_trash? && !@node.trash_node? %> | 50 | <% if @node.draft && !@node.autosave && !@node.in_trash? && !@node.trash_node? %> |
| 50 | <div class="info_item"> | 51 | <div class="info_item"> |
| 51 | <%= button_to t(".publish"), publish_node_path(@node), method: :put, | 52 | <% if may_change_live %> |
| 52 | form: { data: { confirm: t(".confirm_publish") }, class: 'button_to state_changing' } %> | 53 | <%= button_to t(".publish"), publish_node_path(@node), method: :put, |
| 54 | form: { data: { confirm: t(".confirm_publish") }, class: 'button_to state_changing' } %> | ||
| 55 | <% else %> | ||
| 56 | <span class="disabled_action"><%= t(".publish") %></span> | ||
| 57 | <% end %> | ||
| 53 | </div> | 58 | </div> |
| 54 | <% end %> | 59 | <% end %> |
| 55 | <% if @node.autosave || (@node.draft && @node.head) %> | 60 | <% if @node.autosave || (@node.draft && @node.head) %> |
| @@ -64,10 +69,17 @@ | |||
| 64 | <% end %> | 69 | <% end %> |
| 65 | <% unless @node.trash_node? || @node.in_trash? || @node.root? %> | 70 | <% unless @node.trash_node? || @node.in_trash? || @node.root? %> |
| 66 | <div class="info_item"> | 71 | <div class="info_item"> |
| 67 | <%= button_to trash_node_path(@node), method: :put, | 72 | <% if may_change_live %> |
| 68 | form: { data: { confirm: t(".confirm_trash") }, class: 'button_to destructive' } do %> | 73 | <%= button_to trash_node_path(@node), method: :put, |
| 69 | <%= icon("trash", library: "tabler", "aria-hidden": true) %> | 74 | form: { data: { confirm: t(".confirm_trash") }, class: 'button_to destructive' } do %> |
| 70 | <%= t(".move_to_trash") %> | 75 | <%= icon("trash", library: "tabler", "aria-hidden": true) %> |
| 76 | <%= t(".move_to_trash") %> | ||
| 77 | <% end %> | ||
| 78 | <% else %> | ||
| 79 | <span class="disabled_action"> | ||
| 80 | <%= icon("trash", library: "tabler", "aria-hidden": true) %> | ||
| 81 | <%= t(".move_to_trash") %> | ||
| 82 | </span> | ||
| 71 | <% end %> | 83 | <% end %> |
| 72 | </div> | 84 | </div> |
| 73 | <% end %> | 85 | <% end %> |
| @@ -76,6 +88,8 @@ | |||
| 76 | 88 | ||
| 77 | <% if locked_by_other %> | 89 | <% if locked_by_other %> |
| 78 | <span class="field_hint"><%= t(".locked_hint") %></span> | 90 | <span class="field_hint"><%= t(".locked_hint") %></span> |
| 91 | <% elsif !may_change_live %> | ||
| 92 | <span class="field_hint"><%= t(".restricted_hint") %></span> | ||
| 79 | <% end %> | 93 | <% end %> |
| 80 | </div> | 94 | </div> |
| 81 | 95 | ||
