Module: VisibilityLevelHelper

Defined in:
app/helpers/visibility_level_helper.rb

Instance Method Summary collapse

Instance Method Details

#all_visibility_levelsObject



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

def all_visibility_levels
  Gitlab::VisibilityLevel.values
end

#available_visibility_levels(form_model) ⇒ Object



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

def available_visibility_levels(form_model)
  Gitlab::VisibilityLevel.values.reject do |level|
    disallowed_visibility_level?(form_model, level) ||
      restricted_visibility_levels.include?(level)
  end
end

#disabled_visibility_level?(form_model, level) ⇒ Boolean



107
108
109
110
# File 'app/helpers/visibility_level_helper.rb', line 107

def disabled_visibility_level?(form_model, level)
  disallowed_visibility_level?(form_model, level) ||
    restricted_visibility_level?(level)
end

#disallowed_visibility_level?(form_model, level) ⇒ Boolean



50
51
52
53
54
# File 'app/helpers/visibility_level_helper.rb', line 50

def disallowed_visibility_level?(form_model, level)
  return false unless form_model.respond_to?(:visibility_level_allowed?)

  !form_model.visibility_level_allowed?(level)
end

#disallowed_visibility_level_by_organization?(form_model, level) ⇒ Boolean



56
57
58
59
60
# File 'app/helpers/visibility_level_helper.rb', line 56

def disallowed_visibility_level_by_organization?(form_model, level)
  return false unless form_model.respond_to?(:visibility_level_allowed_by_organization?)

  !form_model.visibility_level_allowed_by_organization?(level)
end

#disallowed_visibility_level_by_parent?(form_model, level) ⇒ Boolean



62
63
64
65
66
# File 'app/helpers/visibility_level_helper.rb', line 62

def disallowed_visibility_level_by_parent?(form_model, level)
  return false unless form_model.respond_to?(:visibility_level_allowed_by_parent?)

  !form_model.visibility_level_allowed_by_parent?(level)
end

#disallowed_visibility_level_by_projects?(form_model, level) ⇒ Boolean



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

def disallowed_visibility_level_by_projects?(form_model, level)
  return false unless form_model.respond_to?(:visibility_level_allowed_by_projects?)

  !form_model.visibility_level_allowed_by_projects?(level)
end

#disallowed_visibility_level_by_sub_groups?(form_model, level) ⇒ Boolean



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

def disallowed_visibility_level_by_sub_groups?(form_model, level)
  return false unless form_model.respond_to?(:visibility_level_allowed_by_sub_groups?)

  !form_model.visibility_level_allowed_by_sub_groups?(level)
end

#multiple_visibility_levels_restricted?Boolean



120
121
122
# File 'app/helpers/visibility_level_helper.rb', line 120

def multiple_visibility_levels_restricted?
  restricted_visibility_levels.many? # rubocop:disable CodeReuse/ActiveRecord -- False positive, not AR object
end

#restricted_visibility_level?(level) ⇒ Boolean



112
113
114
# File 'app/helpers/visibility_level_helper.rb', line 112

def restricted_visibility_level?(level)
  restricted_visibility_levels.include?(level)
end

#restricted_visibility_levels(show_all = false) ⇒ Object



41
42
43
44
45
# File 'app/helpers/visibility_level_helper.rb', line 41

def restricted_visibility_levels(show_all = false)
  return [] if current_user.can_admin_all_resources? && !show_all

  Gitlab::CurrentSettings.restricted_visibility_levels || []
end

#selected_visibility_level(form_model, requested_level) ⇒ Object

Visibility level can be restricted in two ways:

  1. The group permissions (e.g. a subgroup is private, which requires

all projects to be private)

  1. The global allowed visibility settings, set by the admin



85
86
87
88
89
90
91
92
93
94
# File 'app/helpers/visibility_level_helper.rb', line 85

def selected_visibility_level(form_model, requested_level)
  requested_level =
    if requested_level.present?
      requested_level.to_i
    else
      default_project_visibility
    end

  [requested_level, max_allowed_visibility_level(form_model)].min
end

#snippets_selected_visibility_level(visibility_levels, selected) ⇒ Object



116
117
118
# File 'app/helpers/visibility_level_helper.rb', line 116

def snippets_selected_visibility_level(visibility_levels, selected)
  visibility_levels.find { |level| level == selected } || visibility_levels.min
end

#visibility_icon_description(form_model) ⇒ Object



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

def visibility_icon_description(form_model)
  if form_model.respond_to?(:visibility_level_allowed_as_fork?)
    project_visibility_icon_description(form_model.visibility_level)
  elsif form_model.respond_to?(:visibility_level_allowed_by_sub_groups?)
    group_visibility_icon_description(form_model.visibility_level)
  end
end

#visibility_level_color(level) ⇒ Object



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

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.


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

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

#visibility_level_label(level) ⇒ Object



37
38
39
# File 'app/helpers/visibility_level_helper.rb', line 37

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