diff options
Diffstat (limited to 'lib/bulk_imports/visibility_level.rb')
-rw-r--r-- | lib/bulk_imports/visibility_level.rb | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/lib/bulk_imports/visibility_level.rb b/lib/bulk_imports/visibility_level.rb new file mode 100644 index 00000000000..6b0af15dd7b --- /dev/null +++ b/lib/bulk_imports/visibility_level.rb @@ -0,0 +1,26 @@ +# frozen_string_literal: true + +module BulkImports + module VisibilityLevel + private + + def visibility_level(entity, namespace, visibility_string) + requested = requested_visibility_level(entity, visibility_string) + max_allowed = max_allowed_visibility_level(namespace) + + return requested if max_allowed >= requested + + max_allowed + end + + def requested_visibility_level(entity, visibility_string) + Gitlab::VisibilityLevel.string_options[visibility_string] || entity.default_visibility_level + end + + def max_allowed_visibility_level(namespace) + return Gitlab::VisibilityLevel.allowed_levels.max if namespace.blank? + + Gitlab::VisibilityLevel.closest_allowed_level(namespace.visibility_level) + end + end +end |