diff options
| author | erdgeist <erdgeist@erdgeist.org> | 2026-07-17 23:14:17 +0200 |
|---|---|---|
| committer | erdgeist <erdgeist@erdgeist.org> | 2026-07-17 23:14:17 +0200 |
| commit | 5dced8b4b624aabf4215ba21b13957080345c326 (patch) | |
| tree | 70afdbd65f28309da76b60e084aad05776ec1881 /app/controllers | |
| parent | 2748dc23be86eeb1e4f5e155b8f2191245bb5f5c (diff) | |
Route and control trash, restore, and permanent deletion
Diffstat (limited to 'app/controllers')
| -rw-r--r-- | app/controllers/nodes_controller.rb | 37 |
1 files changed, 35 insertions, 2 deletions
diff --git a/app/controllers/nodes_controller.rb b/app/controllers/nodes_controller.rb index 9834a17..9ea66ad 100644 --- a/app/controllers/nodes_controller.rb +++ b/app/controllers/nodes_controller.rb | |||
| @@ -13,7 +13,9 @@ class NodesController < ApplicationController | |||
| 13 | :publish, | 13 | :publish, |
| 14 | :unlock, | 14 | :unlock, |
| 15 | :autosave, | 15 | :autosave, |
| 16 | :revert | 16 | :revert, |
| 17 | :trash, | ||
| 18 | :restore_from_trash | ||
| 17 | ] | 19 | ] |
| 18 | 20 | ||
| 19 | around_action :pin_to_default_locale, :only => [:show, :edit, :update, :autosave] | 21 | around_action :pin_to_default_locale, :only => [:show, :edit, :update, :autosave] |
| @@ -139,8 +141,39 @@ class NodesController < ApplicationController | |||
| 139 | redirect_to node_path(@node) | 141 | redirect_to node_path(@node) |
| 140 | end | 142 | end |
| 141 | 143 | ||
| 144 | def trash | ||
| 145 | if @node.trash!(current_user) | ||
| 146 | flash[:notice] = "Page has been moved to the Trash" | ||
| 147 | redirect_to node_path(Node.trash) | ||
| 148 | else | ||
| 149 | flash[:notice] = "Page is already in the Trash" | ||
| 150 | redirect_to node_path(@node) | ||
| 151 | end | ||
| 152 | rescue ActiveRecord::RecordInvalid, LockedByAnotherUser => e | ||
| 153 | flash[:error] = e.message | ||
| 154 | redirect_to node_path(@node) | ||
| 155 | end | ||
| 156 | |||
| 157 | def restore_from_trash | ||
| 158 | parent = Node.find(params[:parent_id]) | ||
| 159 | @node.restore_from_trash!(parent, current_user) | ||
| 160 | flash[:notice] = "Page has been restored from the Trash" | ||
| 161 | redirect_to node_path(@node) | ||
| 162 | rescue ActiveRecord::RecordNotFound | ||
| 163 | flash[:error] = "Restore target not found" | ||
| 164 | redirect_to node_path(@node) | ||
| 165 | rescue ActiveRecord::RecordInvalid => e | ||
| 166 | flash[:error] = e.message | ||
| 167 | redirect_to node_path(@node) | ||
| 168 | end | ||
| 169 | |||
| 142 | def destroy | 170 | def destroy |
| 143 | @node.destroy | 171 | @node.destroy_from_trash!(current_user) |
| 172 | flash[:notice] = "Page has been permanently deleted" | ||
| 173 | redirect_to node_path(Node.trash) | ||
| 174 | rescue ActiveRecord::RecordInvalid, ActiveRecord::RecordNotDestroyed => e | ||
| 175 | flash[:error] = e.message | ||
| 176 | redirect_to node_path(@node) | ||
| 144 | end | 177 | end |
| 145 | 178 | ||
| 146 | def publish | 179 | def publish |
