summaryrefslogtreecommitdiff
path: root/app/helpers/visibility_level_helper.rb
blob: 00d4c7f1051df4950f020ec7288dea1c2f545e45 (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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
module VisibilityLevelHelper
  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

  # 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.
  def visibility_level_description(level, form_model)
    case form_model.is_a?(String) ? form_model : form_model.class.name
    when 'PersonalSnippet', 'ProjectSnippet', 'Snippet'
      snippet_visibility_level_description(level)
    when 'Project'
      project_visibility_level_description(level)
    end
  end

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

  def snippet_visibility_level_description(level)
    capture_haml do
      haml_tag :span do
        case level
        when Gitlab::VisibilityLevel::PRIVATE
          haml_concat "The snippet is visible only for me."
        when Gitlab::VisibilityLevel::INTERNAL
          haml_concat "The snippet is visible for any logged in user."
        when Gitlab::VisibilityLevel::PUBLIC
          haml_concat "The snippet can be accessed"
          haml_concat "without any"
          haml_concat "authentication."
        end
      end
    end
  end

  def visibility_level_icon(level)
    case level
    when Gitlab::VisibilityLevel::PRIVATE
      private_icon
    when Gitlab::VisibilityLevel::INTERNAL
      internal_icon
    when Gitlab::VisibilityLevel::PUBLIC
      public_icon
    end
  end

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

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

  def default_project_visibility
    current_application_settings.default_project_visibility
  end

  def default_snippet_visibility
    current_application_settings.default_snippet_visibility
  end
end