2020-10-15 02:09:14 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module WebIdeButtonHelper
|
|
|
|
def project_fork
|
|
|
|
current_user&.fork_of(@project)
|
|
|
|
end
|
|
|
|
|
|
|
|
def project_to_use
|
|
|
|
fork? ? project_fork : @project
|
|
|
|
end
|
|
|
|
|
|
|
|
def can_collaborate?
|
|
|
|
can_collaborate_with_project?(@project)
|
|
|
|
end
|
|
|
|
|
|
|
|
def can_create_mr_from_fork?
|
|
|
|
can?(current_user, :fork_project, @project) && can?(current_user, :create_merge_request_in, @project)
|
|
|
|
end
|
|
|
|
|
|
|
|
def show_web_ide_button?
|
|
|
|
can_collaborate? || can_create_mr_from_fork?
|
|
|
|
end
|
|
|
|
|
2020-12-09 07:09:42 -05:00
|
|
|
def show_edit_button?(options = {})
|
|
|
|
readable_blob?(options) && show_web_ide_button?
|
2020-10-15 02:09:14 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def show_gitpod_button?
|
2021-01-12 10:10:37 -05:00
|
|
|
show_web_ide_button? && Gitlab::CurrentSettings.gitpod_enabled
|
2020-10-15 02:09:14 -04:00
|
|
|
end
|
|
|
|
|
2022-02-24 07:12:57 -05:00
|
|
|
def show_pipeline_editor_button?(project, path)
|
|
|
|
can_view_pipeline_editor?(project) && path == project.ci_config_path_or_default
|
|
|
|
end
|
|
|
|
|
2020-10-15 02:09:14 -04:00
|
|
|
def can_push_code?
|
|
|
|
current_user&.can?(:push_code, @project)
|
|
|
|
end
|
|
|
|
|
|
|
|
def fork?
|
|
|
|
!project_fork.nil? && !can_push_code?
|
|
|
|
end
|
|
|
|
|
2020-12-09 07:09:42 -05:00
|
|
|
def readable_blob?(options = {})
|
|
|
|
!readable_blob(options, @path, @project, @ref).nil?
|
2020-10-15 02:09:14 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def needs_to_fork?
|
|
|
|
!can_collaborate? && !current_user&.already_forked?(@project)
|
|
|
|
end
|
|
|
|
|
|
|
|
def web_ide_url
|
|
|
|
ide_edit_path(project_to_use, @ref, @path || '')
|
|
|
|
end
|
|
|
|
|
2020-12-09 07:09:42 -05:00
|
|
|
def edit_url(options = {})
|
|
|
|
readable_blob?(options) ? edit_blob_path(@project, @ref, @path || '') : ''
|
2020-10-15 02:09:14 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def gitpod_url
|
2021-01-12 10:10:37 -05:00
|
|
|
return "" unless Gitlab::CurrentSettings.gitpod_enabled
|
2020-10-15 02:09:14 -04:00
|
|
|
|
|
|
|
"#{Gitlab::CurrentSettings.gitpod_url}##{project_tree_url(@project, tree_join(@ref, @path || ''))}"
|
|
|
|
end
|
|
|
|
end
|