Commit 569295d6 authored by Heinrich Lee Yu's avatar Heinrich Lee Yu

Merge branch 'add-blocks-unsafe-serialization-to-namespace' into 'master'

Add BlocksUnsafeSerialization to Namespace

See merge request gitlab-org/gitlab!82661
parents b766afee be35c93a
...@@ -15,6 +15,7 @@ class Namespace < ApplicationRecord ...@@ -15,6 +15,7 @@ class Namespace < ApplicationRecord
include Namespaces::Traversal::Recursive include Namespaces::Traversal::Recursive
include Namespaces::Traversal::Linear include Namespaces::Traversal::Linear
include EachBatch include EachBatch
include BlocksUnsafeSerialization
# Temporary column used for back-filling project namespaces. # Temporary column used for back-filling project namespaces.
# Remove it once the back-filling of all project namespaces is done. # Remove it once the back-filling of all project namespaces is done.
...@@ -660,6 +661,10 @@ class Namespace < ApplicationRecord ...@@ -660,6 +661,10 @@ class Namespace < ApplicationRecord
# Use SHA2 of `traversal_ids` to account for moving a namespace within the same root ancestor hierarchy. # Use SHA2 of `traversal_ids` to account for moving a namespace within the same root ancestor hierarchy.
"namespaces:{#{traversal_ids.first}}:first_auto_devops_config:#{group_id}:#{Digest::SHA2.hexdigest(traversal_ids.join(' '))}" "namespaces:{#{traversal_ids.first}}:first_auto_devops_config:#{group_id}:#{Digest::SHA2.hexdigest(traversal_ids.join(' '))}"
end end
def allow_serialization?(options = nil)
Feature.disabled?(:block_namespace_serialization, self, default_enabled: :yaml) || super
end
end end
Namespace.prepend_mod_with('Namespace') Namespace.prepend_mod_with('Namespace')
---
name: block_namespace_serialization
introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/82661
rollout_issue_url: https://gitlab.com/gitlab-org/gitlab/-/issues/355553
milestone: '14.9'
type: development
group: group::global search
default_enabled: false
...@@ -92,7 +92,7 @@ module Gitlab ...@@ -92,7 +92,7 @@ module Gitlab
def simple_serialize def simple_serialize
subject.as_json( subject.as_json(
tree.merge(include: nil, preloads: nil)) tree.merge(include: nil, preloads: nil, unsafe: true))
end end
def serialize_includes def serialize_includes
......
...@@ -37,7 +37,7 @@ module Gitlab ...@@ -37,7 +37,7 @@ module Gitlab
def serialize_root(exportable_path = @exportable_path) def serialize_root(exportable_path = @exportable_path)
attributes = exportable.as_json( attributes = exportable.as_json(
relations_schema.merge(include: nil, preloads: nil)) relations_schema.merge(include: nil, preloads: nil, unsafe: true))
json_writer.write_attributes(exportable_path, attributes) json_writer.write_attributes(exportable_path, attributes)
end end
......
...@@ -2230,4 +2230,18 @@ RSpec.describe Namespace do ...@@ -2230,4 +2230,18 @@ RSpec.describe Namespace do
expect(namespace.storage_enforcement_date).to be(nil) expect(namespace.storage_enforcement_date).to be(nil)
end end
end end
describe 'serialization' do
let(:object) { build(:namespace) }
it_behaves_like 'blocks unsafe serialization'
context 'when feature flag block_namespace_serialization is disabled' do
before do
stub_feature_flags(block_namespace_serialization: false)
end
it_behaves_like 'allows unsafe serialization'
end
end
end end
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