2018-09-26 03:45:43 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2012-09-17 16:38:59 +00:00
|
|
|
# Controller for viewing a repository's file structure
|
2015-01-26 23:01:51 +00:00
|
|
|
class Projects::TreeController < Projects::ApplicationController
|
|
|
|
include ExtractsPath
|
2015-12-18 09:03:34 +00:00
|
|
|
include CreatesCommit
|
2015-09-17 05:45:22 +00:00
|
|
|
include ActionView::Helpers::SanitizeHelper
|
2019-10-21 18:06:29 +00:00
|
|
|
include RedirectsForMissingPathOnTree
|
2022-01-17 18:16:07 +00:00
|
|
|
include SourcegraphDecorator
|
2015-01-26 23:01:51 +00:00
|
|
|
|
2019-04-08 03:55:29 +00:00
|
|
|
around_action :allow_gitaly_ref_name_caching, only: [:show]
|
|
|
|
|
2015-04-16 12:03:37 +00:00
|
|
|
before_action :require_non_empty_project, except: [:new, :create]
|
|
|
|
before_action :assign_ref_vars
|
2015-09-17 05:45:22 +00:00
|
|
|
before_action :assign_dir_vars, only: [:create_dir]
|
2015-04-16 12:03:37 +00:00
|
|
|
before_action :authorize_download_code!
|
2015-12-18 09:03:34 +00:00
|
|
|
before_action :authorize_edit_tree!, only: [:create_dir]
|
2014-07-07 13:46:57 +00:00
|
|
|
|
2021-09-02 15:11:35 +00:00
|
|
|
before_action do
|
2022-05-06 15:09:03 +00:00
|
|
|
push_frontend_feature_flag(:lazy_load_commits, @project)
|
|
|
|
push_frontend_feature_flag(:refactor_blob_viewer, @project)
|
|
|
|
push_frontend_feature_flag(:highlight_js, @project)
|
2022-01-19 00:12:04 +00:00
|
|
|
push_licensed_feature(:file_locks) if @project.licensed_feature_available?(:file_locks)
|
2021-09-02 15:11:35 +00:00
|
|
|
end
|
|
|
|
|
2020-10-08 18:08:32 +00:00
|
|
|
feature_category :source_code_management
|
2021-11-12 18:12:20 +00:00
|
|
|
urgency :low, [:show]
|
2020-10-08 18:08:32 +00:00
|
|
|
|
2015-01-26 23:01:51 +00:00
|
|
|
def show
|
2020-06-26 18:09:03 +00:00
|
|
|
return render_404 unless @commit
|
2015-07-20 23:55:45 +00:00
|
|
|
|
2014-07-07 13:46:57 +00:00
|
|
|
if tree.entries.empty?
|
|
|
|
if @repository.blob_at(@commit.id, @path)
|
2020-07-11 00:09:17 +00:00
|
|
|
redirect_to project_blob_path(@project, File.join(@ref, @path))
|
2015-07-20 23:55:45 +00:00
|
|
|
elsif @path.present?
|
2020-07-11 00:09:17 +00:00
|
|
|
redirect_to_tree_root_for_missing_path(@project, @ref, @path)
|
2014-07-07 13:46:57 +00:00
|
|
|
end
|
|
|
|
end
|
2012-09-17 16:38:59 +00:00
|
|
|
end
|
2015-09-17 05:45:22 +00:00
|
|
|
|
|
|
|
def create_dir
|
2015-10-09 17:07:29 +00:00
|
|
|
return render_404 unless @commit_params.values.all?
|
2015-09-17 05:45:22 +00:00
|
|
|
|
2019-03-27 16:52:52 +00:00
|
|
|
create_commit(Files::CreateDirService, success_notice: _("The directory has been successfully created."),
|
2017-06-29 17:06:35 +00:00
|
|
|
success_path: project_tree_path(@project, File.join(@branch_name, @dir_name)),
|
|
|
|
failure_path: project_tree_path(@project, @ref))
|
2015-09-17 05:45:22 +00:00
|
|
|
end
|
|
|
|
|
2015-11-17 17:53:56 +00:00
|
|
|
private
|
|
|
|
|
2021-07-14 12:09:23 +00:00
|
|
|
def redirect_renamed_default_branch?
|
|
|
|
action_name == 'show'
|
|
|
|
end
|
|
|
|
|
2015-09-17 05:45:22 +00:00
|
|
|
def assign_dir_vars
|
2017-04-20 00:37:44 +00:00
|
|
|
@branch_name = params[:branch_name]
|
2015-12-18 09:03:34 +00:00
|
|
|
|
2015-09-17 05:45:22 +00:00
|
|
|
@dir_name = File.join(@path, params[:dir_name])
|
|
|
|
@commit_params = {
|
|
|
|
file_path: @dir_name,
|
2017-05-03 11:22:03 +00:00
|
|
|
commit_message: params[:commit_message]
|
2015-09-17 05:45:22 +00:00
|
|
|
}
|
|
|
|
end
|
2012-09-17 16:38:59 +00:00
|
|
|
end
|
2021-12-06 15:14:39 +00:00
|
|
|
|
|
|
|
Projects::TreeController.prepend_mod
|