Commit 15bba7cc authored by Thong Kuah's avatar Thong Kuah

Merge branch 'use_default_external_auth_label_empty' into 'master'

Prevent empty external authorization classification labels from overriding default label

Closes #66617

See merge request gitlab-org/gitlab-ce!32517
parents 6def5bd6 525449d7
---
title: Prevent empty external authorization classification labels from overriding
the default label
merge_request: 32517
author: Will Chandler
type: fixed
...@@ -107,7 +107,7 @@ module Gitlab ...@@ -107,7 +107,7 @@ module Gitlab
def project_params def project_params
@project_params ||= begin @project_params ||= begin
attrs = json_params.merge(override_params).merge(visibility_level) attrs = json_params.merge(override_params).merge(visibility_level, external_label)
# Cleaning all imported and overridden params # Cleaning all imported and overridden params
Gitlab::ImportExport::AttributeCleaner.clean(relation_hash: attrs, Gitlab::ImportExport::AttributeCleaner.clean(relation_hash: attrs,
...@@ -135,6 +135,13 @@ module Gitlab ...@@ -135,6 +135,13 @@ module Gitlab
{ 'visibility_level' => level } { 'visibility_level' => level }
end end
def external_label
label = override_params['external_authorization_classification_label'].presence ||
json_params['external_authorization_classification_label'].presence
{ 'external_authorization_classification_label' => label }
end
# Given a relation hash containing one or more models and its relationships, # Given a relation hash containing one or more models and its relationships,
# loops through each model and each object from a model type and # loops through each model and each object from a model type and
# and assigns its correspondent attributes hash from +tree_hash+ # and assigns its correspondent attributes hash from +tree_hash+
......
...@@ -512,6 +512,24 @@ describe Gitlab::ImportExport::ProjectTreeRestorer do ...@@ -512,6 +512,24 @@ describe Gitlab::ImportExport::ProjectTreeRestorer do
expect(Milestone.find_by_title('Group-level milestone').iid).to eq(2) expect(Milestone.find_by_title('Group-level milestone').iid).to eq(2)
end end
end end
context 'with external authorization classification labels' do
it 'converts empty external classification authorization labels to nil' do
project.create_import_data(data: { override_params: { external_authorization_classification_label: "" } })
restored_project_json
expect(project.external_authorization_classification_label).to be_nil
end
it 'preserves valid external classification authorization labels' do
project.create_import_data(data: { override_params: { external_authorization_classification_label: "foobar" } })
restored_project_json
expect(project.external_authorization_classification_label).to eq("foobar")
end
end
end end
describe '#restored_project' do describe '#restored_project' do
......
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