Sha256: facdba24e691702e4c53e8dd0be93d4dfa1dbcc28fde4ea67cc3d5c12468bb6e

Contents?: true

Size: 1.58 KB

Versions: 14

Compression:

Stored size: 1.58 KB

Contents

# frozen_string_literal: true
module Hyrax
  class SingleUseLinksController < ApplicationController
    class_attribute :show_presenter
    self.show_presenter = Hyrax::SingleUseLinkPresenter
    before_action :authenticate_user!
    before_action :authorize_user!
    # Catch permission errors
    rescue_from Hydra::AccessDenied, CanCan::AccessDenied, with: :deny_link_access

    def deny_link_access(exception)
      if current_user&.persisted?
        redirect_to main_app.root_url, alert: "You do not have sufficient privileges to create links to this document"
      else
        session["user_return_to"] = request.url
        redirect_to new_user_session_url, alert: exception.message
      end
    end

    def create_download
      @su = SingleUseLink.create item_id: params[:id], path: hyrax.download_path(id: params[:id])
      render plain: hyrax.download_single_use_link_url(@su.download_key)
    end

    def create_show
      @su = SingleUseLink.create(item_id: params[:id], path: asset_show_path)
      render plain: hyrax.show_single_use_link_url(@su.download_key)
    end

    def index
      links = SingleUseLink.where(item_id: params[:id]).map { |link| show_presenter.new(link) }
      render partial: 'hyrax/file_sets/single_use_link_rows', locals: { single_use_links: links }
    end

    def destroy
      SingleUseLink.find_by_download_key(params[:link_id]).destroy
      head :ok
    end

    private

    def authorize_user!
      authorize! :edit, params[:id]
    end

    def asset_show_path
      polymorphic_path([main_app, search_service.fetch(params[:id]).last])
    end
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
hyrax-5.0.4 app/controllers/hyrax/single_use_links_controller.rb
hyrax-5.0.3 app/controllers/hyrax/single_use_links_controller.rb
hyrax-5.0.2 app/controllers/hyrax/single_use_links_controller.rb
hyrax-5.0.1 app/controllers/hyrax/single_use_links_controller.rb
hyrax-5.0.0 app/controllers/hyrax/single_use_links_controller.rb
hyrax-5.0.0.rc3 app/controllers/hyrax/single_use_links_controller.rb
hyrax-5.0.0.rc2 app/controllers/hyrax/single_use_links_controller.rb
hyrax-5.0.0.rc1 app/controllers/hyrax/single_use_links_controller.rb
hyrax-4.0.0 app/controllers/hyrax/single_use_links_controller.rb
hyrax-4.0.0.rc3 app/controllers/hyrax/single_use_links_controller.rb
hyrax-4.0.0.rc2 app/controllers/hyrax/single_use_links_controller.rb
hyrax-4.0.0.rc1 app/controllers/hyrax/single_use_links_controller.rb
hyrax-4.0.0.beta2 app/controllers/hyrax/single_use_links_controller.rb
hyrax-4.0.0.beta1 app/controllers/hyrax/single_use_links_controller.rb