Sha256: ff776bb14e9aaf4f7ef173080c2ab9b92611ba0127818d78b5335fc26139d80a

Contents?: true

Size: 1.3 KB

Versions: 10

Compression:

Stored size: 1.3 KB

Contents

require 'sufia/single_use_error'

class SingleUseLinksController < ApplicationController
  prepend_before_filter :normalize_identifier
  before_filter :load_asset
  before_filter :authenticate_user!
  before_filter :authorize_user!

  def new_download
    @su = SingleUseLink.create itemId: params[:id], path: sufia.download_path(id: @asset)
    @link = sufia.download_single_use_link_path(@su.downloadKey)

    respond_to do |format|
      format.html
      format.js  { render js: @link }
    end
  end

  def new_show
    @su = SingleUseLink.create itemId: params[:id], path: sufia.polymorphic_path(@asset)
    @link = sufia.show_single_use_link_path(@su.downloadKey)

    respond_to do |format|
      format.html
      format.js  { render js: @link }
    end
  end

  # Catch permission errors
  rescue_from Hydra::AccessDenied, CanCan::AccessDenied do |exception|
    if current_user and current_user.persisted?
      redirect_to 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

  protected
  def authorize_user!
    authorize! :edit, @asset
  end

  def load_asset
    @asset = ActiveFedora::Base.load_instance_from_solr(params[:id])
  end

end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
sufia-5.0.0 app/controllers/single_use_links_controller.rb
sufia-5.0.0.rc1 app/controllers/single_use_links_controller.rb
sufia-4.3.1 app/controllers/single_use_links_controller.rb
sufia-4.2.0 app/controllers/single_use_links_controller.rb
sufia-4.1.0 app/controllers/single_use_links_controller.rb
sufia-4.0.1 app/controllers/single_use_links_controller.rb
sufia-4.0.0 app/controllers/single_use_links_controller.rb
sufia-4.0.0.rc2 app/controllers/single_use_links_controller.rb
sufia-4.0.0.rc1 app/controllers/single_use_links_controller.rb
sufia-4.0.0.beta4 app/controllers/single_use_links_controller.rb