Sha256: 79b6948b7bc175123b1473d815d33335adbd5712b5503afbdb10e5df98b5a7a8

Contents?: true

Size: 1.16 KB

Versions: 47

Compression:

Stored size: 1.16 KB

Contents

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

47 entries across 47 versions & 1 rubygems

Version Path
blacklight-spotlight-2.4.1 app/controllers/spotlight/versions_controller.rb
blacklight-spotlight-2.4.0 app/controllers/spotlight/versions_controller.rb
blacklight-spotlight-2.3.3 app/controllers/spotlight/versions_controller.rb
blacklight-spotlight-2.3.2 app/controllers/spotlight/versions_controller.rb
blacklight-spotlight-2.3.1 app/controllers/spotlight/versions_controller.rb
blacklight-spotlight-2.3.0 app/controllers/spotlight/versions_controller.rb
blacklight-spotlight-2.2.1 app/controllers/spotlight/versions_controller.rb
blacklight-spotlight-2.2.0 app/controllers/spotlight/versions_controller.rb
blacklight-spotlight-2.1.0 app/controllers/spotlight/versions_controller.rb
blacklight-spotlight-2.0.2 app/controllers/spotlight/versions_controller.rb
blacklight-spotlight-2.0.1 app/controllers/spotlight/versions_controller.rb
blacklight-spotlight-2.0.0 app/controllers/spotlight/versions_controller.rb
blacklight-spotlight-2.0.0.rc6 app/controllers/spotlight/versions_controller.rb
blacklight-spotlight-2.0.0.rc5 app/controllers/spotlight/versions_controller.rb
blacklight-spotlight-2.0.0.rc4 app/controllers/spotlight/versions_controller.rb
blacklight-spotlight-2.0.0.rc3 app/controllers/spotlight/versions_controller.rb
blacklight-spotlight-2.0.0.rc2 app/controllers/spotlight/versions_controller.rb
blacklight-spotlight-2.0.0.rc1 app/controllers/spotlight/versions_controller.rb
blacklight-spotlight-1.5.1 app/controllers/spotlight/versions_controller.rb
blacklight-spotlight-1.4.1 app/controllers/spotlight/versions_controller.rb