Welcome to mirror list, hosted at ThFree Co, Russian Federation.

web_ide_button_helper.rb « helpers « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 9ec22a659d32288cc99f3a86e7d000a8cec05d97 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# 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

  def show_edit_button?(options = {})
    readable_blob?(options) && show_web_ide_button?
  end

  def show_gitpod_button?
    show_web_ide_button? && Gitlab::CurrentSettings.gitpod_enabled
  end

  def show_pipeline_editor_button?(project, path)
    can_view_pipeline_editor?(project) && path == project.ci_config_path_or_default
  end

  def can_push_code?
    current_user&.can?(:push_code, @project)
  end

  def fork?
    !project_fork.nil? && !can_push_code?
  end

  def readable_blob?(options = {})
    !readable_blob(options, @path, @project, @ref).nil?
  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

  def edit_url(options = {})
    readable_blob?(options) ? edit_blob_path(@project, @ref, @path || '') : ''
  end

  def gitpod_url
    return "" unless Gitlab::CurrentSettings.gitpod_enabled

    "#{Gitlab::CurrentSettings.gitpod_url}##{project_tree_url(@project, tree_join(@ref, @path || ''))}"
  end
end