Module: WebIdeButtonHelper

Included in:
TreeHelper
Defined in:
app/helpers/web_ide_button_helper.rb

Instance Method Summary collapse

Instance Method Details

#can_collaborate?Boolean

Returns:

  • (Boolean)

12
13
14
# File 'app/helpers/web_ide_button_helper.rb', line 12

def can_collaborate?
  can_collaborate_with_project?(@project)
end

#can_create_mr_from_fork?Boolean

Returns:

  • (Boolean)

16
17
18
# File 'app/helpers/web_ide_button_helper.rb', line 16

def can_create_mr_from_fork?
  can?(current_user, :fork_project, @project) && can?(current_user, :create_merge_request_in, @project)
end

#can_push_code?Boolean

Returns:

  • (Boolean)

36
37
38
# File 'app/helpers/web_ide_button_helper.rb', line 36

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

#edit_url(options = {}) ⇒ Object


56
57
58
# File 'app/helpers/web_ide_button_helper.rb', line 56

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

#fork?Boolean

Returns:

  • (Boolean)

40
41
42
# File 'app/helpers/web_ide_button_helper.rb', line 40

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

#gitpod_urlObject


60
61
62
63
64
# File 'app/helpers/web_ide_button_helper.rb', line 60

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

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

#needs_to_fork?Boolean

Returns:

  • (Boolean)

48
49
50
# File 'app/helpers/web_ide_button_helper.rb', line 48

def needs_to_fork?
  !can_collaborate? && !current_user&.already_forked?(@project)
end

#project_forkObject


4
5
6
# File 'app/helpers/web_ide_button_helper.rb', line 4

def project_fork
  current_user&.fork_of(@project)
end

#project_to_useObject


8
9
10
# File 'app/helpers/web_ide_button_helper.rb', line 8

def project_to_use
  fork? ? project_fork : @project
end

#readable_blob?(options = {}) ⇒ Boolean

Returns:

  • (Boolean)

44
45
46
# File 'app/helpers/web_ide_button_helper.rb', line 44

def readable_blob?(options = {})
  !readable_blob(options, @path, @project, @ref).nil?
end

#show_edit_button?(options = {}) ⇒ Boolean

Returns:

  • (Boolean)

24
25
26
# File 'app/helpers/web_ide_button_helper.rb', line 24

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

#show_gitpod_button?Boolean

Returns:

  • (Boolean)

28
29
30
# File 'app/helpers/web_ide_button_helper.rb', line 28

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

#show_pipeline_editor_button?(project, path) ⇒ Boolean

Returns:

  • (Boolean)

32
33
34
# File 'app/helpers/web_ide_button_helper.rb', line 32

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

#show_web_ide_button?Boolean

Returns:

  • (Boolean)

20
21
22
# File 'app/helpers/web_ide_button_helper.rb', line 20

def show_web_ide_button?
  can_collaborate? || can_create_mr_from_fork?
end

#web_ide_urlObject


52
53
54
# File 'app/helpers/web_ide_button_helper.rb', line 52

def web_ide_url
  ide_edit_path(project_to_use, @ref, @path || '')
end