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

67 lines
2 KiB
Ruby
Raw Normal View History

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
2015-10-24 18:46:33 +05:30
include ActionView::Helpers::SanitizeHelper
2015-04-26 12:48:37 +05:30
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]
2015-09-11 14:41:01 +05:30
before_action :authorize_download_code!
2015-10-24 18:46:33 +05:30
before_action :authorize_push_code!, only: [:create_dir]
2014-09-02 18:07:02 +05:30
2015-04-26 12:48:37 +05:30
def show
2015-10-24 18:46:33 +05:30
return render_404 unless @repository.commit(@ref)
2015-09-11 14:41:01 +05:30
2014-09-02 18:07:02 +05:30
if tree.entries.empty?
if @repository.blob_at(@commit.id, @path)
2015-04-26 12:48:37 +05:30
redirect_to(
namespace_project_blob_path(@project.namespace, @project,
File.join(@ref, @path))
) and return
2015-09-11 14:41:01 +05:30
elsif @path.present?
2015-10-24 18:46:33 +05:30
return render_404
2014-09-02 18:07:02 +05:30
end
end
respond_to do |format|
format.html
# Disable cache so browser history works
format.js { no_cache_headers }
end
end
2015-10-24 18:46:33 +05:30
def create_dir
return render_404 unless @commit_params.values.all?
begin
result = Files::CreateDirService.new(@project, current_user, @commit_params).execute
message = result[:message]
rescue => e
message = e.to_s
end
if result && result[:status] == :success
flash[:notice] = "The directory has been successfully created"
respond_to do |format|
format.html { redirect_to namespace_project_blob_path(@project.namespace, @project, File.join(@new_branch, @dir_name)) }
end
else
flash[:alert] = message
respond_to do |format|
format.html { redirect_to namespace_project_blob_path(@project.namespace, @project, @new_branch) }
end
end
end
def assign_dir_vars
@new_branch = params[:new_branch].present? ? sanitize(strip_tags(params[:new_branch])) : @ref
@dir_name = File.join(@path, params[:dir_name])
@commit_params = {
file_path: @dir_name,
current_branch: @ref,
target_branch: @new_branch,
commit_message: params[:commit_message],
}
end
2014-09-02 18:07:02 +05:30
end