files_controller.rb revision 21429036acbcc2f51ef24fc38b78c85a3ab2f6c3
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagherclass FilesController < ApplicationController
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher before_filter :check_permissions, only: [:new, :create]
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher #load_and_authorize_resource :except => [:index, :show]
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher commit_id = repository.commit_id(params[:ref])
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher @info = repository.path_info(params[:path], @oid)
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher raise Repository::FileNotFoundError, params[:path] if @info.nil?
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher if request.format == 'text/html' || @info[:type] != :file
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher where(basepath: File.basepath(@info[:entry][:path])).
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher redirect_to [repository, ontologies.first]
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher render text: repository.read_file(@path, @oid)[:content],
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher content_type: Mime::Type.lookup('application/force-download')
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher render json: repository.entries_info(@oid, params[:path])
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher @oid = repository.commit_id(params[:ref])[:oid]
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher @changed_files = repository.changed_files(@oid)
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher @oid = repository.commit_id(params[:ref])[:oid]
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher @current_file = repository.read_file(@path, @oid) if @path
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher @commits = repository.commits(start_oid: @oid, path: @path)
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher repository.save_file @file.file.path, @file.filepath, @file.message, current_user
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher flash[:success] = "Successfully saved uploaded file."
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher redirect_to fancy_repository_path(repository, path: @file.path)
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher @repository ||= Repository.find_by_path!(params[:repository_id])