2018-12-05 23:21:45 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2014-09-02 18:07:02 +05:30
|
|
|
# Controller for viewing a file's blame
|
|
|
|
class Projects::BlameController < Projects::ApplicationController
|
|
|
|
include ExtractsPath
|
2019-12-26 22:10:19 +05:30
|
|
|
include RedirectsForMissingPathOnTree
|
2014-09-02 18:07:02 +05:30
|
|
|
|
2015-09-11 14:41:01 +05:30
|
|
|
before_action :require_non_empty_project
|
|
|
|
before_action :assign_ref_vars
|
2023-03-04 22:38:38 +05:30
|
|
|
before_action :authorize_read_code!
|
2014-09-02 18:07:02 +05:30
|
|
|
|
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
|
|
|
|
2014-09-02 18:07:02 +05:30
|
|
|
def show
|
2015-09-11 14:41:01 +05:30
|
|
|
@blob = @repository.blob_at(@commit.id, @path)
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2019-12-26 22:10:19 +05:30
|
|
|
unless @blob
|
|
|
|
return redirect_to_tree_root_for_missing_path(@project, @ref, @path)
|
|
|
|
end
|
2017-08-17 22:00:37 +05:30
|
|
|
|
|
|
|
environment_params = @repository.branch_exists?(@ref) ? { ref: @ref } : { commit: @commit }
|
2020-03-13 15:44:24 +05:30
|
|
|
environment_params[:find_latest] = true
|
2021-06-08 01:23:25 +05:30
|
|
|
@environment = ::Environments::EnvironmentsByDeploymentsFinder.new(@project, current_user, environment_params).execute.last
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2023-05-27 22:25:52 +05:30
|
|
|
permitted_params = params.permit(:page, :no_pagination, :streaming)
|
|
|
|
blame_service = Projects::BlameService.new(@blob, @commit, permitted_params)
|
2022-07-16 23:28:13 +05:30
|
|
|
|
2022-08-13 15:12:31 +05:30
|
|
|
@blame = Gitlab::View::Presenter::Factory.new(blame_service.blame, project: @project, path: @path, page: blame_service.page).fabricate!
|
2022-11-25 23:54:43 +05:30
|
|
|
|
2023-05-27 22:25:52 +05:30
|
|
|
@entire_blame_path = full_blame_path(no_pagination: true)
|
|
|
|
@blame_pages_url = blame_pages_url(permitted_params)
|
|
|
|
if blame_service.streaming_possible
|
|
|
|
@entire_blame_path = full_blame_path(streaming: true)
|
|
|
|
end
|
|
|
|
|
|
|
|
@streaming_enabled = blame_service.streaming_enabled
|
|
|
|
@blame_pagination = blame_service.pagination unless @streaming_enabled
|
2022-11-25 23:54:43 +05:30
|
|
|
|
|
|
|
@blame_per_page = blame_service.per_page
|
2023-05-27 22:25:52 +05:30
|
|
|
|
|
|
|
render locals: { total_extra_pages: blame_service.total_extra_pages }
|
|
|
|
end
|
|
|
|
|
|
|
|
def page
|
|
|
|
@blob = @repository.blob_at(@commit.id, @path)
|
|
|
|
|
|
|
|
environment_params = @repository.branch_exists?(@ref) ? { ref: @ref } : { commit: @commit }
|
|
|
|
environment_params[:find_latest] = true
|
|
|
|
@environment = ::Environments::EnvironmentsByDeploymentsFinder.new(@project, current_user, environment_params).execute.last
|
|
|
|
|
|
|
|
blame_service = Projects::BlameService.new(@blob, @commit, params.permit(:page, :streaming))
|
|
|
|
|
|
|
|
@blame = Gitlab::View::Presenter::Factory.new(blame_service.blame, project: @project, path: @path, page: blame_service.page).fabricate!
|
|
|
|
|
|
|
|
render partial: 'page'
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def full_blame_path(params)
|
|
|
|
namespace_project_blame_path(namespace_id: @project.namespace, project_id: @project, id: @id, **params)
|
|
|
|
end
|
|
|
|
|
|
|
|
def blame_pages_url(params)
|
|
|
|
namespace_project_blame_page_url(namespace_id: @project.namespace, project_id: @project, id: @id, **params)
|
2014-09-02 18:07:02 +05:30
|
|
|
end
|
|
|
|
end
|
2022-01-26 12:08:38 +05:30
|
|
|
|
|
|
|
Projects::BlameController.prepend_mod
|