Module: VisibilityLevelHelper

Defined in:
app/helpers/visibility_level_helper.rb

Instance Method Summary collapse

Instance Method Details

#default_group_visibilityObject


100
101
102
# File 'app/helpers/visibility_level_helper.rb', line 100

def default_group_visibility
  current_application_settings.default_group_visibility
end

#default_project_visibilityObject


92
93
94
# File 'app/helpers/visibility_level_helper.rb', line 92

def default_project_visibility
  current_application_settings.default_project_visibility
end

#default_snippet_visibilityObject


96
97
98
# File 'app/helpers/visibility_level_helper.rb', line 96

def default_snippet_visibility
  current_application_settings.default_snippet_visibility
end

#group_visibility_icon_description(level) ⇒ Object


75
76
77
# File 'app/helpers/visibility_level_helper.rb', line 75

def group_visibility_icon_description(level)
  "#{visibility_level_label(level)} - #{group_visibility_level_description(level)}"
end

#group_visibility_level_description(level) ⇒ Object


40
41
42
43
44
45
46
47
48
49
# File 'app/helpers/visibility_level_helper.rb', line 40

def group_visibility_level_description(level)
  case level
  when Gitlab::VisibilityLevel::PRIVATE
    "The group and its projects can only be viewed by members."
  when Gitlab::VisibilityLevel::INTERNAL
    "The group and any internal projects can be viewed by any logged in user."
  when Gitlab::VisibilityLevel::PUBLIC
    "The group and any public projects can be viewed without any authentication."
  end
end

#project_visibility_icon_description(level) ⇒ Object


79
80
81
# File 'app/helpers/visibility_level_helper.rb', line 79

def project_visibility_icon_description(level)
  "#{visibility_level_label(level)} - #{project_visibility_level_description(level)}"
end

#project_visibility_level_description(level) ⇒ Object


29
30
31
32
33
34
35
36
37
38
# File 'app/helpers/visibility_level_helper.rb', line 29

def project_visibility_level_description(level)
  case level
  when Gitlab::VisibilityLevel::PRIVATE
    "Project access must be granted explicitly to each user."
  when Gitlab::VisibilityLevel::INTERNAL
    "The project can be cloned by any logged in user."
  when Gitlab::VisibilityLevel::PUBLIC
    "The project can be cloned without any authentication."
  end
end

#restricted_visibility_levels(show_all = false) ⇒ Object


87
88
89
90
# File 'app/helpers/visibility_level_helper.rb', line 87

def restricted_visibility_levels(show_all = false)
  return [] if current_user.is_admin? && !show_all
  current_application_settings.restricted_visibility_levels || []
end

#skip_level?(form_model, level) ⇒ Boolean

Returns:

  • (Boolean)

104
105
106
# File 'app/helpers/visibility_level_helper.rb', line 104

def skip_level?(form_model, level)
  form_model.is_a?(Project) && !form_model.visibility_level_allowed?(level)
end

#snippet_visibility_level_description(level, snippet = nil) ⇒ Object


51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'app/helpers/visibility_level_helper.rb', line 51

def snippet_visibility_level_description(level, snippet = nil)
  case level
  when Gitlab::VisibilityLevel::PRIVATE
    if snippet.is_a? ProjectSnippet
      "The snippet is visible only to project members."
    else
      "The snippet is visible only to me."
    end
  when Gitlab::VisibilityLevel::INTERNAL
    "The snippet is visible to any logged in user."
  when Gitlab::VisibilityLevel::PUBLIC
    "The snippet can be accessed without any authentication."
  end
end

#visibility_icon_description(form_model) ⇒ Object


66
67
68
69
70
71
72
73
# File 'app/helpers/visibility_level_helper.rb', line 66

def visibility_icon_description(form_model)
  case form_model
  when Project
    project_visibility_icon_description(form_model.visibility_level)
  when Group
    group_visibility_icon_description(form_model.visibility_level)
  end
end

#visibility_level_color(level) ⇒ Object


2
3
4
5
6
7
8
9
10
11
# File 'app/helpers/visibility_level_helper.rb', line 2

def visibility_level_color(level)
  case level
  when Gitlab::VisibilityLevel::PRIVATE
    'vs-private'
  when Gitlab::VisibilityLevel::INTERNAL
    'vs-internal'
  when Gitlab::VisibilityLevel::PUBLIC
    'vs-public'
  end
end

#visibility_level_description(level, form_model) ⇒ Object

Return the description for the level argument.

level One of the Gitlab::VisibilityLevel constants form_model Either a model object (Project, Snippet, etc.) or the name of

a Project or Snippet class.

18
19
20
21
22
23
24
25
26
27
# File 'app/helpers/visibility_level_helper.rb', line 18

def visibility_level_description(level, form_model)
  case form_model
  when Project
    project_visibility_level_description(level)
  when Group
    group_visibility_level_description(level)
  when Snippet
    snippet_visibility_level_description(level, form_model)
  end
end

#visibility_level_label(level) ⇒ Object


83
84
85
# File 'app/helpers/visibility_level_helper.rb', line 83

def visibility_level_label(level)
  Project.visibility_levels.key(level)
end