Skip to content
Snippets Groups Projects

Include and process visibility_level

Merged Carla Drago requested to merge 405168-fix-group-visibility-level into master
1 unresolved thread
Files
2
@@ -65,6 +65,13 @@ def process_root(group_id)
@@ -65,6 +65,13 @@ def process_root(group_id)
# with existing groups name and/or path.
# with existing groups name and/or path.
group_attributes.delete_attributes('name', 'path')
group_attributes.delete_attributes('name', 'path')
 
unless @top_level_group.parent.nil?
 
group_attributes.attributes['visibility_level'] = sub_group_visibility_level(
 
group_attributes.attributes,
 
@top_level_group.parent
 
)
 
end
 
restore_group(@top_level_group, group_attributes)
restore_group(@top_level_group, group_attributes)
end
end
@@ -88,14 +95,13 @@ def create_group(group_attributes)
@@ -88,14 +95,13 @@ def create_group(group_attributes)
path = group_attributes.delete_attribute('path')
path = group_attributes.delete_attribute('path')
parent_group = @groups_mapping.fetch(parent_id) { raise(ArgumentError, 'Parent group not found') }
parent_group = @groups_mapping.fetch(parent_id) { raise(ArgumentError, 'Parent group not found') }
destination_group = parent_group.ancestors.find_by(parent_id: nil) || parent_group
group = ::Groups::CreateService.new(
group = ::Groups::CreateService.new(
user,
user,
name: name,
name: name,
path: path,
path: path,
parent_id: parent_group.id,
parent_id: parent_group.id,
visibility_level: sub_group_visibility_level(group_attributes.attributes, destination_group)
visibility_level: sub_group_visibility_level(group_attributes.attributes, parent_group)
).execute
).execute
group.validate!
group.validate!
@@ -125,14 +131,14 @@ def relation_reader
@@ -125,14 +131,14 @@ def relation_reader
end
end
end
end
def sub_group_visibility_level(group_hash, destination_group)
def sub_group_visibility_level(group_hash, parent_group)
destination_visibility_level = destination_group.visibility_level
parent_visibility_level = parent_group.visibility_level
original_visibility_level = group_hash['visibility_level'] ||
original_visibility_level = group_hash['visibility_level'] ||
closest_allowed_level(destination_visibility_level)
closest_allowed_level(parent_visibility_level)
if destination_visibility_level < original_visibility_level
if parent_visibility_level < original_visibility_level
closest_allowed_level(destination_visibility_level)
closest_allowed_level(parent_visibility_level)
else
else
closest_allowed_level(original_visibility_level)
closest_allowed_level(original_visibility_level)
end
end
Loading