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-11-17 12:53:56 -05:00
|
|
|
include CreatesMergeRequestForCommit
|
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-09-17 01:45:22 -04:00
|
|
|
before_action :authorize_push_code!, 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)
|
2015-01-24 13:02:58 -05:00
|
|
|
redirect_to(
|
|
|
|
namespace_project_blob_path(@project.namespace, @project,
|
|
|
|
File.join(@ref, @path))
|
|
|
|
) and return
|
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|
|
|
|
|
format.html
|
|
|
|
# Disable cache so browser history works
|
|
|
|
format.js { no_cache_headers }
|
|
|
|
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
|
|
|
|
|
|
|
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|
|
2015-11-17 12:53:56 -05:00
|
|
|
format.html { redirect_to after_create_dir_path }
|
2015-09-17 01:45:22 -04:00
|
|
|
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
|
|
|
|
|
2015-11-17 12:53:56 -05:00
|
|
|
private
|
|
|
|
|
2015-09-17 01:45:22 -04:00
|
|
|
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
|
2015-11-17 12:53:56 -05:00
|
|
|
|
|
|
|
def after_create_dir_path
|
|
|
|
if create_merge_request?
|
|
|
|
new_merge_request_path
|
|
|
|
else
|
|
|
|
namespace_project_blob_path(@project.namespace, @project, File.join(@new_branch, @dir_name))
|
|
|
|
end
|
|
|
|
end
|
2012-09-17 12:38:59 -04:00
|
|
|
end
|