Sha256: 229b60f4e79a52a1cff8f90a1684b9be2a99a803bdf6f051abf8cd1ff7ddab75

Contents?: true

Size: 1.34 KB

Versions: 4

Compression:

Stored size: 1.34 KB

Contents

module Sufia
  module SingleUseLinksControllerBehavior
    extend ActiveSupport::Concern
    included do

      before_filter :authenticate_user!
      before_filter :authorize_user!
      # 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

    end

    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


    protected
    def authorize_user!
      authorize! :edit, asset
    end

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

  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
sufia-6.2.0 app/controllers/concerns/sufia/single_use_links_controller_behavior.rb
sufia-6.1.0 app/controllers/concerns/sufia/single_use_links_controller_behavior.rb
sufia-6.0.0 app/controllers/concerns/sufia/single_use_links_controller_behavior.rb
sufia-6.0.0.rc4 app/controllers/concerns/sufia/single_use_links_controller_behavior.rb