Sha256: b02d65ef7d65d7fc8205a3a78d54ea5e3fa0c97c551cb9ce413a7bcd3d479cd4

Contents?: true

Size: 1.21 KB

Versions: 23

Compression:

Stored size: 1.21 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 create_download
      @su = SingleUseLink.create itemId: params[:id], path: main_app.download_path(id: asset)
      render text: curation_concerns.download_single_use_link_url(@su.downloadKey)
    end

    def create_show
      @su = SingleUseLink.create itemId: params[:id], path: polymorphic_path([main_app, asset])
      render text: curation_concerns.show_single_use_link_url(@su.downloadKey)
    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

23 entries across 23 versions & 1 rubygems

Version Path
curation_concerns-1.1.2 app/controllers/concerns/curation_concerns/single_use_links_controller_behavior.rb
curation_concerns-1.1.1 app/controllers/concerns/curation_concerns/single_use_links_controller_behavior.rb
curation_concerns-1.1.0 app/controllers/concerns/curation_concerns/single_use_links_controller_behavior.rb
curation_concerns-1.0.0 app/controllers/concerns/curation_concerns/single_use_links_controller_behavior.rb
curation_concerns-1.0.0.beta10 app/controllers/concerns/curation_concerns/single_use_links_controller_behavior.rb
curation_concerns-1.0.0.beta9 app/controllers/concerns/curation_concerns/single_use_links_controller_behavior.rb
curation_concerns-1.0.0.beta8 app/controllers/concerns/curation_concerns/single_use_links_controller_behavior.rb
curation_concerns-1.0.0.beta7 app/controllers/concerns/curation_concerns/single_use_links_controller_behavior.rb
curation_concerns-1.0.0.beta6 app/controllers/concerns/curation_concerns/single_use_links_controller_behavior.rb
curation_concerns-1.0.0.beta5 app/controllers/concerns/curation_concerns/single_use_links_controller_behavior.rb
curation_concerns-1.0.0.beta4 app/controllers/concerns/curation_concerns/single_use_links_controller_behavior.rb
curation_concerns-1.0.0.beta3 app/controllers/concerns/curation_concerns/single_use_links_controller_behavior.rb
curation_concerns-1.0.0.beta2 app/controllers/concerns/curation_concerns/single_use_links_controller_behavior.rb
curation_concerns-1.0.0.beta1 app/controllers/concerns/curation_concerns/single_use_links_controller_behavior.rb
curation_concerns-0.14.0 app/controllers/concerns/curation_concerns/single_use_links_controller_behavior.rb
curation_concerns-0.14.0.pre4 app/controllers/concerns/curation_concerns/single_use_links_controller_behavior.rb
curation_concerns-0.14.0.pre3 app/controllers/concerns/curation_concerns/single_use_links_controller_behavior.rb
curation_concerns-0.14.0.pre2 app/controllers/concerns/curation_concerns/single_use_links_controller_behavior.rb
curation_concerns-0.14.0.pre1 app/controllers/concerns/curation_concerns/single_use_links_controller_behavior.rb
curation_concerns-0.13.1 app/controllers/concerns/curation_concerns/single_use_links_controller_behavior.rb