diff options
Diffstat (limited to 'app/controllers')
| -rw-r--r-- | app/controllers/admin_controller.rb | 9 | ||||
| -rw-r--r-- | app/controllers/content_controller.rb | 2 | ||||
| -rw-r--r-- | app/controllers/csp_reports_controller.rb | 22 | ||||
| -rw-r--r-- | app/controllers/node_actions_controller.rb | 14 | ||||
| -rw-r--r-- | app/controllers/nodes_controller.rb | 61 | ||||
| -rw-r--r-- | app/controllers/page_translations_controller.rb | 3 | ||||
| -rw-r--r-- | app/controllers/revisions_controller.rb | 2 |
7 files changed, 95 insertions, 18 deletions
diff --git a/app/controllers/admin_controller.rb b/app/controllers/admin_controller.rb index 37fd78b..d9cf1be 100644 --- a/app/controllers/admin_controller.rb +++ b/app/controllers/admin_controller.rb | |||
| @@ -6,7 +6,7 @@ class AdminController < ApplicationController | |||
| 6 | 6 | ||
| 7 | def index | 7 | def index |
| 8 | @drafts = Node.drafts_and_autosaves(current_user_id: current_user.id).limit(5) | 8 | @drafts = Node.drafts_and_autosaves(current_user_id: current_user.id).limit(5) |
| 9 | @recent_changes = Node.recently_changed.limit(5) | 9 | @actions = NodeAction.order(:occurred_at => :desc, :id => :desc).limit(5) |
| 10 | end | 10 | end |
| 11 | 11 | ||
| 12 | def conventions | 12 | def conventions |
| @@ -71,4 +71,11 @@ class AdminController < ApplicationController | |||
| 71 | end | 71 | end |
| 72 | end | 72 | end |
| 73 | end | 73 | end |
| 74 | |||
| 75 | # Deliberately raises, to verify the error-log tripwire end to end. | ||
| 76 | # Behind login_required like the rest of the controller; harmless -- | ||
| 77 | # the visitor gets the ordinary 500 page. | ||
| 78 | def boom | ||
| 79 | raise "Deliberate test exception via admin/boom" | ||
| 80 | end | ||
| 74 | end | 81 | end |
diff --git a/app/controllers/content_controller.rb b/app/controllers/content_controller.rb index 8d33105..8be4bfb 100644 --- a/app/controllers/content_controller.rb +++ b/app/controllers/content_controller.rb | |||
| @@ -31,7 +31,7 @@ class ContentController < ApplicationController | |||
| 31 | def render_gallery | 31 | def render_gallery |
| 32 | unless @page.nil? | 32 | unless @page.nil? |
| 33 | @images = @page.assets.images | 33 | @images = @page.assets.images |
| 34 | render :file => "content/gallery" | 34 | render :template => 'content/gallery' |
| 35 | else | 35 | else |
| 36 | head :not_found | 36 | head :not_found |
| 37 | end | 37 | end |
diff --git a/app/controllers/csp_reports_controller.rb b/app/controllers/csp_reports_controller.rb new file mode 100644 index 0000000..5a3b55e --- /dev/null +++ b/app/controllers/csp_reports_controller.rb | |||
| @@ -0,0 +1,22 @@ | |||
| 1 | class CspReportsController < ApplicationController | ||
| 2 | # Browsers POST application/csp-report with no CSRF token, no session. | ||
| 3 | skip_before_action :verify_authenticity_token | ||
| 4 | |||
| 5 | def create | ||
| 6 | request.body.rewind if request.body.respond_to?(:rewind) | ||
| 7 | raw = request.body.read(8192) | ||
| 8 | raw = request.raw_post if raw.blank? | ||
| 9 | |||
| 10 | report = (JSON.parse(raw)["csp-report"] rescue nil) | ||
| 11 | |||
| 12 | if report | ||
| 13 | directive = report["effective-directive"] || report["violated-directive"] | ||
| 14 | at = (URI.parse(report["document-uri"]).path rescue "unparsed") | ||
| 15 | CSP_LOGGER.warn("CSP violation: #{directive} blocked=#{report['blocked-uri']} at=#{at}") | ||
| 16 | else | ||
| 17 | CSP_LOGGER.warn("CSP violation: unparseable report (#{raw.to_s.bytesize} bytes)") | ||
| 18 | end | ||
| 19 | |||
| 20 | head :no_content | ||
| 21 | end | ||
| 22 | end | ||
diff --git a/app/controllers/node_actions_controller.rb b/app/controllers/node_actions_controller.rb new file mode 100644 index 0000000..6e46719 --- /dev/null +++ b/app/controllers/node_actions_controller.rb | |||
| @@ -0,0 +1,14 @@ | |||
| 1 | class NodeActionsController < ApplicationController | ||
| 2 | |||
| 3 | before_action :login_required | ||
| 4 | |||
| 5 | layout 'admin' | ||
| 6 | |||
| 7 | def index | ||
| 8 | @actions = NodeAction.order(:occurred_at => :desc, :id => :desc) | ||
| 9 | @actions = @actions.where(:node_id => params[:node_id]) if params[:node_id].present? | ||
| 10 | @actions = @actions.where(:user_id => params[:user_id]) if params[:user_id].present? | ||
| 11 | @actions = @actions.includes(:node, :user) | ||
| 12 | .paginate(:page => params[:page], :per_page => 50) | ||
| 13 | end | ||
| 14 | end | ||
diff --git a/app/controllers/nodes_controller.rb b/app/controllers/nodes_controller.rb index ed5f8ef..6caa827 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] |
| @@ -27,12 +29,7 @@ class NodesController < ApplicationController | |||
| 27 | def new | 29 | def new |
| 28 | @node = Node.new node_params | 30 | @node = Node.new node_params |
| 29 | @selected_kind = CccConventions::NODE_KINDS.key?(params[:kind]) ? params[:kind] : "generic" | 31 | @selected_kind = CccConventions::NODE_KINDS.key?(params[:kind]) ? params[:kind] : "generic" |
| 30 | if params.has_key?(:parent_id) | 32 | @parent = Node.find(params[:parent_id]) if params.has_key?(:parent_id) |
| 31 | @parent_id = params[:parent_id] | ||
| 32 | parent = Node.find(@parent_id) | ||
| 33 | @parent_name = parent.title | ||
| 34 | @parent_unique_name = parent.current_unique_name | ||
| 35 | end | ||
| 36 | end | 33 | end |
| 37 | 34 | ||
| 38 | def create | 35 | def create |
| @@ -50,14 +47,14 @@ class NodesController < ApplicationController | |||
| 50 | @node.draft.save! | 47 | @node.draft.save! |
| 51 | 48 | ||
| 52 | @node.update!(default_template_name: config[:template]) if config && config[:template] | 49 | @node.update!(default_template_name: config[:template]) if config && config[:template] |
| 50 | NodeAction.record!(:node => @node, :page => @node.draft, :user => current_user, | ||
| 51 | :action => "create", | ||
| 52 | :title => params[:title], :path => @node.unique_name) | ||
| 53 | 53 | ||
| 54 | redirect_to(edit_node_path(@node)) | 54 | redirect_to(edit_node_path(@node)) |
| 55 | else | 55 | else |
| 56 | @selected_kind = CccConventions::NODE_KINDS.key?(params[:kind]) ? params[:kind] : "generic" | 56 | @selected_kind = CccConventions::NODE_KINDS.key?(params[:kind]) ? params[:kind] : "generic" |
| 57 | if params[:parent_id].present? | 57 | @parent = Node.find(params[:parent_id]) if params.has_key?(:parent_id) |
| 58 | @parent_id = params[:parent_id] | ||
| 59 | @parent_name = Node.find(@parent_id).title | ||
| 60 | end | ||
| 61 | render :new | 58 | render :new |
| 62 | end | 59 | end |
| 63 | end | 60 | end |
| @@ -65,6 +62,9 @@ class NodesController < ApplicationController | |||
| 65 | def show | 62 | def show |
| 66 | @page = @node.draft || @node.head | 63 | @page = @node.draft || @node.head |
| 67 | @translations = @page.translation_summary | 64 | @translations = @page.translation_summary |
| 65 | @page_actions = NodeAction.where(:page_id => @node.pages.select(:id)) | ||
| 66 | .order(:occurred_at, :id) | ||
| 67 | .group_by(&:page_id) | ||
| 68 | end | 68 | end |
| 69 | 69 | ||
| 70 | def edit | 70 | def edit |
| @@ -144,8 +144,40 @@ class NodesController < ApplicationController | |||
| 144 | redirect_to node_path(@node) | 144 | redirect_to node_path(@node) |
| 145 | end | 145 | end |
| 146 | 146 | ||
| 147 | def trash | ||
| 148 | if @node.trash!(current_user) | ||
| 149 | flash[:notice] = "Page has been moved to the Trash" | ||
| 150 | redirect_to trashed_nodes_path | ||
| 151 | else | ||
| 152 | flash[:notice] = "Page is already in the Trash" | ||
| 153 | redirect_to node_path(@node) | ||
| 154 | end | ||
| 155 | rescue ActiveRecord::RecordInvalid, LockedByAnotherUser => e | ||
| 156 | flash[:error] = e.message | ||
| 157 | redirect_to node_path(@node) | ||
| 158 | end | ||
| 159 | |||
| 160 | def restore_from_trash | ||
| 161 | parent = Node.find(params[:parent_id]) | ||
| 162 | @node.restore_from_trash!(parent, current_user) | ||
| 163 | flash[:notice] = "Page has been restored from the Trash" | ||
| 164 | redirect_to node_path(@node) | ||
| 165 | rescue ActiveRecord::RecordNotFound | ||
| 166 | flash[:error] = "Restore target not found" | ||
| 167 | redirect_to node_path(@node) | ||
| 168 | rescue ActiveRecord::RecordInvalid => e | ||
| 169 | flash[:error] = e.message | ||
| 170 | redirect_to node_path(@node) | ||
| 171 | end | ||
| 172 | |||
| 147 | def destroy | 173 | def destroy |
| 148 | @node.destroy | 174 | @node.destroy_from_trash!(current_user) |
| 175 | flash[:notice] = "Page has been permanently deleted" | ||
| 176 | redirect_to trashed_nodes_path | ||
| 177 | |||
| 178 | rescue ActiveRecord::RecordInvalid, ActiveRecord::RecordNotDestroyed => e | ||
| 179 | flash[:error] = e.message | ||
| 180 | redirect_to node_path(@node) | ||
| 149 | end | 181 | end |
| 150 | 182 | ||
| 151 | def publish | 183 | def publish |
| @@ -219,6 +251,11 @@ class NodesController < ApplicationController | |||
| 219 | @sitemap_descendant_counts = descendant_counts_for(@sitemap) | 251 | @sitemap_descendant_counts = descendant_counts_for(@sitemap) |
| 220 | end | 252 | end |
| 221 | 253 | ||
| 254 | def trashed | ||
| 255 | @nodes = Node.trash.children.order(:slug) | ||
| 256 | .paginate(:page => params[:page], :per_page => 50) | ||
| 257 | end | ||
| 258 | |||
| 222 | private | 259 | private |
| 223 | 260 | ||
| 224 | def slug_for(title) | 261 | def slug_for(title) |
diff --git a/app/controllers/page_translations_controller.rb b/app/controllers/page_translations_controller.rb index be4f488..38a7c4f 100644 --- a/app/controllers/page_translations_controller.rb +++ b/app/controllers/page_translations_controller.rb | |||
| @@ -63,9 +63,6 @@ class PageTranslationsController < ApplicationController | |||
| 63 | draft.translations.where(:locale => @locale).delete_all | 63 | draft.translations.where(:locale => @locale).delete_all |
| 64 | draft.reload | 64 | draft.reload |
| 65 | 65 | ||
| 66 | NodeAction.record!(:node => @node, :page => draft, :user => current_user, | ||
| 67 | :action => "translation_destroy", :locale => @locale) | ||
| 68 | |||
| 69 | flash[:notice] = "#{@locale.upcase} translation removed from the draft. Publish to make this permanent." | 66 | flash[:notice] = "#{@locale.upcase} translation removed from the draft. Publish to make this permanent." |
| 70 | redirect_to node_path(@node) | 67 | redirect_to node_path(@node) |
| 71 | rescue LockedByAnotherUser => e | 68 | rescue LockedByAnotherUser => e |
diff --git a/app/controllers/revisions_controller.rb b/app/controllers/revisions_controller.rb index c5932a4..c1237a9 100644 --- a/app/controllers/revisions_controller.rb +++ b/app/controllers/revisions_controller.rb | |||
| @@ -49,7 +49,7 @@ class RevisionsController < ApplicationController | |||
| 49 | 49 | ||
| 50 | def restore | 50 | def restore |
| 51 | page = Page.find(params[:id]) | 51 | page = Page.find(params[:id]) |
| 52 | page.node.restore_revision! page.revision | 52 | page.node.restore_revision! page.revision, current_user |
| 53 | flash[:notice] = "Revision #{page.revision} restored" | 53 | flash[:notice] = "Revision #{page.revision} restored" |
| 54 | redirect_to node_path(page.node) | 54 | redirect_to node_path(page.node) |
| 55 | end | 55 | end |
