Skip to content
Snippets Groups Projects
Select Git revision
  • 510995-feature-flag-rollout-of-reject_security_policy_project_deletion_groups-2-removal
  • 515035-add-admin-roles-to-roles-and-permissions-page
  • master default protected
  • 505045-add-all-available-groups-resolver
  • resolve-issue-479191
  • julianthome/add-sast-estensions
  • 507722-vsd-be-projects-by-dora-table-improve-the-accuracy-of-the-projects-representation
  • 515973-dast-docs-timeout-explanation-diagram
  • tbulva-long-line-bug
  • georgekoltsov/restartable-project-import
  • 513321-remove-ff-proj-comp-filter
  • zoekt-speed-up-scheduling-events
  • ag/469118-bso-com-notifications-copy
  • adjust-feature-settings-mutation
  • 520688-add-zoekt-info-rake-task
  • design-item-a11y-alignment-fixes
  • poc/gb/auth-layers-poc
  • 506542-prevent-all-protected-branches-squash-option
  • 523000-follow-up-from-clean-up-main-seats-app-from-vuex-store
  • 515973-dast-ducumentation-improvements
  • v17.7.6-ee protected
  • v17.8.4-ee protected
  • v17.9.1-ee protected
  • v17.8.3-ee protected
  • v17.7.5-ee protected
  • v17.9.0-ee protected
  • v17.9.0-rc42-ee protected
  • v17.6.5-ee protected
  • v17.7.4-ee protected
  • v17.8.2-ee protected
  • v17.6.4-ee protected
  • v17.7.3-ee protected
  • v17.8.1-ee protected
  • v17.8.0-ee protected
  • v17.7.2-ee protected
  • v17.8.0-rc42-ee protected
  • v17.5.5-ee protected
  • v17.6.3-ee protected
  • v17.7.1-ee protected
  • v17.7.0-ee protected
40 results

tree_controller.rb

234
tree_controller.rb 1.85 KiB
# frozen_string_literal: true

# Controller for viewing a repository's file structure
class Projects::TreeController < Projects::ApplicationController
  include ExtractsPath
  include CreatesCommit
  include ActionView::Helpers::SanitizeHelper
  include RedirectsForMissingPathOnTree
  include SourcegraphDecorator

  around_action :allow_gitaly_ref_name_caching, only: [:show]

  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_read_code!
  before_action :authorize_edit_tree!, only: [:create_dir]

  before_action do
    push_frontend_feature_flag(:highlight_js, @project)
    push_licensed_feature(:file_locks) if @project.licensed_feature_available?(:file_locks)
  end

  feature_category :source_code_management
  urgency :low, [:show]

  def show
    return render_404 unless @commit

    if tree.entries.empty?
      if @repository.blob_at(@commit.id, @path)
        redirect_to project_blob_path(@project, File.join(@ref, @path))
      elsif @path.present?
        redirect_to_tree_root_for_missing_path(@project, @ref, @path)
      end
    end
  end

  def create_dir
    return render_404 unless @commit_params.values.all?

    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)
    )
  end

  private

  def redirect_renamed_default_branch?
    action_name == 'show'
  end

  def assign_dir_vars
    @branch_name = params[:branch_name]

    @dir_name = File.join(@path, params[:dir_name])
    @commit_params = {
      file_path: @dir_name,
      commit_message: params[:commit_message]
    }
  end
end

Projects::TreeController.prepend_mod