Sha256: c20cde9ff3b2ff3fa210298a065d90fe8da7e444f66f5155e1f4309e230d8d5d

Contents?: true

Size: 1.19 KB

Versions: 52

Compression:

Stored size: 1.19 KB

Contents

# frozen_string_literal: true

module Spotlight
  ##
  # Controller for reverting to historical versions of e.g. pages
  class VersionsController < Spotlight::ApplicationController
    before_action :authenticate_user!

    load_and_authorize_resource class: 'PaperTrail::Version'

    def revert
      obj = @version.reify
      if obj && authorize!(:manage, obj)
        if obj.save
          redirect_to [obj.exhibit, obj], flash: { html_safe: true }, notice: undo_link
        else
          redirect_to [obj.exhibit, obj], flash: { html_safe: true }, notice: view_context.t(:'spotlight.versions.undo_error')
        end
      else
        redirect_back fallback_location: main_app.root_url, flash: { html_safe: true }, notice: view_context.t(:'spotlight.versions.undo_error')
      end
    end

    private

    def undo_link
      return unless can? :manage, @version

      link_name = if params[:redo] == 'true'
                    view_context.t(:'spotlight.versions.undo')
                  else
                    view_context.t(:'spotlight.versions.redo')
                  end

      view_context.link_to(link_name, revert_version_path(@version.next, redo: !params[:redo]), method: :post)
    end
  end
end

Version data entries

52 entries across 52 versions & 1 rubygems

Version Path
blacklight-spotlight-3.5.0.4 app/controllers/spotlight/versions_controller.rb
blacklight-spotlight-3.5.0.3 app/controllers/spotlight/versions_controller.rb
blacklight-spotlight-3.5.0.2 app/controllers/spotlight/versions_controller.rb
blacklight-spotlight-3.5.0.1 app/controllers/spotlight/versions_controller.rb
blacklight-spotlight-3.5.0 app/controllers/spotlight/versions_controller.rb
blacklight-spotlight-3.4.4.1 app/controllers/spotlight/versions_controller.rb
blacklight-spotlight-3.4.4 app/controllers/spotlight/versions_controller.rb
blacklight-spotlight-3.4.3 app/controllers/spotlight/versions_controller.rb
blacklight-spotlight-3.4.2.2 app/controllers/spotlight/versions_controller.rb
blacklight-spotlight-3.4.2.1 app/controllers/spotlight/versions_controller.rb
blacklight-spotlight-3.4.2 app/controllers/spotlight/versions_controller.rb
blacklight-spotlight-3.4.1 app/controllers/spotlight/versions_controller.rb
blacklight-spotlight-3.4.0 app/controllers/spotlight/versions_controller.rb
blacklight-spotlight-3.3.0 app/controllers/spotlight/versions_controller.rb
blacklight-spotlight-3.2.0 app/controllers/spotlight/versions_controller.rb
blacklight-spotlight-3.1.0 app/controllers/spotlight/versions_controller.rb
blacklight-spotlight-3.0.3 app/controllers/spotlight/versions_controller.rb
blacklight-spotlight-3.0.2 app/controllers/spotlight/versions_controller.rb
blacklight-spotlight-3.0.1 app/controllers/spotlight/versions_controller.rb
blacklight-spotlight-3.0.0 app/controllers/spotlight/versions_controller.rb