gitlab-org--gitlab-foss/app/helpers/visibility_level_helper.rb

102 lines
3.3 KiB
Ruby
Raw Normal View History

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
when Project
project_visibility_level_description(level)
2016-03-01 10:22:29 -05:00
when Group
group_visibility_level_description(level)
when Snippet
snippet_visibility_level_description(level, form_model)
end
end
def project_visibility_level_description(level)
case level
when Gitlab::VisibilityLevel::PRIVATE
2017-06-07 16:13:44 -04:00
_("Project access must be granted explicitly to each user.")
when Gitlab::VisibilityLevel::INTERNAL
2017-06-07 16:13:44 -04:00
_("The project can be accessed by any logged in user.")
when Gitlab::VisibilityLevel::PUBLIC
2017-06-07 16:13:44 -04:00
_("The project can be accessed without any authentication.")
2014-10-08 09:44:25 -04:00
end
end
2016-03-01 10:22:29 -05:00
def group_visibility_level_description(level)
case level
when Gitlab::VisibilityLevel::PRIVATE
2016-03-21 19:09:20 -04:00
"The group and its projects can only be viewed by members."
2016-03-01 10:22:29 -05:00
when Gitlab::VisibilityLevel::INTERNAL
2016-03-21 19:09:20 -04:00
"The group and any internal projects can be viewed by any logged in user."
2016-03-01 10:22:29 -05:00
when Gitlab::VisibilityLevel::PUBLIC
2016-03-21 19:09:20 -04:00
"The group and any public projects can be viewed without any authentication."
2016-03-01 10:22:29 -05:00
end
end
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
2016-03-21 19:09:20 -04:00
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)}"
2016-03-20 16:03:53 -04:00
end
2016-03-21 19:09:20 -04:00
def project_visibility_icon_description(level)
"#{visibility_level_label(level)} - #{project_visibility_level_description(level)}"
2016-03-20 16:03:53 -04:00
end
def visibility_level_label(level)
2017-06-07 16:13:44 -04:00
# The visibility level can be:
# 'VisibilityLevel|Private', 'VisibilityLevel|Internal', 'VisibilityLevel|Public'
s_(Project.visibility_levels.key(level))
end
def restricted_visibility_levels(show_all = false)
2017-04-08 22:20:57 -04:00
return [] if current_user.admin? && !show_all
current_application_settings.restricted_visibility_levels || []
end
2017-02-22 12:51:46 -05:00
delegate :default_project_visibility,
:default_group_visibility,
to: :current_application_settings
2015-07-06 08:38:43 -04:00
def skip_level?(form_model, level)
2016-03-18 08:28:16 -04:00
form_model.is_a?(Project) && !form_model.visibility_level_allowed?(level)
2015-07-06 08:38:43 -04:00
end
end