Sha256: 973472d820fb9ccc02d8eebeb18ffe8dd1d7a9a61149f2a18d9d774143577612

Contents?: true

Size: 1.39 KB

Versions: 17

Compression:

Stored size: 1.39 KB

Contents

module CurationConcerns
  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 main_app.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: main_app.download_path(id: asset)
      @link = curation_concerns.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: polymorphic_path([main_app, asset])
      @link = curation_concerns.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

17 entries across 17 versions & 1 rubygems

Version Path
curation_concerns-0.12.0.pre8 app/controllers/concerns/curation_concerns/single_use_links_controller_behavior.rb
curation_concerns-0.12.0.pre7 app/controllers/concerns/curation_concerns/single_use_links_controller_behavior.rb
curation_concerns-0.12.0.pre6 app/controllers/concerns/curation_concerns/single_use_links_controller_behavior.rb
curation_concerns-0.12.0.pre5 app/controllers/concerns/curation_concerns/single_use_links_controller_behavior.rb
curation_concerns-0.12.0.pre4 app/controllers/concerns/curation_concerns/single_use_links_controller_behavior.rb
curation_concerns-0.12.0.pre3 app/controllers/concerns/curation_concerns/single_use_links_controller_behavior.rb
curation_concerns-0.12.0.pre2 app/controllers/concerns/curation_concerns/single_use_links_controller_behavior.rb
curation_concerns-0.12.0.pre1 app/controllers/concerns/curation_concerns/single_use_links_controller_behavior.rb
curation_concerns-0.11.0 app/controllers/concerns/curation_concerns/single_use_links_controller_behavior.rb
curation_concerns-0.11.0.rc1 app/controllers/concerns/curation_concerns/single_use_links_controller_behavior.rb
curation_concerns-0.10.0 app/controllers/concerns/curation_concerns/single_use_links_controller_behavior.rb
curation_concerns-0.9.0 app/controllers/concerns/curation_concerns/single_use_links_controller_behavior.rb
curation_concerns-0.8.0 app/controllers/concerns/curation_concerns/single_use_links_controller_behavior.rb
curation_concerns-0.7.0 app/controllers/concerns/curation_concerns/single_use_links_controller_behavior.rb
curation_concerns-0.6.0 app/controllers/concerns/curation_concerns/single_use_links_controller_behavior.rb
curation_concerns-0.5.0 app/controllers/concerns/curation_concerns/single_use_links_controller_behavior.rb
curation_concerns-0.4.0 app/controllers/concerns/curation_concerns/single_use_links_controller_behavior.rb