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.
|
|
|
|
#
|
|
|
|
# +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.is_a?(String) ? form_model : form_model.class.name
|
|
|
|
when 'PersonalSnippet', 'ProjectSnippet', 'Snippet'
|
|
|
|
snippet_visibility_level_description(level)
|
|
|
|
when 'Project'
|
|
|
|
project_visibility_level_description(level)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def project_visibility_level_description(level)
|
2013-11-06 10:13:21 -05:00
|
|
|
capture_haml do
|
|
|
|
haml_tag :span do
|
|
|
|
case level
|
|
|
|
when Gitlab::VisibilityLevel::PRIVATE
|
|
|
|
haml_concat "Project access must be granted explicitly for each user."
|
|
|
|
when Gitlab::VisibilityLevel::INTERNAL
|
|
|
|
haml_concat "The project can be cloned by"
|
2013-11-27 06:13:33 -05:00
|
|
|
haml_concat "any logged in user."
|
2013-11-06 10:13:21 -05:00
|
|
|
when Gitlab::VisibilityLevel::PUBLIC
|
|
|
|
haml_concat "The project can be cloned"
|
2013-11-27 06:13:33 -05:00
|
|
|
haml_concat "without any"
|
2013-11-06 10:13:21 -05:00
|
|
|
haml_concat "authentication."
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-10-08 09:44:25 -04:00
|
|
|
def snippet_visibility_level_description(level)
|
|
|
|
capture_haml do
|
|
|
|
haml_tag :span do
|
|
|
|
case level
|
|
|
|
when Gitlab::VisibilityLevel::PRIVATE
|
2015-05-03 09:00:46 -04:00
|
|
|
haml_concat "The snippet is visible only for me."
|
2014-10-08 09:44:25 -04:00
|
|
|
when Gitlab::VisibilityLevel::INTERNAL
|
|
|
|
haml_concat "The snippet is visible for any logged in user."
|
|
|
|
when Gitlab::VisibilityLevel::PUBLIC
|
|
|
|
haml_concat "The snippet can be accessed"
|
|
|
|
haml_concat "without any"
|
|
|
|
haml_concat "authentication."
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-11-06 10:13:21 -05:00
|
|
|
def visibility_level_icon(level)
|
|
|
|
case level
|
|
|
|
when Gitlab::VisibilityLevel::PRIVATE
|
|
|
|
private_icon
|
|
|
|
when Gitlab::VisibilityLevel::INTERNAL
|
|
|
|
internal_icon
|
|
|
|
when Gitlab::VisibilityLevel::PUBLIC
|
|
|
|
public_icon
|
|
|
|
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) &&
|
|
|
|
form_model.forked? &&
|
|
|
|
!Gitlab::VisibilityLevel.allowed_fork_levels(form_model.forked_from_project.visibility_level).include?(level)
|
|
|
|
end
|
2013-11-27 06:13:33 -05:00
|
|
|
end
|