2012-09-17 12:38:59 -04:00
|
|
|
# Controller for viewing a repository's file structure
|
2015-01-26 18:01:51 -05:00
|
|
|
class Projects::TreeController < Projects::ApplicationController
|
|
|
|
include ExtractsPath
|
2015-12-18 04:03:34 -05:00
|
|
|
include CreatesCommit
|
2015-09-17 01:45:22 -04:00
|
|
|
include ActionView::Helpers::SanitizeHelper
|
2015-01-26 18:01:51 -05:00
|
|
|
|
2015-04-16 08:03:37 -04:00
|
|
|
before_action :require_non_empty_project, except: [:new, :create]
|
|
|
|
before_action :assign_ref_vars
|
2015-09-17 01:45:22 -04:00
|
|
|
before_action :assign_dir_vars, only: [:create_dir]
|
2015-04-16 08:03:37 -04:00
|
|
|
before_action :authorize_download_code!
|
2015-12-18 04:03:34 -05:00
|
|
|
before_action :authorize_edit_tree!, only: [:create_dir]
|
2014-07-07 09:46:57 -04:00
|
|
|
|
2015-01-26 18:01:51 -05:00
|
|
|
def show
|
2015-10-09 13:07:29 -04:00
|
|
|
return render_404 unless @repository.commit(@ref)
|
2015-07-20 19:55:45 -04:00
|
|
|
|
2014-07-07 09:46:57 -04:00
|
|
|
if tree.entries.empty?
|
|
|
|
if @repository.blob_at(@commit.id, @path)
|
2017-02-21 17:31:14 -05:00
|
|
|
return redirect_to(
|
2017-06-29 13:06:35 -04:00
|
|
|
project_blob_path(@project,
|
2015-01-24 13:02:58 -05:00
|
|
|
File.join(@ref, @path))
|
2017-02-21 17:31:14 -05:00
|
|
|
)
|
2015-07-20 19:55:45 -04:00
|
|
|
elsif @path.present?
|
2015-10-09 13:07:29 -04:00
|
|
|
return render_404
|
2014-07-07 09:46:57 -04:00
|
|
|
end
|
|
|
|
end
|
2013-10-01 10:00:28 -04:00
|
|
|
|
2012-09-17 12:38:59 -04:00
|
|
|
respond_to do |format|
|
2017-05-26 14:51:24 -04:00
|
|
|
format.html do
|
2017-12-14 06:59:01 -05:00
|
|
|
lfs_blob_ids
|
2017-05-26 14:51:24 -04:00
|
|
|
@last_commit = @repository.last_commit_for_path(@commit.id, @tree.path) || @commit
|
|
|
|
end
|
|
|
|
|
|
|
|
format.js do
|
|
|
|
# Disable cache so browser history works
|
|
|
|
no_cache_headers
|
|
|
|
end
|
|
|
|
|
|
|
|
format.json do
|
2017-08-23 07:23:41 -04:00
|
|
|
page_title @path.presence || _("Files"), @ref, @project.name_with_namespace
|
|
|
|
|
2017-09-22 12:53:08 -04:00
|
|
|
# n+1: https://gitlab.com/gitlab-org/gitlab-ce/issues/38261
|
|
|
|
Gitlab::GitalyClient.allow_n_plus_1_calls do
|
|
|
|
render json: TreeSerializer.new(project: @project, repository: @repository, ref: @ref).represent(@tree)
|
|
|
|
end
|
2017-05-26 14:51:24 -04:00
|
|
|
end
|
2012-09-17 12:38:59 -04:00
|
|
|
end
|
|
|
|
end
|
2015-09-17 01:45:22 -04:00
|
|
|
|
|
|
|
def create_dir
|
2015-10-09 13:07:29 -04:00
|
|
|
return render_404 unless @commit_params.values.all?
|
2015-09-17 01:45:22 -04:00
|
|
|
|
2015-12-18 04:03:34 -05:00
|
|
|
create_commit(Files::CreateDirService, success_notice: "The directory has been successfully created.",
|
2017-06-29 13:06:35 -04:00
|
|
|
success_path: project_tree_path(@project, File.join(@branch_name, @dir_name)),
|
|
|
|
failure_path: project_tree_path(@project, @ref))
|
2015-09-17 01:45:22 -04:00
|
|
|
end
|
|
|
|
|
2015-11-17 12:53:56 -05:00
|
|
|
private
|
|
|
|
|
2015-09-17 01:45:22 -04:00
|
|
|
def assign_dir_vars
|
2017-04-19 20:37:44 -04:00
|
|
|
@branch_name = params[:branch_name]
|
2015-12-18 04:03:34 -05:00
|
|
|
|
2015-09-17 01:45:22 -04:00
|
|
|
@dir_name = File.join(@path, params[:dir_name])
|
|
|
|
@commit_params = {
|
|
|
|
file_path: @dir_name,
|
2017-05-03 07:22:03 -04:00
|
|
|
commit_message: params[:commit_message]
|
2015-09-17 01:45:22 -04:00
|
|
|
}
|
|
|
|
end
|
2012-09-17 12:38:59 -04:00
|
|
|
end
|