Module: VisibilityLevelHelper
- Defined in:
- app/helpers/visibility_level_helper.rb
Instance Method Summary collapse
- #all_visibility_levels_restricted? ⇒ Boolean
- #available_visibility_levels(form_model) ⇒ Object
- #disallowed_visibility_level?(form_model, level) ⇒ Boolean
- #multiple_visibility_levels_restricted? ⇒ Boolean
- #restricted_visibility_levels(show_all = false) ⇒ Object
-
#selected_visibility_level(form_model, requested_level) ⇒ Object
Visibility level can be restricted in two ways:.
- #snippets_selected_visibility_level(visibility_levels, selected) ⇒ Object
- #visibility_icon_description(form_model) ⇒ Object
- #visibility_level_color(level) ⇒ Object
-
#visibility_level_description(level, form_model) ⇒ Object
Return the description for the
level
argument. - #visibility_level_label(level) ⇒ Object
- #visibility_level_options(form_model) ⇒ Object
Instance Method Details
#all_visibility_levels_restricted? ⇒ Boolean
97 98 99 |
# File 'app/helpers/visibility_level_helper.rb', line 97 def all_visibility_levels_restricted? Gitlab::VisibilityLevel.values == restricted_visibility_levels end |
#available_visibility_levels(form_model) ⇒ Object
72 73 74 75 76 77 |
# File 'app/helpers/visibility_level_helper.rb', line 72 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 |
#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 |
#multiple_visibility_levels_restricted? ⇒ Boolean
93 94 95 |
# File 'app/helpers/visibility_level_helper.rb', line 93 def multiple_visibility_levels_restricted? restricted_visibility_levels.many? # rubocop: disable CodeReuse/ActiveRecord 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:
-
The group permissions (e.g. a subgroup is private, which requires
all projects to be private)
-
The global allowed visibility settings, set by the admin
61 62 63 64 65 66 67 68 69 70 |
# File 'app/helpers/visibility_level_helper.rb', line 61 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
89 90 91 |
# File 'app/helpers/visibility_level_helper.rb', line 89 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 |
#visibility_level_options(form_model) ⇒ Object
79 80 81 82 83 84 85 86 87 |
# File 'app/helpers/visibility_level_helper.rb', line 79 def (form_model) available_visibility_levels(form_model).map do |level| { level: level, label: visibility_level_label(level), description: visibility_level_description(level, form_model) } end end |