Sha256: 9ab0e6fbddcfbef370c3fb32a413c27c6b7bdd676392c87034cecb89d1d337e3

Contents?: true

Size: 1.23 KB

Versions: 3

Compression:

Stored size: 1.23 KB

Contents

class SingleUseLinksController < ApplicationController
  prepend_before_filter :normalize_identifier
  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 asset
    @asset ||= ActiveFedora::Base.load_instance_from_solr(params[:id])
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
sufia-6.0.0.rc2 app/controllers/single_use_links_controller.rb
sufia-6.0.0.rc1 app/controllers/single_use_links_controller.rb
sufia-6.0.0.beta1 app/controllers/single_use_links_controller.rb