Sha256: d0e01be0d238e04ec80407a8bbe621a7c4d42fad7ab92e31a89c43d2986d59da

Contents?: true

Size: 1.34 KB

Versions: 7

Compression:

Stored size: 1.34 KB

Contents

require 'sufia/single_use_error'

class SingleUseLinksController < ApplicationController
  include Sufia::Noid

  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

7 entries across 7 versions & 1 rubygems

Version Path
sufia-4.0.0.beta2 app/controllers/single_use_links_controller.rb
sufia-4.0.0.beta1 app/controllers/single_use_links_controller.rb
sufia-3.7.2 app/controllers/single_use_links_controller.rb
sufia-3.7.1 app/controllers/single_use_links_controller.rb
sufia-3.7.0 app/controllers/single_use_links_controller.rb
sufia-3.6.1 app/controllers/single_use_links_controller.rb
sufia-3.6.0 app/controllers/single_use_links_controller.rb