Sha256: a23f7b3506a8f22db1ace1d811c47e7673b6bf9acc7b61a282a5f77bbe3235d4

Contents?: true

Size: 1.88 KB

Versions: 1

Compression:

Stored size: 1.88 KB

Contents

require 'mime/types'

module FcrepoAdmin
  class DatastreamsController < ApplicationController

    layout 'fcrepo_admin/datastreams', :except => :index
    layout 'fcrepo_admin/objects', :only => :index

    include Hydra::Controller::ControllerBehavior
    include Hydra::PolicyAwareAccessControlsEnforcement
    include FcrepoAdmin::Controller::ControllerBehavior

    before_filter :load_and_authorize_object
    before_filter :load_datastream, :except => :index

    def index
    end

    def show
    end

    def content
      unless @datastream.content_is_text?
        render :text => "Datastream content is not text.", :status => 403
      end
    end

    def history
    end

    def download
      # XXX Replace with Hydra download behavior?
      mimetypes = MIME::Types[@datastream.mimeType]
      send_data @datastream.content, :disposition => 'attachment', :type => @datastream.mimeType, :filename => "#{@datastream.pid.sub(/:/, '_')}_#{@datastream.dsid}.#{mimetypes.first.extensions.first}"                
    end

    def edit
      unless @datastream.content_is_editable?
        render :text => "Datastream content is not editable", :status => 403
      end
    end

    def upload
      unless @datastream.content_is_uploadable?
        render :text => "This datstream does not support file content", :status => 403
      end
    end

    def update
      if params[:file] # file uploaded
        @datastream.content = params[:file].read
      else # content submitted
        @datastream.content = params[:content]
      end
      @object.save
      flash[:notice] = "Datastream content updated." # i18n
      redirect_to fcrepo_admin.object_datastream_url(@object, @datastream)
    end

    private
    
    def load_datastream
      @datastream = @object.datastreams[params[:id]]
      @datastream = @datastream.asOfDateTime(params[:asOfDateTime]) if params[:asOfDateTime]
    end

  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
fcrepo_admin-0.5.0 app/controllers/fcrepo_admin/datastreams_controller.rb