gitlab-org--gitlab-foss/app/controllers/projects/tree_controller.rb

54 lines
1.7 KiB
Ruby
Raw Normal View History

2012-09-17 12:38:59 -04:00
# Controller for viewing a repository's file structure
class Projects::TreeController < Projects::ApplicationController
include ExtractsPath
include CreatesCommit
include ActionView::Helpers::SanitizeHelper
before_action :require_non_empty_project, except: [:new, :create]
before_action :assign_ref_vars
before_action :assign_dir_vars, only: [:create_dir]
before_action :authorize_download_code!
before_action :authorize_edit_tree!, only: [:create_dir]
def show
2015-10-09 13:07:29 -04:00
return render_404 unless @repository.commit(@ref)
if tree.entries.empty?
if @repository.blob_at(@commit.id, @path)
redirect_to(
namespace_project_blob_path(@project.namespace, @project,
File.join(@ref, @path))
) and return
elsif @path.present?
2015-10-09 13:07:29 -04:00
return render_404
end
end
2013-10-01 10:00:28 -04:00
2012-09-17 12:38:59 -04:00
respond_to do |format|
format.html
# Disable cache so browser history works
format.js { no_cache_headers }
end
end
def create_dir
2015-10-09 13:07:29 -04:00
return render_404 unless @commit_params.values.all?
create_commit(Files::CreateDirService, success_notice: "The directory has been successfully created.",
2015-12-18 10:14:12 -05:00
success_path: namespace_project_tree_path(@project.namespace, @project, File.join(@target_branch, @dir_name)),
failure_path: namespace_project_tree_path(@project.namespace, @project, @ref))
end
private
def assign_dir_vars
@target_branch = params[:target_branch]
@dir_name = File.join(@path, params[:dir_name])
@commit_params = {
file_path: @dir_name,
commit_message: params[:commit_message],
}
end
2012-09-17 12:38:59 -04:00
end