debian-mirror-gitlab/app/helpers/visibility_level_helper.rb

75 lines
2.2 KiB
Ruby
Raw Normal View History

2014-09-02 18:07:02 +05:30
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
2015-09-11 14:41:01 +05:30
# Return the description for the +level+ argument.
#
2015-12-23 02:04:40 +05:30
# +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-09-11 14:41:01 +05:30
def visibility_level_description(level, form_model)
2015-12-23 02:04:40 +05:30
case form_model
when Project
2015-09-11 14:41:01 +05:30
project_visibility_level_description(level)
2015-12-23 02:04:40 +05:30
when Snippet
snippet_visibility_level_description(level, form_model)
2015-09-11 14:41:01 +05:30
end
end
def project_visibility_level_description(level)
2015-12-23 02:04:40 +05:30
case level
when Gitlab::VisibilityLevel::PRIVATE
"Project access must be granted explicitly to each user."
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."
2015-04-26 12:48:37 +05:30
end
end
2015-12-23 02:04:40 +05:30
def snippet_visibility_level_description(level, snippet = nil)
2014-09-02 18:07:02 +05:30
case level
when Gitlab::VisibilityLevel::PRIVATE
2015-12-23 02:04:40 +05:30
if snippet.is_a? ProjectSnippet
"The snippet is visible only to project members."
else
"The snippet is visible only to me."
end
2014-09-02 18:07:02 +05:30
when Gitlab::VisibilityLevel::INTERNAL
2015-12-23 02:04:40 +05:30
"The snippet is visible to any logged in user."
2014-09-02 18:07:02 +05:30
when Gitlab::VisibilityLevel::PUBLIC
2015-12-23 02:04:40 +05:30
"The snippet can be accessed without any authentication."
2014-09-02 18:07:02 +05:30
end
end
def visibility_level_label(level)
Project.visibility_levels.key(level)
end
2015-04-26 12:48:37 +05:30
def restricted_visibility_levels(show_all = false)
return [] if current_user.is_admin? && !show_all
current_application_settings.restricted_visibility_levels || []
2014-09-02 18:07:02 +05:30
end
2015-09-11 14:41:01 +05:30
def default_project_visibility
current_application_settings.default_project_visibility
end
def default_snippet_visibility
current_application_settings.default_snippet_visibility
end
def skip_level?(form_model, level)
form_model.is_a?(Project) &&
!form_model.visibility_level_allowed?(level)
2015-09-11 14:41:01 +05:30
end
2014-09-02 18:07:02 +05:30
end