Sha256: 3bc0491e0f96ad52a23ab13b0e0628c5c40a0f5fb4395348f23f29c9220f92ad

Contents?: true

Size: 1.34 KB

Versions: 6

Compression:

Stored size: 1.34 KB

Contents

module Sufia
  module SingleUseLinksControllerBehavior
    extend ActiveSupport::Concern
    included do
      before_action :authenticate_user!
      before_action :authorize_user!
      # Catch permission errors
      rescue_from Hydra::AccessDenied, CanCan::AccessDenied do |exception|
        if current_user && 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

6 entries across 6 versions & 1 rubygems

Version Path
sufia-6.7.0 app/controllers/concerns/sufia/single_use_links_controller_behavior.rb
sufia-6.6.1 app/controllers/concerns/sufia/single_use_links_controller_behavior.rb
sufia-6.6.0 app/controllers/concerns/sufia/single_use_links_controller_behavior.rb
sufia-6.5.0 app/controllers/concerns/sufia/single_use_links_controller_behavior.rb
sufia-6.4.0 app/controllers/concerns/sufia/single_use_links_controller_behavior.rb
sufia-6.3.0 app/controllers/concerns/sufia/single_use_links_controller_behavior.rb