Commit 5c8cd42b authored by Stan Hu's avatar Stan Hu

Fix invalid visibility string comparison in project import

This resolves an "ArgumentError: comparison of String with 0 failed"
issue where the visibility_level is stored as a string in the project
import data because the value comes directly from the Web form. This
problem happened upon creating a project from a template or restoring a

We now cast the value to an integer to guard against these kinds of

Closes #61692
parent 20375f81
Pipeline #62672271 passed with stages
in 65 minutes and 47 seconds
title: Fix invalid visibility string comparison in project import
merge_request: 28612
type: fixed
......@@ -129,7 +129,7 @@ module Gitlab
def visibility_level
level = override_params['visibility_level'] || json_params['visibility_level'] || @project.visibility_level
level = if && level >
level = if && level.to_i >
{ 'visibility_level' => level }
......@@ -328,6 +328,19 @@ describe Gitlab::ImportExport::ProjectTreeRestorer do
context 'when the project has overridden params in import data' do
it 'handles string versions of visibility_level' do
# Project needs to be in a group for visibility level comparison
# to happen
group = create(:group) = group
project.create_import_data(data: { override_params: { visibility_level: Gitlab::VisibilityLevel::INTERNAL.to_s } })
expect(project.visibility_level).to eq(Gitlab::VisibilityLevel::INTERNAL)
it 'overwrites the params stored in the JSON' do
project.create_import_data(data: { override_params: { description: "Overridden" } })
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment