BigW Consortium Gitlab

visibility_level_helper.rb 3.29 KB
Newer Older
1 2 3 4
module VisibilityLevelHelper
  def visibility_level_color(level)
    case level
    when Gitlab::VisibilityLevel::PRIVATE
5
      'vs-private'
6
    when Gitlab::VisibilityLevel::INTERNAL
7
      'vs-internal'
8
    when Gitlab::VisibilityLevel::PUBLIC
9
      'vs-public'
10 11 12
    end
  end

Vinnie Okada committed
13 14
  # Return the description for the +level+ argument.
  #
15 16 17
  # +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.
Vinnie Okada committed
18
  def visibility_level_description(level, form_model)
19 20
    case form_model
    when Project
Vinnie Okada committed
21
      project_visibility_level_description(level)
22 23
    when Group
      group_visibility_level_description(level)
24 25
    when Snippet
      snippet_visibility_level_description(level, form_model)
Vinnie Okada committed
26 27 28 29
    end
  end

  def project_visibility_level_description(level)
30 31
    case level
    when Gitlab::VisibilityLevel::PRIVATE
32
      "Project access must be granted explicitly to each user."
33 34 35 36
    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."
37 38 39
    end
  end

40 41 42
  def group_visibility_level_description(level)
    case level
    when Gitlab::VisibilityLevel::PRIVATE
Douwe Maan committed
43
      "The group and its projects can only be viewed by members."
44
    when Gitlab::VisibilityLevel::INTERNAL
Douwe Maan committed
45
      "The group and any internal projects can be viewed by any logged in user."
46
    when Gitlab::VisibilityLevel::PUBLIC
Douwe Maan committed
47
      "The group and any public projects can be viewed without any authentication."
48 49 50
    end
  end

51
  def snippet_visibility_level_description(level, snippet = nil)
52 53
    case level
    when Gitlab::VisibilityLevel::PRIVATE
54 55 56 57 58
      if snippet.is_a? ProjectSnippet
        "The snippet is visible only to project members."
      else
        "The snippet is visible only to me."
      end
59
    when Gitlab::VisibilityLevel::INTERNAL
60
      "The snippet is visible to any logged in user."
61
    when Gitlab::VisibilityLevel::PUBLIC
62
      "The snippet can be accessed without any authentication."
63 64 65
    end
  end

Douwe Maan committed
66 67 68 69 70 71 72 73 74 75 76
  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

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

Douwe Maan committed
79 80
  def project_visibility_icon_description(level)
    "#{visibility_level_label(level)} - #{project_visibility_level_description(level)}"
81 82
  end

83 84 85
  def visibility_level_label(level)
    Project.visibility_levels.key(level)
  end
86

87 88
  def restricted_visibility_levels(show_all = false)
    return [] if current_user.is_admin? && !show_all
89
    current_application_settings.restricted_visibility_levels || []
90
  end
Vinnie Okada committed
91 92 93 94 95 96 97 98

  def default_project_visibility
    current_application_settings.default_project_visibility
  end

  def default_snippet_visibility
    current_application_settings.default_snippet_visibility
  end
99

100 101 102 103
  def default_group_visibility
    current_application_settings.default_group_visibility
  end

104
  def skip_level?(form_model, level)
105
    form_model.is_a?(Project) && !form_model.visibility_level_allowed?(level)
106
  end
107
end