files_controller.rb revision 7a771e3ff4b1a608c4e9031cfb1a225f633f4d33
bcb4e51a409d94ae670de96afb8483a4f7855294Stephan Boschclass FilesController < InheritedResources::Base
7bd5b1c64cc987715bdaf8cc4907c3c37d5d7b29Timo Sirainen helper_method :repository, :ref, :oid, :path, :branch_name
7bd5b1c64cc987715bdaf8cc4907c3c37d5d7b29Timo Sirainen before_filter :check_write_permissions, only: [:new, :create, :update]
678d0463849ba777106eb7875f27db07a5d8e3dfTimo Sirainen # TODO: the query_string check should be done in the iri router
7bd5b1c64cc987715bdaf8cc4907c3c37d5d7b29Timo Sirainen ontology = resource.ontologies.first.children.where(name: request.query_string).first
7bd5b1c64cc987715bdaf8cc4907c3c37d5d7b29Timo Sirainen render json: repository.entries_info(oid, path)
7bd5b1c64cc987715bdaf8cc4907c3c37d5d7b29Timo Sirainen @changed_files = repository.changed_files(oid)
7bd5b1c64cc987715bdaf8cc4907c3c37d5d7b29Timo Sirainen page = @page = params[:page].nil? ? 1 : params[:page].to_i
7bd5b1c64cc987715bdaf8cc4907c3c37d5d7b29Timo Sirainen offset = page > 0 ? (page - 1) * @per_page : 0
a75d470c9223a75801418fcdda258885c36317e0Timo Sirainen @current_file = repository.get_file(path, oid) if path && !repository.dir?(path)
7bd5b1c64cc987715bdaf8cc4907c3c37d5d7b29Timo Sirainen @commits = repository.commits(start_oid: oid, path: path, offset: offset, limit: @per_page)
7bd5b1c64cc987715bdaf8cc4907c3c37d5d7b29Timo Sirainen @repository_file = resource_class.build(params.merge(user: current_user))
7bd5b1c64cc987715bdaf8cc4907c3c37d5d7b29Timo Sirainen @repository_file = resource_class.create(params.merge(user: current_user))
7bd5b1c64cc987715bdaf8cc4907c3c37d5d7b29Timo Sirainen flash[:success] = "Successfully saved the uploaded file."
7bd5b1c64cc987715bdaf8cc4907c3c37d5d7b29Timo Sirainen if ontology = repository.ontologies.find_by_file(resource.target_path)
7bd5b1c64cc987715bdaf8cc4907c3c37d5d7b29Timo Sirainen redirect_to edit_repository_ontology_path(repository, ontology)
7bd5b1c64cc987715bdaf8cc4907c3c37d5d7b29Timo Sirainen redirect_to fancy_repository_path(repository, path: resource.target_path)
7bd5b1c64cc987715bdaf8cc4907c3c37d5d7b29Timo Sirainen @repository_file = resource_class.create(params.merge(user: current_user))
7bd5b1c64cc987715bdaf8cc4907c3c37d5d7b29Timo Sirainen flash[:success] = "Successfully changed the file."
7bd5b1c64cc987715bdaf8cc4907c3c37d5d7b29Timo Sirainen redirect_to fancy_repository_path(repository, path: resource.target_path)
7bd5b1c64cc987715bdaf8cc4907c3c37d5d7b29Timo Sirainen @repository_file ||= RepositoryFile.find_with_path(params)
7bd5b1c64cc987715bdaf8cc4907c3c37d5d7b29Timo Sirainen @repository ||= Repository.find_by_path!(params[:repository_id])
b66d803de86bfb411165b3465b0d9ef64ecfe2a1Timo Sirainen render text: repository.get_file(path, oid).content,
7bd5b1c64cc987715bdaf8cc4907c3c37d5d7b29Timo Sirainen content_type: Mime::Type.lookup('application/force-download')
7bd5b1c64cc987715bdaf8cc4907c3c37d5d7b29Timo Sirainen @commit_id ||= repository.commit_id(params[:ref])
6abf66a3731d52889517bd644595c540e3a9b3ecTimo Sirainen @oid ||= commit_id[:oid] unless commit_id.nil?
45ce71b79700c057074ae847bc3d0d9d86b34919Timo Sirainen # OWL API sends those two http accept headers in different requests:
7bd5b1c64cc987715bdaf8cc4907c3c37d5d7b29Timo Sirainen # application/rdf+xml, application/xml; q=0.5, text/xml; q=0.3, */*; q=0.2
7bd5b1c64cc987715bdaf8cc4907c3c37d5d7b29Timo Sirainen # text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2
7bd5b1c64cc987715bdaf8cc4907c3c37d5d7b29Timo Sirainen # The latter conflicts with what browsers send.
7bd5b1c64cc987715bdaf8cc4907c3c37d5d7b29Timo Sirainen (accepts.present? && accepts.first != Mime::HTML) ||
7bd5b1c64cc987715bdaf8cc4907c3c37d5d7b29Timo Sirainen accepts[0..2] == [Mime::HTML, Mime::GIF, Mime::JPEG]