debian-mirror-gitlab/app/controllers/projects/tree_controller.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

79 lines
2.2 KiB
Ruby
Raw Normal View History

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