files_controller.rb revision 9cfb01db247ca04bb4b5b337bbd77c66b7150e53
a4544a5a0e622ef69e38641f87ab1b5685e05911Phill Cunningtonclass FilesController < ApplicationController
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster helper_method :repository
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster before_filter :check_permissions, only: [:new, :create]
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster # FIXME
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster #load_and_authorize_resource :except => [:index, :show]
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster def files
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster commit_id = repository.commit_id(params[:oid])
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster @oid = commit_id[:oid]
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster @branch_name = commit_id[:branch_name]
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster @path = params[:path]
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster @info = repository.path_info(params[:path], @oid)
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster raise Repository::FileNotFoundError, params[:path] if @info.nil?
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster if request.format == 'text/html' || @info[:type] != :file
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster case @info[:type]
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster when :file
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster @file = repository.read_file(@path, params[:oid])
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster when :file_base
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster # TODO: redirect to ontology view instead of rendering file view
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster @path = @info[:entry][:path]
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster @file = repository.read_file(@path, params[:oid])
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster end
a4544a5a0e622ef69e38641f87ab1b5685e05911Phill Cunnington else
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster render text: repository.read_file(@path, @oid)[:content],
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster content_type: Mime::Type.lookup('application/force-download')
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster end
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster end
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
449854c2a07b50ea64d9d6a8b03d18d4afeeee43Ken Stubbings def entries_info
449854c2a07b50ea64d9d6a8b03d18d4afeeee43Ken Stubbings render json: repository.entries_info(@oid, params[:path])
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster end
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster def diff
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster @oid = repository.commit_id(params[:oid])[:oid]
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster @changed_files = repository.changed_files(@oid)
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster end
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster def history
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster @path = params[:path]
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster @oid = repository.commit_id(params[:oid])[:oid]
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster @current_file = repository.read_file(@path, @oid) if @path
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster @commits = repository.commits(@oid, @path)
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster end
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster def new
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster build_file
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster end
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster def create
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster if build_file.valid?
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster repository.save_file @file.file.path, @file.filepath, @file.message, current_user
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster flash[:success] = "Successfully saved uploaded file."
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster redirect_to fancy_repository_path(repository, path: @file.path)
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster end
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster end
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster protected
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster def repository
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster @repository ||= Repository.find_by_path!(params[:repository_id])
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster end
449854c2a07b50ea64d9d6a8b03d18d4afeeee43Ken Stubbings
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster def build_file
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster @file ||= UploadFile.new(params[:upload_file])
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster end
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster def check_permissions
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster authorize! :write, repository
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster end
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Fosterend
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster