Sha256: 64c56379ca406c126cf428eb2e4a3238ef453c662ef6368c5215359ad5ea36f8

Contents?: true

Size: 1.63 KB

Versions: 62

Compression:

Stored size: 1.63 KB

Contents

module Workarea
  module Admin
    class TrashController < Admin::ApplicationController
      before_action :check_restore_authorization, only: :restore

      def index
        @entries = Mongoid::AuditLog::Entry
                    .all
                    .destroys
                    .where(restored: false)
                    .desc(:created_at)
                    .page(params[:page])
      end

      def restore
        entry = Mongoid::AuditLog::Entry.find(params[:id])
        entry.restore!

        flash[:success] = t('workarea.admin.trash.flash_messages.success')
        redirect_to(
          if entry.audited.is_a?(Content::Block)
            edit_content_path(entry.root)
          elsif entry.audited.is_a?(Navigation::Taxon)
            navigation_taxons_path(taxon_ids: entry.audited.parent_ids)
          elsif entry.audited.is_a?(Comment)
            commentable_comments_path(entry.root.commentable.to_global_id)
          else
            polymorphic_path(entry.root)
          end
        )

      rescue Mongoid::Errors::Validations => e
        flash[:error] = e.document.errors.to_a.to_sentence
        redirect_back fallback_location: trash_index_path
      rescue Mongoid::AuditLog::Restore::InvalidRestore
        flash[:error] = t('workarea.admin.trash.flash_messages.error')
        redirect_back fallback_location: trash_index_path
      end

      private

      def check_restore_authorization
        unless current_user.can_restore?
          flash[:error] = t('workarea.admin.trash.flash_messages.unauthorized')
          redirect_back(fallback_location: root_path) && (return false)
        end
      end
    end
  end
end

Version data entries

62 entries across 62 versions & 1 rubygems

Version Path
workarea-admin-3.5.27 app/controllers/workarea/admin/trash_controller.rb
workarea-admin-3.5.26 app/controllers/workarea/admin/trash_controller.rb
workarea-admin-3.4.45 app/controllers/workarea/admin/trash_controller.rb
workarea-admin-3.5.25 app/controllers/workarea/admin/trash_controller.rb
workarea-admin-3.5.23 app/controllers/workarea/admin/trash_controller.rb
workarea-admin-3.4.44 app/controllers/workarea/admin/trash_controller.rb
workarea-admin-3.5.22 app/controllers/workarea/admin/trash_controller.rb
workarea-admin-3.4.43 app/controllers/workarea/admin/trash_controller.rb
workarea-admin-3.5.21 app/controllers/workarea/admin/trash_controller.rb
workarea-admin-3.4.42 app/controllers/workarea/admin/trash_controller.rb
workarea-admin-3.5.20 app/controllers/workarea/admin/trash_controller.rb
workarea-admin-3.4.41 app/controllers/workarea/admin/trash_controller.rb
workarea-admin-3.5.19 app/controllers/workarea/admin/trash_controller.rb
workarea-admin-3.4.40 app/controllers/workarea/admin/trash_controller.rb
workarea-admin-3.5.18 app/controllers/workarea/admin/trash_controller.rb
workarea-admin-3.4.39 app/controllers/workarea/admin/trash_controller.rb
workarea-admin-3.5.17 app/controllers/workarea/admin/trash_controller.rb
workarea-admin-3.4.38 app/controllers/workarea/admin/trash_controller.rb
workarea-admin-3.5.16 app/controllers/workarea/admin/trash_controller.rb
workarea-admin-3.4.37 app/controllers/workarea/admin/trash_controller.rb