2013-11-06 10:13:21 -05:00
|
|
|
module VisibilityLevelHelper
|
|
|
|
def visibility_level_color(level)
|
|
|
|
case level
|
|
|
|
when Gitlab::VisibilityLevel::PRIVATE
|
2014-06-03 07:49:50 -04:00
|
|
|
'vs-private'
|
2013-11-06 10:13:21 -05:00
|
|
|
when Gitlab::VisibilityLevel::INTERNAL
|
2014-06-03 07:49:50 -04:00
|
|
|
'vs-internal'
|
2013-11-06 10:13:21 -05:00
|
|
|
when Gitlab::VisibilityLevel::PUBLIC
|
2014-06-03 07:49:50 -04:00
|
|
|
'vs-public'
|
2013-11-06 10:13:21 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-04-26 01:01:52 -04:00
|
|
|
# Return the description for the +level+ argument.
|
|
|
|
#
|
2015-12-07 07:37:01 -05:00
|
|
|
# +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.
|
2015-04-26 01:01:52 -04:00
|
|
|
def visibility_level_description(level, form_model)
|
2015-12-07 07:37:01 -05:00
|
|
|
case form_model
|
|
|
|
when Project
|
2015-04-26 01:01:52 -04:00
|
|
|
project_visibility_level_description(level)
|
2015-12-07 07:37:01 -05:00
|
|
|
when Snippet
|
|
|
|
snippet_visibility_level_description(level, form_model)
|
2015-04-26 01:01:52 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def project_visibility_level_description(level)
|
2015-12-02 08:08:59 -05:00
|
|
|
case level
|
|
|
|
when Gitlab::VisibilityLevel::PRIVATE
|
2015-12-07 07:37:01 -05:00
|
|
|
"Project access must be granted explicitly to each user."
|
2015-12-02 08:08:59 -05:00
|
|
|
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."
|
2014-10-08 09:44:25 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-12-07 07:37:01 -05:00
|
|
|
def snippet_visibility_level_description(level, snippet = nil)
|
2013-11-06 10:13:21 -05:00
|
|
|
case level
|
|
|
|
when Gitlab::VisibilityLevel::PRIVATE
|
2015-12-07 07:37:01 -05:00
|
|
|
if snippet.is_a? ProjectSnippet
|
|
|
|
"The snippet is visible only to project members."
|
|
|
|
else
|
|
|
|
"The snippet is visible only to me."
|
|
|
|
end
|
2013-11-06 10:13:21 -05:00
|
|
|
when Gitlab::VisibilityLevel::INTERNAL
|
2015-12-07 07:37:01 -05:00
|
|
|
"The snippet is visible to any logged in user."
|
2013-11-06 10:13:21 -05:00
|
|
|
when Gitlab::VisibilityLevel::PUBLIC
|
2015-12-02 08:08:59 -05:00
|
|
|
"The snippet can be accessed without any authentication."
|
2013-11-06 10:13:21 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def visibility_level_label(level)
|
|
|
|
Project.visibility_levels.key(level)
|
|
|
|
end
|
2013-11-27 06:13:33 -05:00
|
|
|
|
2015-03-01 10:06:46 -05:00
|
|
|
def restricted_visibility_levels(show_all = false)
|
|
|
|
return [] if current_user.is_admin? && !show_all
|
2015-03-16 15:29:27 -04:00
|
|
|
current_application_settings.restricted_visibility_levels || []
|
2013-11-06 10:13:21 -05:00
|
|
|
end
|
2015-04-26 01:01:52 -04:00
|
|
|
|
|
|
|
def default_project_visibility
|
|
|
|
current_application_settings.default_project_visibility
|
|
|
|
end
|
|
|
|
|
|
|
|
def default_snippet_visibility
|
|
|
|
current_application_settings.default_snippet_visibility
|
|
|
|
end
|
2015-07-06 08:38:43 -04:00
|
|
|
|
|
|
|
def skip_level?(form_model, level)
|
|
|
|
form_model.is_a?(Project) &&
|
2015-11-03 10:37:39 -05:00
|
|
|
!form_model.visibility_level_allowed?(level)
|
2015-07-06 08:38:43 -04:00
|
|
|
end
|
2013-11-27 06:13:33 -05:00
|
|
|
end
|