Sha256: e0c000bdfd77184e6b1b06fe33d6411873f398289df1b688c90700fe2153e230

Contents?: true

Size: 1.25 KB

Versions: 29

Compression:

Stored size: 1.25 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]),
                           data: { method: :post, turbo_method: :post })
    end
  end
end

Version data entries

29 entries across 29 versions & 1 rubygems

Version Path
blacklight-spotlight-4.7.0 app/controllers/spotlight/versions_controller.rb
blacklight-spotlight-4.6.1 app/controllers/spotlight/versions_controller.rb
blacklight-spotlight-4.6.0 app/controllers/spotlight/versions_controller.rb
blacklight-spotlight-4.5.0 app/controllers/spotlight/versions_controller.rb
blacklight-spotlight-4.4.0 app/controllers/spotlight/versions_controller.rb
blacklight-spotlight-4.3.6 app/controllers/spotlight/versions_controller.rb
blacklight-spotlight-4.3.5 app/controllers/spotlight/versions_controller.rb
blacklight-spotlight-4.3.4 app/controllers/spotlight/versions_controller.rb
blacklight-spotlight-4.3.3 app/controllers/spotlight/versions_controller.rb
blacklight-spotlight-4.3.2 app/controllers/spotlight/versions_controller.rb
blacklight-spotlight-4.3.1 app/controllers/spotlight/versions_controller.rb
blacklight-spotlight-4.3.0 app/controllers/spotlight/versions_controller.rb
blacklight-spotlight-4.2.0 app/controllers/spotlight/versions_controller.rb
blacklight-spotlight-4.1.2 app/controllers/spotlight/versions_controller.rb
blacklight-spotlight-4.1.1 app/controllers/spotlight/versions_controller.rb
blacklight-spotlight-4.1.0 app/controllers/spotlight/versions_controller.rb
blacklight-spotlight-4.0.3 app/controllers/spotlight/versions_controller.rb
blacklight-spotlight-4.0.2 app/controllers/spotlight/versions_controller.rb
blacklight-spotlight-4.0.1 app/controllers/spotlight/versions_controller.rb
blacklight-spotlight-4.0.0 app/controllers/spotlight/versions_controller.rb